1 10 Lwip
1 10 Lwip
1 10 Lwip
김백규
What is LWIP?
An implementation of the TCP/IP protocol stack.
Designing in a layered
fashion leads to…
<Layered model>
communication overhead
between layers
Network communication is
similar to IPC or file I/O
APP can’t aware of the
buffer mechanisms.
(e.g. reuse buffers with
frequently used data.)
Features of TCP/IP stack(L
WIP version)
between layers.
(By means of shared memory)
- APP layer can use the buffer handling mechanisms used by the
lower layers.
- APP can more efficiently reuse buffers.
OS specific function calls and data structures are not used directly
in the code.
The operating system emulation layer is used.
Porting to a different OS
Only need the operating system emulation layer
.
Buffer and memory management
Types of pbufs
PBUF_RAM, PBUF_ROM, PBUF_POOL
has the packet data stored in memory managed by the pbuf subsystem.
used when an application sends data that is dynamically generated.
PBUF_ROM pbuf
Called when a
datagram is received.
UDP processing(2/2)
UDP processing
TCP processing(1/2)
Function to call when a
listener has been connected.
Next sequence
number
Receiver’s
window
netconn delete()
void netconn delete(struct netconn *conn)
netconn bind()
int netconn bind(struct netconn *conn, struct ip addr *addr, unsigned
short port)
netconn connect()
int netconn connect(struct netconn *conn, struct ip addr *remote
addr, unsigned short remote port)
Network connection function(2/2)
netconn listen()
int netconn listen(struct netconn *conn)
netconn accept()
struct netconn * netconn accept(struct netconn *conn)
netconn recv()
struct netbuf * netconn recv(struct netconn *conn)
netconn write()
int netconn write(struct netconn *conn, void *data, int len, unsigned
int flags)
Example #1
<This example shows how to open a TCP server on port 2000>
Int main()
{
struct netconn *conn, *newconn;
/* create a connection structure */
conn = netconn_new(NETCONN_TCP);
/* bind the connection to port 2000 on any local
IP address */
netconn_bind(conn, NULL, 2000);
/* tell the connection to listen for incoming
connection requests */
netconn_listen(conn);
/* block until we get an incoming connection */
newconn = netconn_accept(conn);
/* do something with the connection */
process_connection(newconn);
/* deallocate both connections */
netconn_delete(newconn);
netconn_delete(conn);
}
Example #2
<This is a small example that shows a suggested use of the netconn_recv() function.>