socket.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:13k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* socket.h - socket header */
  2. /* Copyright 1984 - 2001 Wind River Systems, Inc. */
  3. /* $NetBSD: socket.h,v 1.10 1994/06/29 06:45:27 cgd Exp $ */
  4. /*
  5.  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
  6.  * The Regents of the University of California.  All rights reserved.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. All advertising materials mentioning features or use of this software
  17.  *    must display the following acknowledgement:
  18.  * This product includes software developed by the University of
  19.  * California, Berkeley and its contributors.
  20.  * 4. Neither the name of the University nor the names of its contributors
  21.  *    may be used to endorse or promote products derived from this software
  22.  *    without specific prior written permission.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34.  * SUCH DAMAGE.
  35.  *
  36.  * @(#)socket.h 8.4 (Berkeley) 2/21/94
  37.  */
  38. /*
  39. modification history
  40. --------------------
  41. 03c,12oct01,rae  merge from truestack (path MTU, VIRTUAL_STACK)
  42. 03b,04feb97,vin  added #defines in msghdr struct for backward compatibility.
  43.  the fields msg_accrights in bsd4.3 is used with only 
  44.  unix domains, which we do not support.
  45. 03a,03mar96,vin  integrated with 02e of socket.h.   
  46. 02e,25jul95,dzb  added AF_INET_BSD and AF_INET_STREAMS.
  47. 02d,27mar95,sgv  added Mentat socket.h diffs.
  48. 02c,26sep94,dzb  added MSG_MBUF, MSG_IGNORE_SB socket flags.
  49. 02b,22sep92,rrr  added support for c++
  50. 02a,04jul92,jcf  cleaned up.
  51. 01m,04jul92,smb  made to include vxWorks.h
  52. 01l,26may92,rrr  the tree shuffle
  53. 01k,04oct91,rrr  passed through the ansification filter
  54.   -changed includes to have absolute path from h/
  55.   -fixed #else and #endif
  56.   -changed copyright notice
  57. 01j,10jun91,del  added pragma for gnu960 alignment.
  58. 01h,06oct90,hjb  restored typedef of SOCKADDR
  59. 01g,05oct90,shl  added copyright notice.
  60.                  made #endif ANSI style.
  61. 01f,18mar90,hjb  added MSG_NO_UIO
  62. 01e,16apr89,gae  updated to new 4.3BSD.
  63. 01d,29apr87,dnw  added header and copyright.
  64. 01c,02apr87,ecs  added typedef of SOCKADDR
  65. 01b,21dec86,dnw  added include of types.h
  66. */
  67. #ifndef __INCsocketh
  68. #define __INCsocketh
  69. #ifdef __cplusplus
  70. extern "C" {
  71. #endif
  72. #include "vxWorks.h"
  73. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  74. #pragma align 1 /* tell gcc960 not to optimize alignments */
  75. #endif /* CPU_FAMILY==I960 */
  76. /*
  77.  * Definitions related to sockets: types, address families, options.
  78.  */
  79. /*
  80.  * Types
  81.  */
  82. #define SOCK_STREAM 1 /* stream socket */
  83. #define SOCK_DGRAM 2 /* datagram socket */
  84. #define SOCK_RAW 3 /* raw-protocol interface */
  85. #define SOCK_RDM 4 /* reliably-delivered message */
  86. #define SOCK_SEQPACKET 5 /* sequenced packet stream */
  87. /*
  88.  * Option flags per-socket.
  89.  */
  90. #define SO_DEBUG 0x0001 /* turn on debugging info recording */
  91. #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
  92. #define SO_REUSEADDR 0x0004 /* allow local address reuse */
  93. #define SO_KEEPALIVE 0x0008 /* keep connections alive */
  94. #define SO_DONTROUTE 0x0010 /* just use interface addresses */
  95. #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
  96. #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
  97. #define SO_LINGER 0x0080 /* linger on close if data present */
  98. #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
  99. #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
  100. #define SO_USEPATHMTU  0x0400  /* enable path MTU discovery */
  101. #define SO_VSID         0x0800          /* virtual stack id */
  102. /*
  103.  * Additional options, not kept in so_options.
  104.  */
  105. #define SO_SNDBUF 0x1001 /* send buffer size */
  106. #define SO_RCVBUF 0x1002 /* receive buffer size */
  107. #define SO_SNDLOWAT 0x1003 /* send low-water mark */
  108. #define SO_RCVLOWAT 0x1004 /* receive low-water mark */
  109. #define SO_SNDTIMEO 0x1005 /* send timeout */
  110. #define SO_RCVTIMEO 0x1006 /* receive timeout */
  111. #define SO_ERROR 0x1007 /* get error status and clear */
  112. #define SO_TYPE 0x1008 /* get socket type */
  113. #define SO_PROTOTYPE    0x1009 /* get/set protocol type */
  114. #define SO_PATHMTU_TBL  0x100a  /* get/set path MTU table */
  115. /*
  116.  * An option specification consists of an opthdr, followed by the value of
  117.  * the option.  An options buffer contains one or more options.  The len
  118.  * field of opthdr specifies the length of the option value in bytes.  This
  119.  * length must be a multiple of sizeof (long) (use OPTLEN macro).
  120.  */
  121. struct opthdr {
  122. long  level; /* protocol level affected */
  123. long name; /* option to modify */
  124. long len; /* length of option value */
  125. };
  126. #define OPTLEN(x) ((((x) + sizeof (long) - 1) / sizeof (long)) * sizeof (long))
  127. #define OPTVAL(opt) ((char *)(opt + 1))
  128. /*
  129.  * Structure used for manipulating linger option.
  130.  */
  131. struct linger {
  132. int l_onoff; /* option on/off */
  133. int l_linger; /* linger time */
  134. };
  135. /*
  136.  * Level number for (get/set)sockopt() to apply to socket itself.
  137.  */
  138. #define SOL_SOCKET 0xffff /* options for socket level */
  139. /*
  140.  * Address families.
  141.  */
  142. #define AF_UNSPEC 0 /* unspecified */
  143. #define AF_LOCAL 1 /* local to host (pipes, portals) */
  144. #define AF_UNIX AF_LOCAL /* backward compatibility */
  145. #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
  146. #define AF_IMPLINK 3 /* arpanet imp addresses */
  147. #define AF_PUP 4 /* pup protocols: e.g. BSP */
  148. #define AF_CHAOS 5 /* mit CHAOS protocols */
  149. #define AF_NS 6 /* XEROX NS protocols */
  150. #define AF_ISO 7 /* ISO protocols */
  151. #define AF_OSI AF_ISO
  152. #define AF_ECMA 8 /* european computer manufacturers */
  153. #define AF_DATAKIT 9 /* datakit protocols */
  154. #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
  155. #define AF_SNA 11 /* IBM SNA */
  156. #define AF_DECnet 12 /* DECnet */
  157. #define AF_DLI 13 /* DEC Direct data link interface */
  158. #define AF_LAT 14 /* LAT */
  159. #define AF_HYLINK 15 /* NSC Hyperchannel */
  160. #define AF_APPLETALK 16 /* Apple Talk */
  161. #define AF_ROUTE 17 /* Internal Routing Protocol */
  162. #define AF_LINK 18 /* Link layer interface */
  163. #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
  164. #define AF_COIP 20 /* connection-oriented IP, aka ST II */
  165. #define AF_CNT 21 /* Computer Network Technology */
  166. #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
  167. #define AF_IPX 23 /* Novell Internet Protocol */
  168. #define AF_SIP 24 /* Simple Internet Protocol */
  169. #define pseudo_AF_PIP 25 /* Help Identify PIP packets */
  170. #define AF_MAX 26
  171. #define AF_INET_BSD 100 /* BSD-specific INET af */
  172. #define AF_INET_STREAMS 101 /* STREAMS-specific INET af */
  173. /*
  174.  * Structure used by kernel to store most
  175.  * addresses.
  176.  */
  177. struct sockaddr {
  178. u_char sa_len; /* total length */
  179. u_char sa_family; /* address family */
  180. char sa_data[14]; /* actually longer; address value */
  181. };
  182. typedef struct sockaddr SOCKADDR;
  183. /*
  184.  * Structure used by kernel to pass protocol
  185.  * information in raw sockets.
  186.  */
  187. struct sockproto {
  188. u_short sp_family; /* address family */
  189. u_short sp_protocol; /* protocol */
  190. };
  191. /*
  192.  * Protocol families, same as address families for now.
  193.  */
  194. #define PF_UNSPEC AF_UNSPEC
  195. #define PF_LOCAL AF_LOCAL
  196. #define PF_UNIX PF_LOCAL /* backward compatibility */
  197. #define PF_INET AF_INET
  198. #define PF_IMPLINK AF_IMPLINK
  199. #define PF_PUP AF_PUP
  200. #define PF_CHAOS AF_CHAOS
  201. #define PF_NS AF_NS
  202. #define PF_ISO AF_ISO
  203. #define PF_OSI AF_ISO
  204. #define PF_ECMA AF_ECMA
  205. #define PF_DATAKIT AF_DATAKIT
  206. #define PF_CCITT AF_CCITT
  207. #define PF_SNA AF_SNA
  208. #define PF_DECnet AF_DECnet
  209. #define PF_DLI AF_DLI
  210. #define PF_LAT AF_LAT
  211. #define PF_HYLINK AF_HYLINK
  212. #define PF_APPLETALK AF_APPLETALK
  213. #define PF_ROUTE AF_ROUTE
  214. #define PF_LINK AF_LINK
  215. #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
  216. #define PF_COIP AF_COIP
  217. #define PF_CNT AF_CNT
  218. #define PF_SIP AF_SIP
  219. #define PF_IPX AF_IPX /* same format as AF_NS */
  220. #define PF_RTIP pseudo_AF_FTIP /* same format as AF_INET */
  221. #define PF_PIP pseudo_AF_PIP
  222. #define PF_MAX AF_MAX
  223. /*
  224.  * Definitions for network related sysctl, CTL_NET.
  225.  *
  226.  * Second level is protocol family.
  227.  * Third level is protocol number.
  228.  *
  229.  * Further levels are defined by the individual families below.
  230.  */
  231. #define NET_MAXID AF_MAX
  232. #define CTL_NET_NAMES { 
  233. { 0, 0 }, 
  234. { "unix", CTLTYPE_NODE }, 
  235. { "inet", CTLTYPE_NODE }, 
  236. { "implink", CTLTYPE_NODE }, 
  237. { "pup", CTLTYPE_NODE }, 
  238. { "chaos", CTLTYPE_NODE }, 
  239. { "xerox_ns", CTLTYPE_NODE }, 
  240. { "iso", CTLTYPE_NODE }, 
  241. { "emca", CTLTYPE_NODE }, 
  242. { "datakit", CTLTYPE_NODE }, 
  243. { "ccitt", CTLTYPE_NODE }, 
  244. { "ibm_sna", CTLTYPE_NODE }, 
  245. { "decnet", CTLTYPE_NODE }, 
  246. { "dec_dli", CTLTYPE_NODE }, 
  247. { "lat", CTLTYPE_NODE }, 
  248. { "hylink", CTLTYPE_NODE }, 
  249. { "appletalk", CTLTYPE_NODE }, 
  250. { "route", CTLTYPE_NODE }, 
  251. { "link_layer", CTLTYPE_NODE }, 
  252. { "xtp", CTLTYPE_NODE }, 
  253. { "coip", CTLTYPE_NODE }, 
  254. { "cnt", CTLTYPE_NODE }, 
  255. { "rtip", CTLTYPE_NODE }, 
  256. { "ipx", CTLTYPE_NODE }, 
  257. { "sip", CTLTYPE_NODE }, 
  258. { "pip", CTLTYPE_NODE }, 
  259. }
  260. /*
  261.  * PF_ROUTE - Routing table
  262.  *
  263.  * Three additional levels are defined:
  264.  * Fourth: address family, 0 is wildcard
  265.  * Fifth: type of info, defined below
  266.  * Sixth: flag(s) to mask with for NET_RT_FLAGS
  267.  */
  268. #define NET_RT_DUMP 1 /* dump; may limit to a.f. */
  269. #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
  270. #define NET_RT_IFLIST 3 /* survey interface list */
  271. #define NET_RT_MAXID 4
  272. #define CTL_NET_RT_NAMES { 
  273. { 0, 0 }, 
  274. { "dump", CTLTYPE_STRUCT }, 
  275. { "flags", CTLTYPE_STRUCT }, 
  276. { "iflist", CTLTYPE_STRUCT }, 
  277. }
  278. /*
  279.  * Maximum queue length specifiable by listen.
  280.  */
  281. #define SOMAXCONN 5
  282. /*
  283.  * Message header for recvmsg and sendmsg calls.
  284.  * Used value-result for recvmsg, value only for sendmsg.
  285.  */
  286. struct msghdr {
  287. caddr_t msg_name; /* optional address */
  288. u_int msg_namelen; /* size of address */
  289. struct iovec *msg_iov; /* scatter/gather array */
  290. u_int msg_iovlen; /* # elements in msg_iov */
  291. caddr_t msg_control; /* ancillary data, see below */
  292. u_int msg_controllen; /* ancillary data buffer len */
  293. /* provided for backward compatibility, access rights not supported by wrs */
  294. #define msg_accrights   msg_control
  295. #define msg_accrightslen msg_controllen
  296. int msg_flags; /* flags on received message */
  297. };
  298. #define MSG_OOB 0x1 /* process out-of-band data */
  299. #define MSG_PEEK 0x2 /* peek at incoming message */
  300. #define MSG_DONTROUTE 0x4 /* send without using routing tables */
  301. #if 1 /* OLD XXX */
  302. #define MSG_NO_UIO 0x8 /* for system use only */
  303. #endif /* XXX */
  304. #define MSG_EOR 0x8 /* data completes record */
  305. #define MSG_TRUNC 0x10 /* data discarded before delivery */
  306. #define MSG_CTRUNC 0x20 /* control data lost before delivery */
  307. #define MSG_WAITALL 0x40 /* wait for full request or error */
  308. #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
  309. #define MSG_MBUF 0x10000 /* mbuf interface - WRS ext. */
  310. #define MSG_IGNORE_SB 0x20000 /* ignore socket write buf - WRS ext. */
  311. #define MSG_MAXIOVLEN 16
  312. /*
  313.  * Header for ancillary data objects in msg_control buffer.
  314.  * Used for additional information with/about a datagram
  315.  * not expressible by flags.  The format is a sequence
  316.  * of message elements headed by cmsghdr structures.
  317.  */
  318. struct cmsghdr {
  319. u_int cmsg_len; /* data byte count, including hdr */
  320. int cmsg_level; /* originating protocol */
  321. int cmsg_type; /* protocol-specific type */
  322. /* followed by u_char  cmsg_data[]; */
  323. };
  324. /* given pointer to struct cmsghdr, return pointer to data */
  325. #define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1))
  326. /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
  327. #define CMSG_NXTHDR(mhdr, cmsg)
  328. (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > 
  329.     (mhdr)->msg_control + (mhdr)->msg_controllen) ? 
  330.     (struct cmsghdr *)NULL : 
  331.     (struct cmsghdr *)((caddr_t)(cmsg) + MEM_ALIGNED((cmsg)->cmsg_len)))
  332. #define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
  333. /* "Socket"-level control message types: */
  334. #define SCM_RIGHTS 0x01 /* access rights (array of int) */
  335. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  336. #pragma align 0 /* turn off alignment requirement */
  337. #endif /* CPU_FAMILY==I960 */
  338. #ifdef __cplusplus
  339. }
  340. #endif
  341. #endif /* __INCsocketh */