Skip to main content
Visitor II
September 27, 2021
Solved

Why would I receive 2 unlinked netbufs for one packet transmission?

  • September 27, 2021
  • 4 replies
  • 1344 views

I am putting a Webserver in a STM32F407. I have static and dynamic pages working and am now working on a file upload function. The browser sends me a single packet that is 887 bytes long according to Wireshark. I am using Netconn with LWIP so when I call netconn_recv, I only get 536 bytes in the first call then 297 bytes in the second call. It's clear that these are supposed to be connected together (printed them in the debugger).

There is no way to see that these should be connected to each other. With both packets the Len and Tot_Len are the same! Also they are not linked to each other...two separate netbufs!

Any ideas?

    This topic has been closed for replies.
    Best answer by alister

    >There is no way to see that these should be connected to each other

    TCP is a stream. So long as all the bytes arrive and in order, lwIP has done its job.

    4 replies

    alisterAnswer
    Explorer
    September 28, 2021

    >There is no way to see that these should be connected to each other

    TCP is a stream. So long as all the bytes arrive and in order, lwIP has done its job.

    MStra.3Author
    Visitor II
    September 28, 2021

    @alister​  OK, I re-read the LWIP wiki and I guess I am not supposed to have any expectations on how much data is given to me at a time regardless of the size chunk that was sent.

    So I have one question. How am I supposed to figure out when I receive a chunk that I have not received everything the sender sent? In my case I am receiving a POST upload.cgi. It has a "Content Length" of 192 which doesn't give me a clue as to how long the packet should be. In this case it's not the file size because the filename is blank.

    Mike.

    Explorer
    September 28, 2021

    https://datatracker.ietf.org/doc/html/rfc7230#section-3

    You parse the receive stream, get the Content Length header value, and use that from the start of the body which is delineated from the headers by two CRLF sequences.

    MStra.3Author
    Visitor II
    September 28, 2021

    I hadn't noticed that, but I did see that the body is bounded by Boundary Markers which are included in the Content Length, so I am parsing the stream for the Boundary Markers to find the uploaded file data.

    Thanks for your help!

    MStra.3Author
    Visitor II
    September 28, 2021

    I ended up answering my question by doing a lot of digging on the web and running trials with Wireshark... Are we having fun yet?

    Visitor II
    November 11, 2021

    Hello MStra.3.

    change this define TCP_MSS 

    Own project\Middlewares\Third_Party\LwIP\src\include\lwip\opt.h -> #define TCP_MSS