home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / languages / netlib / !NetLib / sys / h / socket < prev    next >
Encoding:
Text File  |  1995-08-19  |  9.2 KB  |  262 lines

  1. /*
  2.  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)socket.h    8.4 (Berkeley) 2/21/94
  34.  */
  35.  
  36. #ifndef __sys_socket_h
  37. #define __sys_socket_h
  38.  
  39. /* Freenet programmers interface - sys/socket.h - edit by andy 23/5/95 */
  40.  
  41. #include "Internet:sys.h.types"
  42.  
  43. /*
  44.  * Definitions related to sockets: types, address families, options.
  45.  */
  46.  
  47. /*
  48.  * Socket types
  49.  */
  50. #define SOCK_STREAM     1         /* Stream socket */
  51. #define SOCK_DGRAM    2         /* Datagram socket */
  52. #define SOCK_RAW    3         /* Raw socket */
  53. #define    SOCK_RDM    4      /* reliably-delivered message */
  54. #define    SOCK_SEQPACKET    5      /* sequenced packet stream */
  55.  
  56. /*
  57.  * Address families
  58.  */
  59. #define    AF_UNSPEC       0        /* unspecified */
  60. #define    AF_LOCAL    1        /* local to host (pipes, portals) */
  61. #define    AF_UNIX        AF_LOCAL    /* backward compatibility */
  62. #define AF_INET     2         /* Internet */
  63. #define    AF_IMPLINK    3        /* arpanet imp addresses */
  64. #define    AF_PUP        4        /* pup protocols: e.g. BSP */
  65. #define    AF_CHAOS    5        /* mit CHAOS protocols */
  66. #define    AF_NS        6        /* XEROX NS protocols */
  67. #define    AF_ISO        7        /* ISO protocols */
  68. #define    AF_OSI        AF_ISO
  69. #define    AF_ECMA        8        /* european computer manufacturers */
  70. #define    AF_DATAKIT    9        /* datakit protocols */
  71. #define    AF_CCITT    10        /* CCITT protocols, X.25 etc */
  72. #define    AF_SNA        11        /* IBM SNA */
  73. #define AF_DECnet    12        /* DECnet */
  74. #define AF_DLI        13        /* DEC Direct data link interface */
  75. #define AF_LAT        14        /* LAT */
  76. #define    AF_HYLINK    15        /* NSC Hyperchannel */
  77. #define    AF_APPLETALK    16        /* Apple Talk */
  78. #define    AF_ROUTE    17        /* Internal Routing Protocol */
  79. #define    AF_LINK        18        /* Link layer interface */
  80. #define    pseudo_AF_XTP    19        /* eXpress Transfer Protocol (no AF) */
  81. #define    AF_COIP        20        /* connection-oriented IP, aka ST II */
  82. #define    AF_CNT        21        /* Computer Network Technology */
  83. #define pseudo_AF_RTIP    22        /* Help Identify RTIP packets */
  84. #define    AF_IPX        23        /* Novell Internet Protocol */
  85. #define    AF_SIP        24        /* Simple Internet Protocol */
  86. #define pseudo_AF_PIP    25        /* Help Identify PIP packets */
  87.  
  88. #define    AF_MAX        26
  89.  
  90. /*
  91.  * Protocol families
  92.  */
  93. #define    PF_UNSPEC    AF_UNSPEC
  94. #define    PF_LOCAL    AF_LOCAL
  95. #define    PF_UNIX        PF_LOCAL    /* backward compatibility */
  96. #define PF_INET     AF_INET   /* Internet */
  97. #define    PF_IMPLINK    AF_IMPLINK
  98. #define    PF_PUP        AF_PUP
  99. #define    PF_CHAOS    AF_CHAOS
  100. #define    PF_NS        AF_NS
  101. #define    PF_ISO        AF_ISO
  102. #define    PF_OSI        AF_ISO
  103. #define    PF_ECMA        AF_ECMA
  104. #define    PF_DATAKIT    AF_DATAKIT
  105. #define    PF_CCITT    AF_CCITT
  106. #define    PF_SNA        AF_SNA
  107. #define PF_DECnet    AF_DECnet
  108. #define PF_DLI        AF_DLI
  109. #define PF_LAT        AF_LAT
  110. #define    PF_HYLINK    AF_HYLINK
  111. #define    PF_APPLETALK    AF_APPLETALK
  112. #define    PF_ROUTE    AF_ROUTE
  113. #define    PF_LINK        AF_LINK
  114. #define    PF_XTP        pseudo_AF_XTP    /* really just proto family, no AF */
  115. #define    PF_COIP        AF_COIP
  116. #define    PF_CNT        AF_CNT
  117. #define    PF_SIP        AF_SIP
  118. #define    PF_IPX        AF_IPX        /* same format as AF_NS */
  119. #define PF_RTIP        pseudo_AF_FTIP    /* same format as AF_INET */
  120. #define PF_PIP        pseudo_AF_PIP
  121.  
  122. #define    PF_MAX        AF_MAX
  123.  
  124. /*
  125.  * 4.3 BSD compatibility structure representing socket addresses
  126.  */
  127. struct sockaddr {
  128.   u_short sa_family;          /* Address family */
  129.   char    sa_data[14];        /* Address data (maximum 14 bytes) */
  130. };
  131.  
  132. /*
  133.  * Maximum queue length for listen() calls
  134.  */
  135. #define SOMAXCONN   5
  136.  
  137. struct iovec {
  138.         caddr_t iov_base;
  139.         int     iov_len;
  140. };
  141.  
  142. /*
  143.  * Message header for sendmsg() and recvmsg() calls - this is a
  144.  * struct definition kept from 4.3 BSD to preserve compatibility
  145.  * with the Acorn TCP/IP suite.
  146.  */
  147. struct msghdr {
  148.   caddr_t      msg_name;         /* Address (optional) */
  149.   int          msg_namelen;      /* Address size */
  150.   struct iovec *msg_iov;         /* Scatter/gather array */
  151.   int          msg_iovlen;       /* Number of elements in msg_iov */
  152.   caddr_t      msg_accrights;    /* Access rights */
  153.   int          msg_accrightslen; /* Size of msg_accrights */
  154. };
  155.  
  156. /*
  157.  * Flags for data sending/receiving calls
  158.  */
  159. #define MSG_OOB         0x1      /* Process out-of-band data */
  160. #define MSG_PEEK        0x2      /* Peek at incoming message */
  161. #define MSG_DONTROUTE   0x4      /* Send without routing */
  162. #define    MSG_EOR        0x8     /* data completes record */
  163. #define    MSG_TRUNC    0x10     /* data discarded before delivery */
  164. #define    MSG_CTRUNC    0x20     /* control data lost before delivery */
  165. #define    MSG_WAITALL    0x40     /* wait for full request or error */
  166. #define    MSG_DONTWAIT    0x80     /* this message should be nonblocking */
  167. /*
  168.  * Maximum size of a scatter/gather array
  169.  */
  170. #define MSG_MAXIOVLEN 16
  171.  
  172. /*
  173.  * Option level for socket level options
  174.  */
  175. #define SOL_SOCKET    0xffff
  176.  
  177. /*
  178.  * Available socket level options
  179.  */
  180. #define SO_DEBUG      0x0001     /* Turn on debugging */
  181. #define SO_ACCEPTCONN 0x0002     /* Socket is listening for connections */
  182. #define SO_REUSEADDR  0x0004     /* Allow local reuse of this address */
  183. #define SO_KEEPALIVE  0x0008     /* Keep connections alive */
  184. #define SO_DONTROUTE  0x0010     /* Bypass routing for this socket */
  185. #define SO_BROADCAST  0x0020     /* Allow sending of broadcast messages */
  186. #define    SO_USELOOPBACK    0x0040     /* bypass hardware when possible */
  187. #define SO_LINGER     0x0080     /* Linger on close if data present */
  188. #define SO_OOBINLINE  0x0100     /* Receive OOB data inline */
  189. #define    SO_REUSEPORT  0x0200     /* allow local address & port reuse */
  190.  
  191. #define SO_SNDBUF     0x1001     /* Output buffer size */
  192. #define SO_RCVBUF     0x1002     /* Input buffer size */
  193. #define SO_SNDLOWAT   0x1003     /* send low-water mark */
  194. #define SO_RCVLOWAT   0x1004     /* receive low-water mark */
  195. #define SO_SNDTIMEO   0x1005     /* send timeout */
  196. #define SO_RCVTIMEO   0x1006     /* receive timeout */
  197. #define SO_ERROR      0x1007     /* Get socket type (read only) */
  198. #define SO_TYPE       0x1008     /* Get and clear error (read only) */
  199.  
  200. /*
  201.  * structure used for manipulating SO_LINGER option
  202.  */
  203. struct linger {
  204.   int l_onoff;                   /* Option on/off toggle */
  205.   int l_linger;                  /* Time to linger for */
  206. };
  207.  
  208. /*
  209.  * Create a socket
  210.  */
  211. extern int socket(int /*af*/, int /*type*/, int /*protocol*/);
  212.  
  213. /*
  214.  * Bind a name to a socket
  215.  */
  216. extern int bind(int /*s*/, struct sockaddr * /*name*/, int /*namelen*/);
  217.  
  218. /*
  219.  * Start listening for connections on a socket
  220.  */
  221. extern int listen(int /*s*/, int /*backlog*/);
  222.  
  223. /*
  224.  * Accept a connection on a socket
  225.  */
  226. extern int accept(int /*s*/, struct sockaddr */*name*/, int */*namelen*/);
  227.  
  228. /*
  229.  * Make a connection on a socket
  230.  */
  231. extern int connect(int /*s*/, struct sockaddr */*name*/, int /*namelen*/);
  232.  
  233. /*
  234.  * Routines to receive data on a socket
  235.  */
  236. extern int recv(int /*s*/, char */*msg*/, int /*len*/, int /*flags*/);
  237. extern int recvfrom(int /*s*/, char */*msg*/, int /*len*/, int /*flags*/,
  238.                     struct sockaddr */*from*/, int */*fromlen*/);
  239. extern int recvmsg(int /*s*/, struct msghdr */*msg*/, int /*flags*/);
  240.  
  241. /*
  242.  * Routines to send data from a socket
  243.  */
  244. extern int send(int /*s*/, char */*msg*/, int /*len*/, int /*flags*/);
  245. extern int sendto(int /*s*/, char */*msg*/, int /*len*/, int /*flags*/,
  246.                   struct sockaddr */*to*/, int /*tolen*/);
  247. extern int sendmsg(int /*s*/, struct msghdr * /*msg*/, int /*flags*/);
  248.  
  249. /*
  250.  * Manipulate socket options
  251.  */
  252. extern int setsockopt(int /*s*/, int /*level*/, int /*optname*/, char */*optval*/, int /*optlen*/);
  253. extern int getsockopt(int /*s*/, int /*level*/, int /*optname*/, char */*optval*/, int * /*optlen*/);
  254.  
  255. /*
  256.  * Find the names of a socket and its peer
  257.  */
  258. extern int getsockname(int /*s*/, struct sockaddr */*name*/, int */*namelen*/);
  259. extern int getpeername(int /*s*/, struct sockaddr */*name*/, int */*namelen*/);
  260.  
  261. #endif /* socket.h */
  262.