P_udp4_listen 3porty 2011-04-14 libporty manual

NAME

P_udp4_listen, P_udp4_recvfrom

SYNPOSIS

#include <libporty/net/udp4.h>

int P_udp4_listen (P_net_socket * sock , const char * loc_hostname , int loc_port , P_net_nonblock_t non_blocking , P_net_broadcast_t broadcast );
int P_udp4_recvfrom (P_net_socket sock , char * buff , int maxlen , unsigned int * rem_ip , char ** rem_host , int * rem_port )

Link with -lporty_net

DESCRIPTION

P_udp4_listen creates an UDP/IPv4 listening socket (socket is returned in sock ). The socket is bound to loc_hostname : loc_port locally. For listening on any interface loc_hostname should be "0.0.0.0". If loc_hostname is not an ip address, a blocking DNS lookup will be issued.

If non_blocking has bit P_net_nonblock_socket set, the socket listening socket will be non-blocking for read. If broadcast has bit P_net_broadcast_socket set, broadcast packets are received and sent.

Caller should poll for reading (P_POLLIN) on listening sockets and call P_udp4_revfrom when the socket becomes readable. Data of the incoming datagram is copied into buff , at most maxlen bytes. Buffer should be big enough to host full messages - excess bytes may be lost. In case any of rem_ip , rem_host and rem_port is non-NULL, source address information is filled in.

Note: rem_host triggers blocking DNS lookups.

RETURN VALUE

Returns 0 on success or an error code from P_net_err n failure.

P_udp4_listen 3porty 2011-04-14 libporty manual