lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Extracting data from lwIP TCP/IP flow on microcontrolle


From: Sergio R. Caprile
Subject: Re: [lwip-users] Extracting data from lwIP TCP/IP flow on microcontroller
Date: Fri, 27 Jul 2018 10:44:11 -0300
User-agent: Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

OK...
You seem to need a tutorship or a crash course in networking followed by
a study of lwIP.

You need to first get a grasp of the layer model as an abstraction: if
you set things right, that is, if you assign the proper IP address and
open the proper TCP port, you will get a callback with a pointer to what
you sent from the other side. There is no "other traffic" to worry about.
There's a catch: TCP is not a serial port, you will get exactly what you
sent, but not necessarily timed in the same way.

Then there is lwIP... and its RAW API. Here, in your callbacks, you
don't get plain data, you get pbufs. A pbuf is a structure holding a bit
of your data. Here 'a bit' is what arrived in a single Ethernet frame,
which depends on how TCP arranged it at the other end, and it might be
scattered through many pbufs in a pbuf chain, depending on how memory
was alloced when the driver asked for it.

You should take a look at the many available examples and learn how to
do what you want to do.
For example, a simple RAW API TCP callback can be:
static err_t myrecv(void *arg, struct tcp_pcb* pcb, struct pbuf *p,
err_t err)
{
static char buffer[MSG_LEN];

        if ((p == NULL) || (err != ERR_OK)){
                // Connection closed by remote end
                // need to close pcb and related stuff
                return ERR_OK;
        }
        // assuming MSG_LEN >= p->tot_len, otherwise is a bit more complicated
        pbuf_copy_partial(p, buffer, p->tot_len, 0);
        tcp_recved(pcb, p->tot_len);
        pbuf_free(p);
        // your data is now in a contiguous buffer, use it
        return ERR_OK;
}
There are many posts on the list discussing this.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]