1 #ifndef NET__SOCKET__H__ 2 #define NET__SOCKET__H__ 3 4 #include "ipv4.h" 5 #include "ipv6.h" 6 7 /** \defgroup socket socket: General socket manipulations 8 9 \par Calling Convention 10 11 When calling a socket function, the socket file descriptor (where 12 required) will always be the first parameter. Functions that return a 13 file descriptor (either creating a new socket or accepting a connection 14 on a socket return that file descriptor on success or \c -1 on error. 15 All other functions return non-zero (true) on success or \c 0 (false) on 16 error. All functions set errno on error. 17 18 @{ */ 19 20 /** \name IP socket functions 21 @{ */ 22 int socket_tcp4(void); 23 int socket_tcp6(void); 24 int socket_tcp(void); 25 int socket_udp4(void); 26 int socket_udp6(void); 27 int socket_udp(void); 28 int socket_connect4(int sock, const ipv4addr* ip, ipv4port port); 29 int socket_connect4_timeout(int sock, const ipv4addr* ip, ipv4port port, 30 int timeout); 31 int socket_connect6(int sock, const ipv6addr* ip, ipv6port port); 32 int socket_connect6_timeout(int sock, const ipv6addr* ip, ipv6port port, 33 int timeout); 34 int socket_bind4(int sock, const ipv4addr* ip, ipv4port port); 35 int socket_bind6(int sock, const ipv6addr* ip, ipv6port port); 36 int socket_accept4(int sock, ipv4addr* ip, ipv4port* port); 37 int socket_accept6(int sock, ipv6addr* ip, ipv6port* port); 38 int socket_recv4(int sock, char* buffer, unsigned buflen, 39 ipv4addr* ip, ipv4port* port); 40 int socket_recv6(int sock, char* buffer, unsigned buflen, 41 ipv6addr* ip, ipv6port* port); 42 int socket_send4(int sock, const char* buffer, unsigned buflen, 43 const ipv4addr* ip, ipv4port port); 44 int socket_send6(int sock, const char* buffer, unsigned buflen, 45 const ipv6addr* ip, ipv6port port); 46 int socket_getaddr4(int sock, ipv4addr* ip, ipv4port* port); 47 int socket_getaddr6(int sock, ipv6addr* ip, ipv6port* port); 48 int socket_cork(int sock); 49 int socket_uncork(int sock); 50 int socket_notcpdelay(int sock, int enable); 51 /** @} */ 52 53 /** \name UNIX local-domain socket functions 54 @{ */ 55 int socket_unixdgm(void); 56 int socket_unixstr(void); 57 int socket_connectu(int sock, const char* path); 58 int socket_connectu_timeout(int sock, const char* path, int timeout); 59 int socket_bindu(int sock, const char* path); 60 int socket_acceptu(int sock); 61 int socket_recvu(int sock, char* buffer, unsigned buflen); 62 int socket_sendu(int sock, const char* buffer, unsigned buflen); 63 64 int socket_pairstr(int fd[2]); 65 int socket_pairdgm(int fd[2]); 66 /** @} */ 67 68 /** \name Functions for any type of socket 69 @{ */ 70 int socket_broadcast(int sock); 71 int socket_connected(int sock); 72 int socket_linger(int fd, int onoff, int seconds); 73 int socket_listen(int sock, int backlog); 74 int socket_reuse(int sock); 75 int socket_shutdown(int sock, int shut_rd, int shut_wr); 76 77 int socket_sendfd(int sock, int fd); 78 int socket_recvfd(int sock); 79 /** @} */ 80 81 /** @} */ 82 83 #endif 84