lwIP - A Minimal TCP/IP implementation - Wikia
lwIP - A Minimal TCP/IP implementation - Wikia
lwIP - A Minimal TCP/IP implementation - Wikia
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
17 BSD SOCKET LIBRARY 17.3 Connection setup<br />
int<br />
connect(int s, struct sockaddr *name, int namelen)<br />
{<br />
struct netconn *conn;<br />
struct ip_addr *remote_addr;<br />
unsigned short remote_port;<br />
remote_addr = (struct ip_addr *)name->sin_addr;<br />
remote_port = name->sin_port;<br />
conn = sockets[s];<br />
netconn_connect(conn, remote_addr, remote_port);<br />
}<br />
return 0;<br />
17.3.3 The listen() call<br />
The listen() call is the equivalent of the <strong>lw<strong>IP</strong></strong> API function netconn listen() and can only be<br />
used for <strong>TCP</strong> connections. The only difference is that the BSD socket API allows the application<br />
to specify the size of the queue of pending connections (the backlog). This is not possible with<br />
<strong>lw<strong>IP</strong></strong> and the backlog parameter is ignored.<br />
int<br />
listen(int s, int backlog)<br />
{<br />
netconn_listen(sockets[s]);<br />
return 0;<br />
}<br />
17.3.4 The accept() call<br />
The accept() call is used to wait for incoming connections on a <strong>TCP</strong> socket that previously has<br />
been set into LISTEN state by a call to listen(). The call to accept() blocks until a connection<br />
has been established with a remote host. The arguments to listen are result parameters that are<br />
set by the call to accept(). These are filled with the address of the remote host.<br />
When the new connection has been established, the <strong>lw<strong>IP</strong></strong> function netconn accept() will<br />
return the connection handle for the new connection. After the <strong>IP</strong> address and port number of<br />
the remote host has been filled in, a new socket identifier is allocated and returned.<br />
int<br />
accept(int s, struct sockaddr *addr, int *addrlen)<br />
{<br />
struct netconn *conn, *newconn;<br />
struct ip_addr *addr;<br />
unsigned short port;<br />
int i;<br />
conn = sockets[s];<br />
newconn = netconn_accept(conn);<br />
/* get the <strong>IP</strong> address and port of the remote host */<br />
32