home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / socket / sys / socket.h next >
Encoding:
C/C++ Source or Header  |  1994-10-14  |  11.5 KB  |  308 lines

  1. /* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #ifndef    _SYS_SOCKET_H
  20.  
  21. #define    _SYS_SOCKET_H    1
  22. #include <features.h>
  23.  
  24. __BEGIN_DECLS
  25.  
  26. #define    __need_size_t
  27. #include <stddef.h>
  28.  
  29.  
  30. /* Types of sockets.  */
  31. enum __socket_type
  32. {
  33.   SOCK_STREAM = 1,        /* Sequenced, reliable, connection-based
  34.                    byte streams.  */
  35.   SOCK_DGRAM = 2,        /* Connectionless, unreliable datagrams
  36.                    of fixed maximum length.  */
  37.   SOCK_RAW = 3,            /* Raw protocol interface.  */
  38.   SOCK_RDM = 4,            /* Reliably-delivered messages.  */
  39.   SOCK_SEQPACKET = 5,        /* Sequenced, reliable, connection-based,
  40.                    datagrams of fixed maximum length.  */
  41. };
  42.  
  43. /* Protocol families.  */
  44. #define    PF_UNSPEC    0    /* Unspecified.  */
  45. #define    PF_LOCAL    1    /* Local to host (pipes and file-domain).  */
  46. #define    PF_UNIX        PF_LOCAL /* Old BSD name for PF_LOCAL.  */
  47. #define    PF_INET        2    /* IP protocol family.  */
  48. #define    PF_IMPLINK    3    /* ARPAnet IMP protocol.  */
  49. #define    PF_PUP        4    /* PUP protocols.  */
  50. #define    PF_CHAOS    5    /* MIT Chaos protocols.  */
  51. #define    PF_NS        6    /* Xerox NS protocols.  */
  52. #define    PF_ISO        7    /* ISO protocols.  */
  53. #define    PF_OSI        PF_ISO
  54. #define    PF_ECMA        8    /* ECMA protocols.  */
  55. #define    PF_DATAKIT    9    /* AT&T Datakit protocols.  */
  56. #define    PF_CCITT    10    /* CCITT protocols (X.25 et al).  */
  57. #define    PF_SNA        11    /* IBM SNA protocol.  */
  58. #define    PF_DECnet    12    /* DECnet protocols.  */
  59. #define    PF_DLI        13    /* Direct data link interface.  */
  60. #define    PF_LAT        14    /* DEC Local Area Transport protocol.  */
  61. #define    PF_HYLINK    15    /* NSC Hyperchannel protocol.  */
  62. #define    PF_APPLETALK    16    /* Don't use this.  */
  63. #define    PF_ROUTE    17    /* Internal Routing Protocol.  */
  64. #define    PF_LINK        18    /* Link layer interface.  */
  65. #define    PF_XTP        19    /* eXpress Transfer Protocol (no AF).  */
  66. #define    PF_COIP        20    /* Connection-oriented IP, aka ST II.  */
  67. #define    PF_CNT        21    /* Computer Network Technology.  */
  68. #define PF_RTIP        22    /* Help Identify RTIP packets.  **/
  69. #define    PF_IPX        23    /* Novell Internet Protocol.  */
  70. #define    PF_SIP        24    /* Simple Internet Protocol.  */
  71. #define PF_PIP        25    /* Help Identify PIP packets.  */
  72. #define    PF_MAX        26
  73.  
  74. /* Address families.  */
  75. #define    AF_UNSPEC    PF_UNSPEC
  76. #define    AF_LOCAL    PF_LOCAL
  77. #define    AF_UNIX        PF_UNIX
  78. #define    AF_INET        PF_INET
  79. #define    AF_IMPLINK    PF_IMPLINK
  80. #define    AF_PUP        PF_PUP
  81. #define    AF_CHAOS    PF_CHAOS
  82. #define    AF_NS        PF_NS
  83. #define    AF_ISO        PF_ISO
  84. #define    AF_OSI        PF_OSI
  85. #define    AF_ECMA        PF_ECMA
  86. #define    AF_DATAKIT    PF_DATAKIT
  87. #define    AF_CCITT    PF_CCITT
  88. #define    AF_SNA        PF_SNA
  89. #define    AF_DECnet    PF_DECnet
  90. #define    AF_DLI        PF_DLI
  91. #define    AF_LAT        PF_LAT
  92. #define    AF_HYLINK    PF_HYLINK
  93. #define    AF_APPLETALK    PF_APPLETALK
  94. #define    AF_ROUTE    PF_ROUTE
  95. #define    AF_LINK        PF_LINK
  96. #define    pseudo_AF_XTP    PF_XTP
  97. #define    AF_COIP        PF_COIP
  98. #define    AF_CNT        PF_CNT
  99. #define pseudo_AF_RTIP    PF_RTIP
  100. #define    AF_IPX        PF_IPX
  101. #define    AF_SIP        PF_SIP
  102. #define pseudo_AF_PIP    PF_PIP
  103. #define    AF_MAX        PF_MAX
  104.  
  105.  
  106. /* Structure describing a generic socket address.  */
  107. struct sockaddr
  108.   {
  109.     unsigned short int sa_family; /* Address family.  */
  110.     char sa_data[14];        /* Address data.  */
  111.   };
  112.  
  113. /* This is the type we use for generic socket address arguments.
  114.  
  115.    NOTE: Since this functionality is volatile, I'm disabling the use of it for
  116.    now.
  117.  
  118.    With GCC 2.6 and later, the funky union causes redeclarations or uses with
  119.    any of the listed types to be allowed without complaint.  */
  120. #if    (!defined (__GNUC__) || __GNUC__ < 2 || \
  121.      /*(__GNUC__ == 2 && __GNUC_MINOR__ < 6)*/ 1)
  122. #define    __SOCKADDR_ARG    struct sockaddr *
  123. #else
  124. /* Bring these names into being at top-level scope, in case they have not been
  125.    defined yet.  Add more `struct sockaddr_AF' types here as necessary.  */
  126. struct sockaddr_in;
  127. struct sockaddr_un;
  128. struct sockaddr_ns;
  129. typedef union { struct sockaddr *__sa;
  130.         struct sockaddr_in *__sa_in;
  131.         struct sockaddr_un *__sa_un;
  132.         struct sockaddr_ns *__sa_ns;
  133.           } __SOCKADDR_ARG __attribute__ ((transparent_union));
  134. #endif
  135.  
  136.  
  137. /* Create a new socket of type TYPE in domain DOMAIN, using
  138.    protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
  139.    Returns a file descriptor for the new socket, or -1 for errors.  */
  140. extern int socket __P ((int __domain, enum __socket_type __type,
  141.             int __protocol));
  142.  
  143. /* Create two new sockets, of type TYPE in domain DOMAIN and using
  144.    protocol PROTOCOL, which are connected to each other, and put file
  145.    descriptors for them in FDS[0] and FDS[1].  If PROTOCOL is zero,
  146.    one will be chosen automatically.  Returns 0 on success, -1 for errors.  */
  147. extern int socketpair __P ((int __domain, enum __socket_type __type,
  148.                 int __protocol, int __fds[2]));
  149.  
  150. /* Give the socket FD the local address ADDR (which is LEN bytes long).  */
  151. extern int bind __P ((int __fd, __SOCKADDR_ARG __addr, size_t __len));
  152.  
  153. /* Put the local address of FD into *ADDR and its length in *LEN.  */
  154. extern int getsockname __P ((int __fd, __SOCKADDR_ARG __addr,
  155.                  size_t *__len));
  156.  
  157. /* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
  158.    For connectionless socket types, just set the default address to send to
  159.    and the only address from which to accept transmissions.
  160.    Return 0 on success, -1 for errors.  */
  161. extern int connect __P ((int __fd, __SOCKADDR_ARG __addr, size_t __len));
  162.  
  163. /* Put the address of the peer connected to socket FD into *ADDR
  164.    (which is *LEN bytes long), and its actual length into *LEN.  */
  165. extern int getpeername __P ((int __fd, __SOCKADDR_ARG __addr,
  166.                  size_t *__len));
  167.  
  168.  
  169. /* Bits in the FLAGS argument to `send', `recv', et al.  */
  170. enum
  171.   {
  172.     MSG_OOB        = 0x01,    /* Process out-of-band data.  */
  173.     MSG_PEEK        = 0x02,    /* Peek at incoming messages.  */
  174.     MSG_DONTROUTE    = 0x04,    /* Don't use local routing.  */
  175.     MSG_EOR        = 0x08,    /* Data completes record.  */
  176.     MSG_TRUNC        = 0x10,    /* Data discarded before delivery.  */
  177.     MSG_CTRUNC        = 0x20,    /* Control data lost before delivery.  */
  178.     MSG_WAITALL        = 0x40,    /* Wait for full request or error.  */
  179.     MSG_DONTWAIT    = 0x80,    /* This message should be nonblocking.  */
  180.   };
  181.  
  182. /* Send N bytes of BUF to socket FD.  Returns the number sent or -1.  */
  183. extern int send __P ((int __fd, __ptr_t __buf, size_t __n, int __flags));
  184.  
  185. /* Read N bytes into BUF from socket FD.
  186.    Returns the number read or -1 for errors.  */
  187. extern int recv __P ((int __fd, __ptr_t __buf, size_t __n, int __flags));
  188.  
  189. /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
  190.    ADDR_LEN bytes long).  Returns the number sent, or -1 for errors.  */
  191. extern int sendto __P ((int __fd, __ptr_t __buf, size_t __n, int __flags,
  192.             __SOCKADDR_ARG __addr, size_t __addr_len));
  193.  
  194. /* Read N bytes into BUF through socket FD.
  195.    If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
  196.    the sender, and store the actual size of the address in *ADDR_LEN.
  197.    Returns the number of bytes read or -1 for errors.  */
  198. extern int recvfrom __P ((int __fd, __ptr_t __buf, size_t __n, int __flags,
  199.               __SOCKADDR_ARG __addr, size_t *__addr_len));
  200.  
  201.  
  202.  
  203. /* Structure describing messages sent by
  204.    `sendmsg' and received by `recvmsg'.  */
  205. struct msghdr
  206.   {
  207.     __ptr_t msg_name;        /* Address to send to/receive from.  */
  208.     size_t msg_namelen;        /* Length of address data.  */
  209.  
  210.     struct iovec *msg_iov;    /* Vector of data to send/receive into.  */
  211.     size_t msg_iovlen;        /* Number of elements in the vector.  */
  212.  
  213.     __ptr_t msg_accrights;    /* Access rights information.  */
  214.     size_t msg_accrightslen;    /* Length of access rights information.  */
  215.   };
  216.  
  217. /* Send a message described MESSAGE on socket FD.
  218.    Returns the number of bytes sent, or -1 for errors.  */
  219. extern int sendmsg __P ((int __fd, __const struct msghdr *__message,
  220.              int __flags));
  221.  
  222. /* Receive a message as described by MESSAGE from socket FD.
  223.    Returns the number of bytes read or -1 for errors.  */
  224. extern int recvmsg __P ((int __fd, struct msghdr *__message, int __flags));
  225.  
  226.  
  227. /* Protocol number used to manipulate socket-level options
  228.    with `getsockopt' and `setsockopt'.  */
  229. #define    SOL_SOCKET    0xffff
  230.  
  231. /* Socket-level options for `getsockopt' and `setsockopt'.  */
  232. enum
  233.   {
  234.     SO_DEBUG = 0x0001,        /* Record debugging information.  */
  235.     SO_ACCEPTCONN = 0x0002,    /* Accept connections on socket.  */
  236.     SO_REUSEADDR = 0x0004,    /* Allow reuse of local addresses.  */
  237.     SO_KEEPALIVE = 0x0008,    /* Keep connections alive and send
  238.                    SIGPIPE when they die.  */
  239.     SO_DONTROUTE = 0x0010,    /* Don't do local routing.  */
  240.     SO_BROADCAST = 0x0020,    /* Allow transmission of
  241.                    broadcast messages.  */
  242.     SO_USELOOPBACK = 0x0040,    /* Use the software loopback to avoid
  243.                    hardware use when possible.  */
  244.     SO_LINGER = 0x0080,        /* Block on close of a reliable
  245.                    socket to transmit pending data.  */
  246.     SO_OOBINLINE = 0x0100,    /* Receive out-of-band data in-band.  */
  247.  
  248.     SO_REUSEPORT = 0x0200,    /* Allow local address and port reuse.  */
  249.  
  250.     SO_SNDBUF = 0x1001,        /* Send buffer size.  */
  251.     SO_RCVBUF = 0x1002,        /* Receive buffer.  */
  252.     SO_SNDLOWAT = 0x1003,    /* Send low-water mark.  */
  253.     SO_RCVLOWAT = 0x1004,    /* Receive low-water mark.  */
  254.     SO_SNDTIMEO = 0x1005,    /* Send timeout.  */
  255.     SO_RCVTIMEO = 0x1006,    /* Receive timeout.  */
  256.  
  257.     SO_ERROR = 0x1007,        /* Get and clear error status.  */
  258.     SO_STYLE = 0x1008,        /* Get socket connection style.  */
  259.     SO_TYPE = SO_STYLE,        /* Compatible name for SO_STYLE.  */
  260.   };
  261.  
  262. /* Structure used to manipulate the SO_LINGER option.  */
  263. struct linger
  264.   {
  265.     int l_onoff;        /* Nonzero to linger on close.  */
  266.     int l_linger;        /* Time to linger.  */
  267.   };
  268.  
  269.  
  270. /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
  271.    into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
  272.    actual length.  Returns 0 on success, -1 for errors.  */
  273. extern int getsockopt __P ((int __fd, int __level, int __optname,
  274.                 __ptr_t __optval, size_t *__optlen));
  275.  
  276. /* Set socket FD's option OPTNAME at protocol level LEVEL
  277.    to *OPTVAL (which is OPTLEN bytes long).
  278.    Returns 0 on success, -1 for errors.  */
  279. extern int setsockopt __P ((int __fd, int __level, int __optname,
  280.                 __ptr_t __optval, size_t __optlen));
  281.  
  282.  
  283. /* Prepare to accept connections on socket FD.
  284.    N connection requests will be queued before further requests are refused.
  285.    Returns 0 on success, -1 for errors.  */
  286. extern int listen __P ((int __fd, unsigned int __n));
  287.  
  288. /* Await a connection on socket FD.
  289.    When a connection arrives, open a new socket to communicate with it,
  290.    set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
  291.    peer and *ADDR_LEN to the address's actual length, and return the
  292.    new socket's descriptor, or -1 for errors.  */
  293. extern int accept __P ((int __fd, __SOCKADDR_ARG __addr,
  294.             size_t *__addr_len));
  295.  
  296. /* Shut down all or part of the connection open on socket FD.
  297.    HOW determines what to shut down:
  298.      0 = No more receptions;
  299.      1 = No more transmissions;
  300.      2 = No more receptions or transmissions.
  301.    Returns 0 on success, -1 for errors.  */
  302. extern int shutdown __P ((int __fd, int __how));
  303.  
  304.  
  305. __END_DECLS
  306.  
  307. #endif /* sys/socket.h */
  308.