home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Tools / MorphOS / cvs-1.11.2 / source / amiga / netinclude / sys / socket.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-18  |  11.2 KB  |  352 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.6 (Berkeley) 5/3/95
  34.  */
  35.  
  36. #ifndef _SYS_SOCKET_H_
  37. #define    _SYS_SOCKET_H_
  38.  
  39. #ifndef EXEC_TYPES_H
  40. #include <exec/types.h>
  41. #endif /* EXEC_TYPES_H */
  42.  
  43. /*
  44.  * Definitions related to sockets: types, address families, options.
  45.  */
  46.  
  47. /*
  48.  * Types
  49.  */
  50. #define    SOCK_STREAM    1        /* stream socket */
  51. #define    SOCK_DGRAM    2        /* datagram socket */
  52. #define    SOCK_RAW    3        /* raw-protocol interface */
  53. #define    SOCK_RDM    4        /* reliably-delivered message */
  54. #define    SOCK_SEQPACKET    5        /* sequenced packet stream */
  55.  
  56. /*
  57.  * Option flags per-socket.
  58.  */
  59. #define    SO_DEBUG    0x0001        /* turn on debugging info recording */
  60. #define    SO_ACCEPTCONN    0x0002        /* socket has had listen() */
  61. #define    SO_REUSEADDR    0x0004        /* allow local address reuse */
  62. #define    SO_KEEPALIVE    0x0008        /* keep connections alive */
  63. #define    SO_DONTROUTE    0x0010        /* just use interface addresses */
  64. #define    SO_BROADCAST    0x0020        /* permit sending of broadcast msgs */
  65. #define    SO_USELOOPBACK    0x0040        /* bypass hardware when possible */
  66. #define    SO_LINGER    0x0080        /* linger on close if data present */
  67. #define    SO_OOBINLINE    0x0100        /* leave received OOB data in line */
  68. #define    SO_REUSEPORT    0x0200        /* allow local address & port reuse */
  69.  
  70. /*
  71.  * Additional options, not kept in so_options.
  72.  */
  73. #define SO_SNDBUF    0x1001        /* send buffer size */
  74. #define SO_RCVBUF    0x1002        /* receive buffer size */
  75. #define SO_SNDLOWAT    0x1003        /* send low-water mark */
  76. #define SO_RCVLOWAT    0x1004        /* receive low-water mark */
  77. #define SO_SNDTIMEO    0x1005        /* send timeout */
  78. #define SO_RCVTIMEO    0x1006        /* receive timeout */
  79. #define    SO_ERROR    0x1007        /* get error status and clear */
  80. #define    SO_TYPE        0x1008        /* get socket type */
  81.  
  82. /*
  83.  * Structure used for manipulating linger option.
  84.  */
  85. struct    linger {
  86.     LONG    l_onoff;        /* option on/off */
  87.     LONG    l_linger;        /* linger time in seconds */
  88. };
  89.  
  90. /*
  91.  * Level number for (get/set)sockopt() to apply to socket itself.
  92.  */
  93. #define    SOL_SOCKET    0xffff        /* options for socket level */
  94.  
  95. /*
  96.  * Address families.
  97.  */
  98. #define    AF_UNSPEC    0        /* unspecified */
  99. #define    AF_LOCAL    1        /* local to host (pipes, portals) */
  100. #define    AF_UNIX        AF_LOCAL    /* backward compatibility */
  101. #define    AF_INET        2        /* internetwork: UDP, TCP, etc. */
  102. #define    AF_IMPLINK    3        /* arpanet imp addresses */
  103. #define    AF_PUP        4        /* pup protocols: e.g. BSP */
  104. #define    AF_CHAOS    5        /* mit CHAOS protocols */
  105. #define    AF_NS        6        /* XEROX NS protocols */
  106. #define    AF_ISO        7        /* ISO protocols */
  107. #define    AF_OSI        AF_ISO
  108. #define    AF_ECMA        8        /* european computer manufacturers */
  109. #define    AF_DATAKIT    9        /* datakit protocols */
  110. #define    AF_CCITT    10        /* CCITT protocols, X.25 etc */
  111. #define    AF_SNA        11        /* IBM SNA */
  112. #define AF_DECnet    12        /* DECnet */
  113. #define AF_DLI        13        /* DEC Direct data link interface */
  114. #define AF_LAT        14        /* LAT */
  115. #define    AF_HYLINK    15        /* NSC Hyperchannel */
  116. #define    AF_APPLETALK    16        /* Apple Talk */
  117. #define    AF_ROUTE    17        /* Internal Routing Protocol */
  118. #define    AF_LINK        18        /* Link layer interface */
  119. #define    pseudo_AF_XTP    19        /* eXpress Transfer Protocol (no AF) */
  120. #define    AF_COIP        20        /* connection-oriented IP, aka ST II */
  121. #define    AF_CNT        21        /* Computer Network Technology */
  122. #define pseudo_AF_RTIP    22        /* Help Identify RTIP packets */
  123. #define    AF_IPX        23        /* Novell Internet Protocol */
  124. #define    AF_SIP        24        /* Simple Internet Protocol */
  125. #define pseudo_AF_PIP    25        /* Help Identify PIP packets */
  126.  
  127. #define    AF_MAX        26
  128.  
  129. /*
  130.  * Structure used by kernel to store most
  131.  * addresses.
  132.  */
  133. struct sockaddr {
  134.     UBYTE    sa_len;            /* total length */
  135.     UBYTE    sa_family;        /* address family */
  136.     UBYTE    sa_data[14];        /* actually longer; address value */
  137. };
  138.  
  139. /*
  140.  * Structure used by kernel to pass protocol
  141.  * information in raw sockets.
  142.  */
  143. struct sockproto {
  144.     UWORD    sp_family;        /* address family */
  145.     UWORD    sp_protocol;        /* protocol */
  146. };
  147.  
  148. /*
  149.  * Protocol families, same as address families for now.
  150.  */
  151. #define    PF_UNSPEC    AF_UNSPEC
  152. #define    PF_LOCAL    AF_LOCAL
  153. #define    PF_UNIX        PF_LOCAL    /* backward compatibility */
  154. #define    PF_INET        AF_INET
  155. #define    PF_IMPLINK    AF_IMPLINK
  156. #define    PF_PUP        AF_PUP
  157. #define    PF_CHAOS    AF_CHAOS
  158. #define    PF_NS        AF_NS
  159. #define    PF_ISO        AF_ISO
  160. #define    PF_OSI        AF_ISO
  161. #define    PF_ECMA        AF_ECMA
  162. #define    PF_DATAKIT    AF_DATAKIT
  163. #define    PF_CCITT    AF_CCITT
  164. #define    PF_SNA        AF_SNA
  165. #define PF_DECnet    AF_DECnet
  166. #define PF_DLI        AF_DLI
  167. #define PF_LAT        AF_LAT
  168. #define    PF_HYLINK    AF_HYLINK
  169. #define    PF_APPLETALK    AF_APPLETALK
  170. #define    PF_ROUTE    AF_ROUTE
  171. #define    PF_LINK        AF_LINK
  172. #define    PF_XTP        pseudo_AF_XTP    /* really just proto family, no AF */
  173. #define    PF_COIP        AF_COIP
  174. #define    PF_CNT        AF_CNT
  175. #define    PF_SIP        AF_SIP
  176. #define    PF_IPX        AF_IPX        /* same format as AF_NS */
  177. #define PF_RTIP        pseudo_AF_FTIP    /* same format as AF_INET */
  178. #define PF_PIP        pseudo_AF_PIP
  179.  
  180. #define    PF_MAX        AF_MAX
  181.  
  182. /*
  183.  * Definitions for network related sysctl, CTL_NET.
  184.  *
  185.  * Second level is protocol family.
  186.  * Third level is protocol number.
  187.  *
  188.  * Further levels are defined by the individual families below.
  189.  */
  190. #define NET_MAXID    AF_MAX
  191.  
  192. /*
  193.  * PF_ROUTE - Routing table
  194.  *
  195.  * Three additional levels are defined:
  196.  *    Fourth: address family, 0 is wildcard
  197.  *    Fifth: type of info, defined below
  198.  *    Sixth: flag(s) to mask with for NET_RT_FLAGS
  199.  */
  200. #define NET_RT_DUMP    1        /* dump; may limit to a.f. */
  201. #define NET_RT_FLAGS    2        /* by flags, e.g. RESOLVING */
  202. #define NET_RT_IFLIST    3        /* survey interface list */
  203. #define    NET_RT_MAXID    4
  204.  
  205. /*
  206.  * Maximum queue length specifiable by listen.
  207.  */
  208. #define    SOMAXCONN    5
  209.  
  210. /*
  211.  * This is from <sys/uio.h>
  212.  */
  213. struct iovec {
  214.     APTR    iov_base;    /* Base address. */
  215.     LONG    iov_len;    /* Length. */
  216. };
  217.  
  218. /*
  219.  * Message header for recvmsg and sendmsg calls.
  220.  * Used value-result for recvmsg, value only for sendmsg.
  221.  */
  222. struct msghdr {
  223.     APTR    msg_name;        /* optional address */
  224.     ULONG    msg_namelen;        /* size of address */
  225.     struct    iovec *msg_iov;        /* scatter/gather array */
  226.     ULONG    msg_iovlen;        /* # elements in msg_iov */
  227.     APTR    msg_control;        /* ancillary data, see below */
  228.     ULONG    msg_controllen;        /* ancillary data buffer len */
  229.     LONG    msg_flags;        /* flags on received message */
  230. };
  231.  
  232. #define    MSG_OOB        0x1        /* process out-of-band data */
  233. #define    MSG_PEEK    0x2        /* peek at incoming message */
  234. #define    MSG_DONTROUTE    0x4        /* send without using routing tables */
  235. #define    MSG_EOR        0x8        /* data completes record */
  236. #define    MSG_TRUNC    0x10        /* data discarded before delivery */
  237. #define    MSG_CTRUNC    0x20        /* control data lost before delivery */
  238. #define    MSG_WAITALL    0x40        /* wait for full request or error */
  239. #define    MSG_DONTWAIT    0x80        /* this message should be nonblocking */
  240.  
  241. /*
  242.  * Header for ancillary data objects in msg_control buffer.
  243.  * Used for additional information with/about a datagram
  244.  * not expressible by flags.  The format is a sequence
  245.  * of message elements headed by cmsghdr structures.
  246.  */
  247. struct cmsghdr {
  248.     ULONG    cmsg_len;        /* data byte count, including hdr */
  249.     LONG    cmsg_level;        /* originating protocol */
  250.     LONG    cmsg_type;        /* protocol-specific type */
  251. /* followed by    UBYTE  cmsg_data[]; */
  252. };
  253.  
  254. /* given pointer to struct cmsghdr, return pointer to data */
  255. #define    CMSG_DATA(cmsg)        ((UBYTE *)((cmsg) + 1))
  256.  
  257. /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
  258. #define    CMSG_NXTHDR(mhdr, cmsg)    \
  259.     (((APTR)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
  260.         (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
  261.         (struct cmsghdr *)NULL : \
  262.         (struct cmsghdr *)((APTR)(cmsg) + ALIGN((cmsg)->cmsg_len)))
  263.  
  264. #define    CMSG_FIRSTHDR(mhdr)    ((struct cmsghdr *)(mhdr)->msg_control)
  265.  
  266. /* "Socket"-level control message types: */
  267. #define    SCM_RIGHTS    0x01        /* access rights (array of LONG) */
  268.  
  269. /*
  270.  * The following comes from the original <sys/types.h> header file,
  271.  * which has been retired in favour of the Amiga specific <exec/types.h>
  272.  * type definitions. What remains are the macros in support of the
  273.  * "select()" call and those for endian-neutral operations.
  274.  */
  275.  
  276. /*
  277.  * Macros for network/external number representation conversion.
  278.  */
  279. #define    ntohl(x) (x)
  280. #define    ntohs(x) (x)
  281. #define    htonl(x) (x)
  282. #define    htons(x) (x)
  283.  
  284. #define    NTOHL(x) (x)
  285. #define    NTOHS(x) (x)
  286. #define    HTONL(x) (x)
  287. #define    HTONS(x) (x)
  288.  
  289. /*
  290.  * In case the select() data structures and macros are already
  291.  * defined by somebody else...
  292.  */
  293.  
  294. #ifndef FD_SET
  295.  
  296. #define    NBBY 8    /* number of bits in a byte */
  297.  
  298. /*
  299.  * We are going to reference memcpy() and memset() below, which is why
  300.  * we need to make sure that both are declared somewhere.
  301.  */
  302. #include <string.h>
  303. #include <stdlib.h>
  304.  
  305. /*
  306.  * Select uses bit masks of file descriptors in longs.  These macros
  307.  * manipulate such bit fields (the filesystem macros use chars).
  308.  * FD_SETSIZE may be defined by the user, but the default here should
  309.  * be enough for most uses.
  310.  */
  311. #ifndef    FD_SETSIZE
  312. #define    FD_SETSIZE 256
  313. #endif
  314.  
  315. typedef LONG fd_mask;
  316. #define NFDBITS    (sizeof(fd_mask) * NBBY) /* bits per mask */
  317.  
  318. #ifndef howmany
  319. #define    howmany(x, y)    (((x) + ((y) - 1)) / (y))
  320. #endif
  321.  
  322. typedef    struct fd_set {
  323.     fd_mask    fds_bits[howmany(FD_SETSIZE, NFDBITS)];
  324. } fd_set;
  325.  
  326. #define    FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  327. #define    FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  328. #define    FD_ISSET(n, p)    ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  329. #define    FD_COPY(f, t)    memcpy(t, f, sizeof(*(f)))
  330. #define    FD_ZERO(p)    memset(p, 0, sizeof(*(p)))
  331.  
  332. /*
  333.  * This is for compatibility with POSIX-like 'timeval' structures
  334.  * which are remarkably similar to the Amiga 'timeval' except for
  335.  * the structure member names...
  336.  */
  337. #ifndef DEVICES_TIMER_H
  338. //#include <devices/timer.h>
  339. #endif /* DEVICES_TIMER_H */
  340.  
  341. #ifndef tv_sec
  342. #define tv_sec tv_secs
  343. #endif /* tv_sec */
  344.  
  345. #ifndef tv_usec
  346. #define tv_usec tv_micro
  347. #endif /* tv_usec */
  348.  
  349. #endif /* FD_SET */
  350.  
  351. #endif /* !_SYS_SOCKET_H_ */
  352.