modernc.org/cc@v1.0.1/v2/headers/linux_386/usr/include/i386-linux-gnu/sys/socket.h (about)

     1  /* Declarations of socket constants, types, and functions.
     2     Copyright (C) 1991-2018 Free Software Foundation, Inc.
     3     This file is part of the GNU C Library.
     4  
     5     The GNU C Library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9  
    10     The GNU C Library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14  
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with the GNU C Library; if not, see
    17     <http://www.gnu.org/licenses/>.  */
    18  
    19  #ifndef	_SYS_SOCKET_H
    20  #define	_SYS_SOCKET_H	1
    21  
    22  #include <features.h>
    23  
    24  __BEGIN_DECLS
    25  #include <bits/types/struct_iovec.h>
    26  #define	__need_size_t
    27  #include <stddef.h>
    28  /* This operating system-specific header file defines the SOCK_*, PF_*,
    29     AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr',
    30     `struct msghdr', and `struct linger' types.  */
    31  #include <bits/socket.h>
    32  #ifdef __USE_MISC
    33  # include <bits/types/struct_osockaddr.h>
    34  #endif
    35  /* The following constants should be used for the second parameter of
    36     `shutdown'.  */
    37      enum {
    38  	SHUT_RD = 0,		/* No more receptions.  */
    39  #define SHUT_RD		SHUT_RD
    40  	SHUT_WR,		/* No more transmissions.  */
    41  #define SHUT_WR		SHUT_WR
    42  	SHUT_RDWR		/* No more receptions or transmissions.  */
    43  #define SHUT_RDWR	SHUT_RDWR
    44  };
    45  
    46  /* This is the type we use for generic socket address arguments.
    47  
    48     With GCC 2.7 and later, the funky union causes redeclarations or
    49     uses with any of the listed types to be allowed without complaint.
    50     G++ 2.7 does not support transparent unions so there we want the
    51     old-style declaration, too.  */
    52  #if defined __cplusplus || !__GNUC_PREREQ (2, 7) || !defined __USE_GNU
    53  # define __SOCKADDR_ARG		struct sockaddr *__restrict
    54  # define __CONST_SOCKADDR_ARG	const struct sockaddr *
    55  #else
    56  /* Add more `struct sockaddr_AF' types here as necessary.
    57     These are all the ones I found on NetBSD and Linux.  */
    58  # define __SOCKADDR_ALLTYPES \
    59    __SOCKADDR_ONETYPE (sockaddr) \
    60    __SOCKADDR_ONETYPE (sockaddr_at) \
    61    __SOCKADDR_ONETYPE (sockaddr_ax25) \
    62    __SOCKADDR_ONETYPE (sockaddr_dl) \
    63    __SOCKADDR_ONETYPE (sockaddr_eon) \
    64    __SOCKADDR_ONETYPE (sockaddr_in) \
    65    __SOCKADDR_ONETYPE (sockaddr_in6) \
    66    __SOCKADDR_ONETYPE (sockaddr_inarp) \
    67    __SOCKADDR_ONETYPE (sockaddr_ipx) \
    68    __SOCKADDR_ONETYPE (sockaddr_iso) \
    69    __SOCKADDR_ONETYPE (sockaddr_ns) \
    70    __SOCKADDR_ONETYPE (sockaddr_un) \
    71    __SOCKADDR_ONETYPE (sockaddr_x25)
    72  
    73  # define __SOCKADDR_ONETYPE(type) struct type *__restrict __##type##__;
    74  typedef union {
    75  __SOCKADDR_ALLTYPES} __SOCKADDR_ARG __attribute__ ((__transparent_union__));
    76  # undef __SOCKADDR_ONETYPE
    77  # define __SOCKADDR_ONETYPE(type) const struct type *__restrict __##type##__;
    78  typedef union {
    79  __SOCKADDR_ALLTYPES} __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__));
    80  # undef __SOCKADDR_ONETYPE
    81  #endif
    82  
    83  #ifdef __USE_GNU
    84  /* For `recvmmsg' and `sendmmsg'.  */
    85  struct mmsghdr {
    86  	struct msghdr msg_hdr;	/* Actual message header.  */
    87  	unsigned int msg_len;	/* Number of received or sent bytes for the
    88  				   entry.  */
    89  };
    90  #endif
    91  
    92  /* Create a new socket of type TYPE in domain DOMAIN, using
    93     protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
    94     Returns a file descriptor for the new socket, or -1 for errors.  */
    95  extern int socket(int __domain, int __type, int __protocol) __THROW;
    96  
    97  /* Create two new sockets, of type TYPE in domain DOMAIN and using
    98     protocol PROTOCOL, which are connected to each other, and put file
    99     descriptors for them in FDS[0] and FDS[1].  If PROTOCOL is zero,
   100     one will be chosen automatically.  Returns 0 on success, -1 for errors.  */
   101  extern int socketpair(int __domain, int __type, int __protocol, int __fds[2]) __THROW;
   102  
   103  /* Give the socket FD the local address ADDR (which is LEN bytes long).  */
   104  extern int bind(int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len) __THROW;
   105  
   106  /* Put the local address of FD into *ADDR and its length in *LEN.  */
   107  extern int getsockname(int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __len) __THROW;
   108  
   109  /* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
   110     For connectionless socket types, just set the default address to send to
   111     and the only address from which to accept transmissions.
   112     Return 0 on success, -1 for errors.
   113  
   114     This function is a cancellation point and therefore not marked with
   115     __THROW.  */
   116  extern int connect(int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
   117  
   118  /* Put the address of the peer connected to socket FD into *ADDR
   119     (which is *LEN bytes long), and its actual length into *LEN.  */
   120  extern int getpeername(int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __len) __THROW;
   121  
   122  /* Send N bytes of BUF to socket FD.  Returns the number sent or -1.
   123  
   124     This function is a cancellation point and therefore not marked with
   125     __THROW.  */
   126  extern ssize_t send(int __fd, const void *__buf, size_t __n, int __flags);
   127  
   128  /* Read N bytes into BUF from socket FD.
   129     Returns the number read or -1 for errors.
   130  
   131     This function is a cancellation point and therefore not marked with
   132     __THROW.  */
   133  extern ssize_t recv(int __fd, void *__buf, size_t __n, int __flags);
   134  
   135  /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
   136     ADDR_LEN bytes long).  Returns the number sent, or -1 for errors.
   137  
   138     This function is a cancellation point and therefore not marked with
   139     __THROW.  */
   140  extern ssize_t sendto(int __fd, const void *__buf, size_t __n, int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len);
   141  
   142  /* Read N bytes into BUF through socket FD.
   143     If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
   144     the sender, and store the actual size of the address in *ADDR_LEN.
   145     Returns the number of bytes read or -1 for errors.
   146  
   147     This function is a cancellation point and therefore not marked with
   148     __THROW.  */
   149  extern ssize_t recvfrom(int __fd, void *__restrict __buf, size_t __n, int __flags, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
   150  
   151  /* Send a message described MESSAGE on socket FD.
   152     Returns the number of bytes sent, or -1 for errors.
   153  
   154     This function is a cancellation point and therefore not marked with
   155     __THROW.  */
   156  extern ssize_t sendmsg(int __fd, const struct msghdr *__message, int __flags);
   157  
   158  #ifdef __USE_GNU
   159  /* Send a VLEN messages as described by VMESSAGES to socket FD.
   160     Returns the number of datagrams successfully written or -1 for errors.
   161  
   162     This function is a cancellation point and therefore not marked with
   163     __THROW.  */
   164  extern int sendmmsg(int __fd, struct mmsghdr *__vmessages, unsigned int __vlen, int __flags);
   165  #endif
   166  
   167  /* Receive a message as described by MESSAGE from socket FD.
   168     Returns the number of bytes read or -1 for errors.
   169  
   170     This function is a cancellation point and therefore not marked with
   171     __THROW.  */
   172  extern ssize_t recvmsg(int __fd, struct msghdr *__message, int __flags);
   173  
   174  #ifdef __USE_GNU
   175  /* Receive up to VLEN messages as described by VMESSAGES from socket FD.
   176     Returns the number of messages received or -1 for errors.
   177  
   178     This function is a cancellation point and therefore not marked with
   179     __THROW.  */
   180  extern int recvmmsg(int __fd, struct mmsghdr *__vmessages, unsigned int __vlen, int __flags, struct timespec *__tmo);
   181  #endif
   182  
   183  /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
   184     into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
   185     actual length.  Returns 0 on success, -1 for errors.  */
   186  extern int getsockopt(int __fd, int __level, int __optname, void *__restrict __optval, socklen_t * __restrict __optlen) __THROW;
   187  
   188  /* Set socket FD's option OPTNAME at protocol level LEVEL
   189     to *OPTVAL (which is OPTLEN bytes long).
   190     Returns 0 on success, -1 for errors.  */
   191  extern int setsockopt(int __fd, int __level, int __optname, const void *__optval, socklen_t __optlen) __THROW;
   192  
   193  /* Prepare to accept connections on socket FD.
   194     N connection requests will be queued before further requests are refused.
   195     Returns 0 on success, -1 for errors.  */
   196  extern int listen(int __fd, int __n) __THROW;
   197  
   198  /* Await a connection on socket FD.
   199     When a connection arrives, open a new socket to communicate with it,
   200     set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
   201     peer and *ADDR_LEN to the address's actual length, and return the
   202     new socket's descriptor, or -1 for errors.
   203  
   204     This function is a cancellation point and therefore not marked with
   205     __THROW.  */
   206  extern int accept(int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
   207  
   208  #ifdef __USE_GNU
   209  /* Similar to 'accept' but takes an additional parameter to specify flags.
   210  
   211     This function is a cancellation point and therefore not marked with
   212     __THROW.  */
   213  extern int accept4(int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len, int __flags);
   214  #endif
   215  
   216  /* Shut down all or part of the connection open on socket FD.
   217     HOW determines what to shut down:
   218       SHUT_RD   = No more receptions;
   219       SHUT_WR   = No more transmissions;
   220       SHUT_RDWR = No more receptions or transmissions.
   221     Returns 0 on success, -1 for errors.  */
   222  extern int shutdown(int __fd, int __how) __THROW;
   223  
   224  #ifdef __USE_XOPEN2K
   225  /* Determine wheter socket is at a out-of-band mark.  */
   226  extern int sockatmark(int __fd) __THROW;
   227  #endif
   228  
   229  #ifdef __USE_MISC
   230  /* FDTYPE is S_IFSOCK or another S_IF* macro defined in <sys/stat.h>;
   231     returns 1 if FD is open on an object of the indicated type, 0 if not,
   232     or -1 for errors (setting errno).  */
   233  extern int isfdtype(int __fd, int __fdtype) __THROW;
   234  #endif
   235  
   236  /* Define some macros helping to catch buffer overflows.  */
   237  #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
   238  # include <bits/socket2.h>
   239  #endif
   240  
   241  __END_DECLS
   242  #endif				/* sys/socket.h */