socket_util.h (1099B)
1 #ifndef UDPHOLE_SOCKET_UTIL_H 2 #define UDPHOLE_SOCKET_UTIL_H 3 4 /* Set socket blocking (0) or non-blocking (1). Returns 0 on success, -1 on error. */ 5 int set_socket_nonblocking(int fd, int nonblock); 6 7 /* Create listening sockets. Supports dual-stack when host is empty. 8 * addr can be "port", "host:port", or "[ipv6]:port". Missing host uses default_host, 9 * missing port uses default_port. 10 * Returns int array: index 0 = count, index 1+ = socket fds. Caller must free. 11 * On error returns NULL. */ 12 int *tcp_listen(const char *addr, const char *default_host, const char *default_port); 13 14 /* Create UDP receiving sockets. Same semantics as tcp_listen(). */ 15 int *udp_recv(const char *addr, const char *default_host, const char *default_port); 16 17 /* Create Unix domain socket. path is the socket path, sock_type is SOCK_DGRAM or SOCK_STREAM. 18 * owner is optional and can be "user" or "user:group" to set socket ownership. 19 * Returns int array: index 0 = count, index 1 = socket fd. Caller must free. 20 * On error returns NULL. */ 21 int *unix_listen(const char *path, int sock_type, const char *owner); 22 23 #endif