socket_accept4(3) | Library Functions Manual | socket_accept4(3) |
socket_accept4 - accept an IPv4 TCP connection on a socket
#include <socket.h>
int socket_accept4(int s,char ip[4],uint16 *port);
When a TCP connection arrives on a listening TCP socket s, the socket becomes readable.
socket_accept4 accepts the connection. It sets ip and port to the client IP address and client TCP port. 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.
If something goes wrong, socket_accept4 returns -1, setting errno appropriately, without creating a new socket.
#include <socket.h>
int s;
char ip[4];
uint16 p;
s = socket_tcp4();
socket_bind4(s,ip,p);
socket_listen(s,16);
socket_accept4(s,ip,&p);