lwIP - A Minimal TCP/IP implementation - Wikia
lwIP - A Minimal TCP/IP implementation - Wikia
lwIP - A Minimal TCP/IP implementation - Wikia
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
17 BSD SOCKET LIBRARY<br />
}<br />
netconn_send(conn, buf);<br />
/* reference the text into the netbuf */<br />
netbuf_ref(buf, text, sizeof(text));<br />
/* send the text */<br />
netconn_send(conn, buf);<br />
/* deallocate connection and netbuf */<br />
netconn_delete(conn);<br />
netconn_delete(buf);<br />
16.0.26 netconn close()<br />
Synopsis<br />
int netconn close(struct netconn *conn)<br />
Description<br />
Closes the connection conn.<br />
17 BSD socket library<br />
This section provides a simple <strong>implementation</strong> of the BSD socket API using the <strong>lw<strong>IP</strong></strong> API. The<br />
<strong>implementation</strong> is provided as a reference only, and is not intended for use in actual programs.<br />
There is for example no error handling.<br />
Also, this <strong>implementation</strong> does not support the select() and poll() functions of the BSD<br />
socket API since the <strong>lw<strong>IP</strong></strong> API does not have any functions that can be used to implement those.<br />
In order to implement those functions, the BSD socket <strong>implementation</strong> would have to communicate<br />
directly with the <strong>lw<strong>IP</strong></strong> stack and not use the API.<br />
17.1 The representation of a socket<br />
In the BSD socket API sockets are represented as ordinary file descriptors. File descriptors are<br />
integers that uniquely identifies the file or network connection. In this <strong>implementation</strong> of the BSD<br />
socket API, sockets are internally represented by a netconn structure. Since BSD sockets are<br />
identified by an integer, the netconn variables are kept in an array, sockets[], where the BSD<br />
socket identifier is the index into the array.<br />
17.2 Allocating a socket<br />
17.2.1 The socket() call<br />
The socket() call allocates a BSD socket. The parameters to socket() are used to specify what<br />
type of socket that is requested. Since this socket API <strong>implementation</strong> is concerned only with<br />
network sockets, these are the only socket type that is supported. Also, only UDP (SOCK DGRAM)<br />
or <strong>TCP</strong> (SOCK STREAM) sockets can be used.<br />
int<br />
socket(int domain, int type, int protocol)<br />
{<br />
struct netconn *conn;<br />
int i;<br />
30