1 #include <sys/cdefs.h> 2 #include "namespace.h" 3 #include <lib.h> 4 5 #include <errno.h> 6 #include <stdio.h> 7 #include <string.h> 8 #include <sys/ioctl.h> 9 #include <sys/socket.h> 10 #include <netinet/in.h> 11 12 #include <net/gen/in.h> 13 #include <net/gen/tcp.h> 14 #include <net/gen/tcp_io.h> 15 #include <net/gen/udp.h> 16 #include <net/gen/udp_io.h> 17 18 /* 19 * Put a socket in listening mode. 20 */ 21 static int 22 __listen(int fd, int backlog) 23 { 24 message m; 25 26 memset(&m, 0, sizeof(m)); 27 m.m_lc_vfs_listen.fd = fd; 28 m.m_lc_vfs_listen.backlog = backlog; 29 30 return _syscall(VFS_PROC_NR, VFS_LISTEN, &m); 31 } 32 33 int listen(int sock, int backlog) 34 { 35 int r; 36 37 r = __listen(sock, backlog); 38 if (r != -1 || (errno != ENOTSOCK && errno != ENOSYS)) 39 return r; 40 41 r= ioctl(sock, NWIOTCPLISTENQ, &backlog); 42 if (r != -1 || errno != ENOTTY) 43 return r; 44 45 r= ioctl(sock, NWIOSUDSBLOG, &backlog); 46 if (r != -1 || errno != ENOTTY) 47 return r; 48 49 errno = ENOTSOCK; 50 return -1; 51 } 52