April 2024 | ||||||
Mo | Tu | We | Th | Fr | Sa | Su |
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 |
001: /* Declarations of socket constants, types, and functions. 002: Copyright (C) 1991,92,1994-2001,2003,2005,2007,2008 003: Free Software Foundation, Inc. 004: This file is part of the GNU C Library. 005: 006: The GNU C Library is free software; you can redistribute it and/or 007: modify it under the terms of the GNU Lesser General Public 008: License as published by the Free Software Foundation; either 009: version 2.1 of the License, or (at your option) any later version. 010: 011: The GNU C Library is distributed in the hope that it will be useful, 012: but WITHOUT ANY WARRANTY; without even the implied warranty of 013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014: Lesser General Public License for more details. 015: 016: You should have received a copy of the GNU Lesser General Public 017: License along with the GNU C Library; if not, write to the Free 018: Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 019: 02111-1307 USA. */ 020: 021: #ifndef _SYS_SOCKET_H 022: #define _SYS_SOCKET_H 1 023: 024: #include <features.h> 025: 026: __BEGIN_DECLS 027: 028: #include <sys/uio.h> 029: #define __need_size_t 030: #include <stddef.h> 031: #ifdef __USE_GNU 032: /* Get the __sigset_t definition. */ 033: # include <bits/sigset.h> 034: #endif 035: 036: 037: /* This operating system-specific header file defines the SOCK_*, PF_*, 038: AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr', 039: `struct msghdr', and `struct linger' types. */ 040: #include <bits/socket.h> 041: 042: #ifdef __USE_BSD 043: /* This is the 4.3 BSD `struct sockaddr' format, which is used as wire 044: format in the grotty old 4.3 `talk' protocol. */ 045: struct osockaddr 046: { 047: unsigned short int sa_family; 048: unsigned char sa_data[14]; 049: }; 050: #endif 051: 052: /* The following constants should be used for the second parameter of 053: `shutdown'. */ 054: enum 055: { 056: SHUT_RD = 0, /* No more receptions. */ 057: #define SHUT_RD SHUT_RD 058: SHUT_WR, /* No more transmissions. */ 059: #define SHUT_WR SHUT_WR 060: SHUT_RDWR /* No more receptions or transmissions. */ 061: #define SHUT_RDWR SHUT_RDWR 062: }; 063: 064: /* This is the type we use for generic socket address arguments. 065: 066: With GCC 2.7 and later, the funky union causes redeclarations or 067: uses with any of the listed types to be allowed without complaint. 068: G++ 2.7 does not support transparent unions so there we want the 069: old-style declaration, too. */ 070: #if defined __cplusplus || !__GNUC_PREREQ (2, 7) || !defined __USE_GNU 071: # define __SOCKADDR_ARG struct sockaddr *__restrict 072: # define __CONST_SOCKADDR_ARG __const struct sockaddr * 073: #else 074: /* Add more `struct sockaddr_AF' types here as necessary. 075: These are all the ones I found on NetBSD and Linux. */ 076: # define __SOCKADDR_ALLTYPES \ 077: __SOCKADDR_ONETYPE (sockaddr) \ 078: __SOCKADDR_ONETYPE (sockaddr_at) \ 079: __SOCKADDR_ONETYPE (sockaddr_ax25) \ 080: __SOCKADDR_ONETYPE (sockaddr_dl) \ 081: __SOCKADDR_ONETYPE (sockaddr_eon) \ 082: __SOCKADDR_ONETYPE (sockaddr_in) \ 083: __SOCKADDR_ONETYPE (sockaddr_in6) \ 084: __SOCKADDR_ONETYPE (sockaddr_inarp) \ 085: __SOCKADDR_ONETYPE (sockaddr_ipx) \ 086: __SOCKADDR_ONETYPE (sockaddr_iso) \ 087: __SOCKADDR_ONETYPE (sockaddr_ns) \ 088: __SOCKADDR_ONETYPE (sockaddr_un) \ 089: __SOCKADDR_ONETYPE (sockaddr_x25) 090: 091: # define __SOCKADDR_ONETYPE(type) struct type *__restrict __##type##__; 092: typedef union { __SOCKADDR_ALLTYPES 093: } __SOCKADDR_ARG __attribute__ ((__transparent_union__)); 094: # undef __SOCKADDR_ONETYPE 095: # define __SOCKADDR_ONETYPE(type) __const struct type *__restrict __##type##__; 096: typedef union { __SOCKADDR_ALLTYPES 097: } __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__)); 098: # undef __SOCKADDR_ONETYPE 099: #endif 100: 101: 102: /* Create a new socket of type TYPE in domain DOMAIN, using 103: protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically. 104: Returns a file descriptor for the new socket, or -1 for errors. */ 105: extern int socket (int __domain, int __type, int __protocol) __THROW; 106: 107: /* Create two new sockets, of type TYPE in domain DOMAIN and using 108: protocol PROTOCOL, which are connected to each other, and put file 109: descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero, 110: one will be chosen automatically. Returns 0 on success, -1 for errors. */ 111: extern int socketpair (int __domain, int __type, int __protocol, 112: int __fds[2]) __THROW; 113: 114: /* Give the socket FD the local address ADDR (which is LEN bytes long). */ 115: extern int bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len) 116: __THROW; 117: 118: /* Put the local address of FD into *ADDR and its length in *LEN. */ 119: extern int getsockname (int __fd, __SOCKADDR_ARG __addr, 120: socklen_t *__restrict __len) __THROW; 121: 122: /* Open a connection on socket FD to peer at ADDR (which LEN bytes long). 123: For connectionless socket types, just set the default address to send to 124: and the only address from which to accept transmissions. 125: Return 0 on success, -1 for errors. 126: 127: This function is a cancellation point and therefore not marked with 128: __THROW. */ 129: extern int connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len); 130: 131: /* Put the address of the peer connected to socket FD into *ADDR 132: (which is *LEN bytes long), and its actual length into *LEN. */ 133: extern int getpeername (int __fd, __SOCKADDR_ARG __addr, 134: socklen_t *__restrict __len) __THROW; 135: 136: 137: /* Send N bytes of BUF to socket FD. Returns the number sent or -1. 138: 139: This function is a cancellation point and therefore not marked with 140: __THROW. */ 141: extern ssize_t send (int __fd, __const void *__buf, size_t __n, int __flags); 142: 143: /* Read N bytes into BUF from socket FD. 144: Returns the number read or -1 for errors. 145: 146: This function is a cancellation point and therefore not marked with 147: __THROW. */ 148: extern ssize_t recv (int __fd, void *__buf, size_t __n, int __flags); 149: 150: /* Send N bytes of BUF on socket FD to peer at address ADDR (which is 151: ADDR_LEN bytes long). Returns the number sent, or -1 for errors. 152: 153: This function is a cancellation point and therefore not marked with 154: __THROW. */ 155: extern ssize_t sendto (int __fd, __const void *__buf, size_t __n, 156: int __flags, __CONST_SOCKADDR_ARG __addr, 157: socklen_t __addr_len); 158: 159: /* Read N bytes into BUF through socket FD. 160: If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of 161: the sender, and store the actual size of the address in *ADDR_LEN. 162: Returns the number of bytes read or -1 for errors. 163: 164: This function is a cancellation point and therefore not marked with 165: __THROW. */ 166: extern ssize_t recvfrom (int __fd, void *__restrict __buf, size_t __n, 167: int __flags, __SOCKADDR_ARG __addr, 168: socklen_t *__restrict __addr_len); 169: 170: 171: /* Send a message described MESSAGE on socket FD. 172: Returns the number of bytes sent, or -1 for errors. 173: 174: This function is a cancellation point and therefore not marked with 175: __THROW. */ 176: extern ssize_t sendmsg (int __fd, __const struct msghdr *__message, 177: int __flags); 178: 179: /* Receive a message as described by MESSAGE from socket FD. 180: Returns the number of bytes read or -1 for errors. 181: 182: This function is a cancellation point and therefore not marked with 183: __THROW. */ 184: extern ssize_t recvmsg (int __fd, struct msghdr *__message, int __flags); 185: 186: 187: /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL 188: into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's 189: actual length. Returns 0 on success, -1 for errors. */ 190: extern int getsockopt (int __fd, int __level, int __optname, 191: void *__restrict __optval, 192: socklen_t *__restrict __optlen) __THROW; 193: 194: /* Set socket FD's option OPTNAME at protocol level LEVEL 195: to *OPTVAL (which is OPTLEN bytes long). 196: Returns 0 on success, -1 for errors. */ 197: extern int setsockopt (int __fd, int __level, int __optname, 198: __const void *__optval, socklen_t __optlen) __THROW; 199: 200: 201: /* Prepare to accept connections on socket FD. 202: N connection requests will be queued before further requests are refused. 203: Returns 0 on success, -1 for errors. */ 204: extern int listen (int __fd, int __n) __THROW; 205: 206: /* Await a connection on socket FD. 207: When a connection arrives, open a new socket to communicate with it, 208: set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting 209: peer and *ADDR_LEN to the address's actual length, and return the 210: new socket's descriptor, or -1 for errors. 211: 212: This function is a cancellation point and therefore not marked with 213: __THROW. */ 214: extern int accept (int __fd, __SOCKADDR_ARG __addr, 215: socklen_t *__restrict __addr_len); 216: 217: #ifdef __USE_GNU 218: /* Similar to 'accept' but takes an additional parameter to specify flags. 219: 220: This function is a cancellation point and therefore not marked with 221: __THROW. */ 222: extern int accept4 (int __fd, __SOCKADDR_ARG __addr, 223: socklen_t *__restrict __addr_len, int __flags); 224: #endif 225: 226: /* Shut down all or part of the connection open on socket FD. 227: HOW determines what to shut down: 228: SHUT_RD = No more receptions; 229: SHUT_WR = No more transmissions; 230: SHUT_RDWR = No more receptions or transmissions. 231: Returns 0 on success, -1 for errors. */ 232: extern int shutdown (int __fd, int __how) __THROW; 233: 234: 235: #ifdef __USE_XOPEN2K 236: /* Determine wheter socket is at a out-of-band mark. */ 237: extern int sockatmark (int __fd) __THROW; 238: #endif 239: 240: 241: #ifdef __USE_MISC 242: /* FDTYPE is S_IFSOCK or another S_IF* macro defined in <sys/stat.h>; 243: returns 1 if FD is open on an object of the indicated type, 0 if not, 244: or -1 for errors (setting errno). */ 245: extern int isfdtype (int __fd, int __fdtype) __THROW; 246: #endif 247: 248: 249: /* Define some macros helping to catch buffer overflows. */ 250: #if __USE_FORTIFY_LEVEL > 0 && defined __extern_always_inline 251: # include <bits/socket2.h> 252: #endif 253: 254: __END_DECLS 255: 256: #endif /* sys/socket.h */ 257: