int socket_listen(int s,int n);
int socket_accept(int s,char ip[16],
uint16 *port,uint32 *scope_id);
int socket_ipoptionskill(int s);
int socket_ip6anycast((int s);
int socket_dualstack(int s);
int socket_nodualstack(int s);
socket_accept accepts the connection. It creates a new socket for the connection and returns a file descriptor pointing to the new socket; you can use the read and write system calls to transmit data through that file descriptor. Further, it provides information about client's ip address and TCP port number perhaps together with local receiving interface scope_id.
socket_ipoptionskill is used to disable previously defined options in IPv4 or IPv6 packets like Source Routing prior of using this socket for data exchange. socket_ipoptionskill uses the setsockopt.
socket_ip6anycast enables unspecified reversed anycasting on the listening socket s with IPv6 address ::. Upon receiving IPv6 packets, the socket records the incoming IPv6 address and the receiving scope_id in order provide additional routing information.
socket_dualstack and socket_nodualstack can be used to force or forbid dual-stack behavior setting the setsockopt variable IPV6_V6ONLY appropriately. In the last case, a potential servers needs two instances to accept incoming IPv6 and IPv6 packets.
int s, t;
int r;
char ip[16];
uint16 p;
if ((s = socket_tcp()) == -1)
err_tmp("",111,"unable to create TCP socket: ");
r = socket_ipoptionskill(s);
if (socket_bind_reuse(s,(char *)V6localnet,8002,0) == -1)
err_tmp("",111,"unable to bind: ");
if (socket_listen(s,1) == -1)
err_tmp("",111,"unable to listen: ");
t = socket_tcp();
socket_bind(t,ip,p,0);
socket_listen(s,16);
socket_accept(t,ip,&p,&scope_id);