Back to index

glibc  2.9
socket.h
Go to the documentation of this file.
00001 #ifndef _SYS_SOCKET_H
00002 #include <socket/sys/socket.h>
00003 
00004 /* Now define the internal interfaces.  */
00005 
00006 /* Create a new socket of type TYPE in domain DOMAIN, using
00007    protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
00008    Returns a file descriptor for the new socket, or -1 for errors.  */
00009 extern int __socket (int __domain, int __type,
00010                    int __protocol) attribute_hidden;
00011 
00012 /* Create two new sockets, of type TYPE in domain DOMAIN and using
00013    protocol PROTOCOL, which are connected to each other, and put file
00014    descriptors for them in FDS[0] and FDS[1].  If PROTOCOL is zero,
00015    one will be chosen automatically.  Returns 0 on success, -1 for errors.  */
00016 extern int __socketpair (int __domain, int __type, int __protocol,
00017                       int __fds[2]) attribute_hidden;
00018 
00019 /* Return a socket of any type.  The socket can be used in subsequent
00020    ioctl calls to talk to the kernel.  */
00021 extern int __opensock (void) internal_function attribute_hidden;
00022 
00023 /* Put the address of the peer connected to socket FD into *ADDR
00024    (which is *LEN bytes long), and its actual length into *LEN.  */
00025 extern int __getpeername (int __fd, __SOCKADDR_ARG __addr,
00026                        socklen_t *__len) attribute_hidden;
00027 
00028 /* Send N bytes of BUF to socket FD.  Returns the number sent or -1.  */
00029 extern ssize_t __libc_send (int __fd, __const void *__buf, size_t __n,
00030                          int __flags);
00031 extern ssize_t __send (int __fd, __const void *__buf, size_t __n, int __flags);
00032 libc_hidden_proto (__send)
00033 
00034 /* Read N bytes into BUF from socket FD.
00035    Returns the number read or -1 for errors.  */
00036 extern ssize_t __libc_recv (int __fd, void *__buf, size_t __n, int __flags);
00037 
00038 /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
00039    ADDR_LEN bytes long).  Returns the number sent, or -1 for errors.  */
00040 extern ssize_t __libc_sendto (int __fd, __const void *__buf, size_t __n,
00041                            int __flags, __CONST_SOCKADDR_ARG __addr,
00042                            socklen_t __addr_len);
00043 
00044 /* Read N bytes into BUF through socket FD.
00045    If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
00046    the sender, and store the actual size of the address in *ADDR_LEN.
00047    Returns the number of bytes read or -1 for errors.  */
00048 extern ssize_t __libc_recvfrom (int __fd, void *__restrict __buf, size_t __n,
00049                             int __flags, __SOCKADDR_ARG __addr,
00050                             socklen_t *__restrict __addr_len);
00051 
00052 /* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
00053    For connectionless socket types, just set the default address to send to
00054    and the only address from which to accept transmissions.
00055    Return 0 on success, -1 for errors.  */
00056 extern int __libc_connect (int __fd, __CONST_SOCKADDR_ARG __addr,
00057                         socklen_t __len);
00058 extern int __connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
00059 extern int __connect_internal (int __fd, __CONST_SOCKADDR_ARG __addr,
00060                             socklen_t __len) attribute_hidden;
00061 
00062 /* Read N bytes into BUF from socket FD.
00063    Returns the number read or -1 for errors.
00064 
00065    This function is a cancellation point and therefore not marked with
00066    __THROW.  */
00067 extern ssize_t __recv (int __fd, void *__buf, size_t __n, int __flags)
00068      attribute_hidden;
00069 
00070 /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
00071    ADDR_LEN bytes long).  Returns the number sent, or -1 for errors.  */
00072 extern ssize_t __libc_sendto (int __fd, __const void *__buf, size_t __n,
00073                            int __flags, __CONST_SOCKADDR_ARG __addr,
00074                            socklen_t __addr_len);
00075 extern ssize_t __sendto (int __fd, __const void *__buf, size_t __n,
00076                       int __flags, __CONST_SOCKADDR_ARG __addr,
00077                       socklen_t __addr_len) attribute_hidden;
00078 
00079 /* Read N bytes into BUF through socket FD.
00080    If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
00081    the sender, and store the actual size of the address in *ADDR_LEN.
00082    Returns the number of bytes read or -1 for errors.  */
00083 extern ssize_t __recvfrom (int __fd, void *__restrict __buf, size_t __n,
00084                         int __flags, __SOCKADDR_ARG __addr,
00085                         socklen_t *__restrict __addr_len) attribute_hidden;
00086 
00087 /* Send a message described MESSAGE on socket FD.
00088    Returns the number of bytes sent, or -1 for errors.  */
00089 extern ssize_t __libc_sendmsg (int __fd, __const struct msghdr *__message,
00090                             int __flags);
00091 extern ssize_t __sendmsg (int __fd, __const struct msghdr *__message,
00092                        int __flags) attribute_hidden;
00093 
00094 /* Receive a message as described by MESSAGE from socket FD.
00095    Returns the number of bytes read or -1 for errors.  */
00096 extern ssize_t __libc_recvmsg (int __fd, struct msghdr *__message,
00097                             int __flags);
00098 extern ssize_t __recvmsg (int __fd, struct msghdr *__message,
00099                        int __flags) attribute_hidden;
00100 
00101 /* Set socket FD's option OPTNAME at protocol level LEVEL
00102    to *OPTVAL (which is OPTLEN bytes long).
00103    Returns 0 on success, -1 for errors.  */
00104 extern int __setsockopt (int __fd, int __level, int __optname,
00105                       __const void *__optval,
00106                       socklen_t __optlen) attribute_hidden;
00107 
00108 /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
00109    into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
00110    actual length.  Returns 0 on success, -1 for errors.  */
00111 extern int __getsockopt (int __fd, int __level, int __optname,
00112                       void *__restrict __optval,
00113                       socklen_t *__restrict __optlen) attribute_hidden;
00114 
00115 /* Put the local address of FD into *ADDR and its length in *LEN.  */
00116 extern int __getsockname (int __fd, __SOCKADDR_ARG __addr,
00117                        socklen_t *__restrict __len) attribute_hidden;
00118 
00119 /* Give the socket FD the local address ADDR (which is LEN bytes long).  */
00120 extern int __bind (int __fd, __CONST_SOCKADDR_ARG __addr,
00121                  socklen_t __len) attribute_hidden;
00122 
00123 /* Prepare to accept connections on socket FD.
00124    N connection requests will be queued before further requests are refused.
00125    Returns 0 on success, -1 for errors.  */
00126 extern int __listen (int __fd, int __n) attribute_hidden;
00127 
00128 /* Await a connection on socket FD.
00129    When a connection arrives, open a new socket to communicate with it,
00130    set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
00131    peer and *ADDR_LEN to the address's actual length, and return the
00132    new socket's descriptor, or -1 for errors.  */
00133 extern int __libc_accept (int __fd, __SOCKADDR_ARG __addr,
00134                        socklen_t *__restrict __addr_len)
00135      __THROW;
00136 libc_hidden_proto (accept)
00137 
00138 /* Return the length of a `sockaddr' structure.  */
00139 #ifdef _HAVE_SA_LEN
00140 # define SA_LEN(_x)      (_x)->sa_len
00141 #else
00142 extern int __libc_sa_len (sa_family_t __af);
00143 extern int __libc_sa_len_internal (sa_family_t __af) attribute_hidden;
00144 # ifndef NOT_IN_libc
00145 #  define SA_LEN(_x)      INTUSE(__libc_sa_len)((_x)->sa_family)
00146 # else
00147 #  define SA_LEN(_x)      __libc_sa_len((_x)->sa_family)
00148 # endif
00149 #endif
00150 
00151 
00152 #ifndef NOT_IN_libc
00153 # define __connect(fd, addr, len) INTUSE(__connect) (fd, addr, len)
00154 #endif
00155 
00156 #ifdef SOCK_CLOEXEC
00157 extern int __have_sock_cloexec;
00158 /* At lot of other functionality became available at the same time as
00159    SOCK_CLOEXEC.  Avoid defining separate variables for all of them
00160    unless it is really necessary.  */
00161 # define __have_paccept __have_sock_cloexec
00162 #endif
00163 
00164 #endif