socket.h

Go to the documentation of this file.
00001 // © Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
00002 
00003 /*-
00004  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
00005  *      The Regents of the University of California.  All rights reserved.
00006  * © Portions copyright (c) 2007 Symbian Software Ltd. All rights reserved.
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  * 4. Neither the name of the University nor the names of its contributors
00016  *    may be used to endorse or promote products derived from this software
00017  *    without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00020  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00023  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00024  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00025  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00026  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00027  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00028  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00029  * SUCH DAMAGE.
00030  *
00031  *      @(#)socket.h    8.4 (Berkeley) 2/21/94
00032  * $FreeBSD: src/sys/sys/socket.h,v 1.88.2.1 2005/09/27 21:14:10 rwatson Exp $
00033  */
00034 
00035 #ifndef _SYS_SOCKET_H_
00036 #define _SYS_SOCKET_H_
00037 
00038 #include <sys/cdefs.h>
00039 #include <sys/types.h>
00040 #include <sys/_types.h>
00041 #include <sys/_iovec.h>
00042 #define _NO_NAMESPACE_POLLUTION
00043 #include <machine/param.h>
00044 #undef _NO_NAMESPACE_POLLUTION
00045 
00046 /*
00047  * Definitions related to sockets: types, address families, options.
00048  */
00049 
00050 /*
00051  * Data types.
00052  */
00053 #if __BSD_VISIBLE
00054 #ifndef _GID_T_DECLARED
00055 typedef __gid_t         gid_t;
00056 #define _GID_T_DECLARED
00057 #endif
00058 
00059 #ifndef _OFF_T_DECLARED
00060 typedef __off_t         off_t;
00061 #define _OFF_T_DECLARED
00062 #endif
00063 
00064 #ifndef _PID_T_DECLARED
00065 typedef __pid_t         pid_t;
00066 #define _PID_T_DECLARED
00067 #endif
00068 #endif
00069 
00070 #ifndef _SA_FAMILY_T_DECLARED
00071 typedef __sa_family_t   sa_family_t;
00072 #define _SA_FAMILY_T_DECLARED
00073 #endif
00074 
00075 #ifndef _SOCKLEN_T_DECLARED
00076 typedef __socklen_t     socklen_t;
00077 #define _SOCKLEN_T_DECLARED
00078 #endif
00079  
00080 #ifndef _SSIZE_T_DECLARED
00081 typedef __ssize_t       ssize_t;
00082 #define _SSIZE_T_DECLARED
00083 #endif
00084 
00085 #if __BSD_VISIBLE 
00086 #ifndef _UID_T_DECLARED
00087 typedef __uid_t         uid_t;
00088 #define _UID_T_DECLARED
00089 #endif
00090 #endif
00091 
00092 /*
00093  * Types
00094  */
00095 #define SOCK_STREAM     1               /* stream socket */
00096 #define SOCK_DGRAM      2               /* datagram socket */
00097 #ifdef __SYMBIAN32__
00098 #define SOCK_RAW        4               /* raw-protocol interface */
00099 #else
00100 #define SOCK_RAW        3               /* raw-protocol interface */
00101 // __SYMBIAN32__
00102 #endif
00103 #if __BSD_VISIBLE
00104 #define SOCK_RDM        4               /* reliably-delivered message */
00105 #endif
00106 #ifdef __SYMBIAN32__
00107 #define SOCK_SEQPACKET  3               /* sequenced packet stream */
00108 #else
00109 #define SOCK_SEQPACKET  5               /* sequenced packet stream */
00110 // __SYMBIAN32__
00111 #endif
00112 
00113 /*
00114  * Option flags per-socket.
00115  */
00116 #define SO_DEBUG        0x0001          /* turn on debugging info recording KSODebug */
00117 #define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
00118 #ifdef __SYMBIAN32__
00119 #define SO_REUSEADDR    0x406           /* allow local address reuse */
00120 #else
00121 #define SO_REUSEADDR    0x0004          /* allow local address reuse */
00122 // __SYMBIAN32__
00123 #endif
00124 #ifdef __SYMBIAN32__
00125 #define SO_KEEPALIVE    0x305           /* keep connections alive KSoTcpKeepAlive */
00126 #else
00127 #define SO_KEEPALIVE    0x0008          /* keep connections alive */
00128 // __SYMBIAN32__
00129 #endif
00130 #define SO_DONTROUTE    0x0010          /* just use interface addresses */
00131 #ifdef __SYMBIAN32__
00132 #define SO_BROADCAST    -1                      /* permit sending of broadcast msgs */
00133 #else
00134 #define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
00135 // __SYMBIAN32__
00136 #endif
00137 #if __BSD_VISIBLE
00138 #ifdef __SYMBIAN32__
00139 #define SO_USELOOPBACK  -2              /* bypass hardware when possible */
00140 #else
00141 #define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
00142 // __SYMBIAN32__
00143 #endif
00144 #endif
00145 #ifdef __SYMBIAN32__
00146 #define SO_LINGER       -3                      /* linger on close if data present */
00147 #else
00148 #define SO_LINGER       0x0080          /* linger on close if data present */
00149 // __SYMBIAN32__
00150 #endif
00151 #ifdef __SYMBIAN32__
00152 #define SO_OOBINLINE    0x315           /* leave received OOB data in line KSoTcpOobInline */
00153 #else
00154 #define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
00155 // __SYMBIAN32__
00156 #endif
00157 #if __BSD_VISIBLE
00158 #define SO_REUSEPORT    0x0200          /* allow local address & port reuse */
00159 #define SO_TIMESTAMP    0x0400          /* timestamp received dgram traffic */
00160 #define SO_NOSIGPIPE    0x0800          /* no SIGPIPE from EPIPE */
00161 #define SO_ACCEPTFILTER 0x1000          /* there is an accept filter */
00162 #define SO_BINTIME      0x2000          /* timestamp received dgram traffic */
00163 #endif
00164 
00165 /*
00166  * Additional options, not kept in so_options.
00167  */
00168 #ifdef __SYMBIAN32__
00169 #define SO_SNDBUF       3                       /* send buffer size KSOSendBuf */
00170 #else
00171 #define SO_SNDBUF       0x1001          /* send buffer size */
00172 // __SYMBIAN32__
00173 #endif
00174 #ifdef __SYMBIAN32__
00175 #define SO_RCVBUF       2                       /* receive buffer size KSORecvBuf */
00176 #else
00177 #define SO_RCVBUF       0x1002          /* receive buffer size */
00178 // __SYMBIAN32__
00179 #endif
00180 #define SO_SNDLOWAT     0x1003          /* send low-water mark */
00181 #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
00182 #define SO_SNDTIMEO     0x1005          /* send timeout */
00183 #define SO_RCVTIMEO     0x1006          /* receive timeout */
00184 #ifdef __SYMBIAN32__
00185 #define SO_ERROR        9               /* get error status and clear */
00186 #else
00187 #define SO_ERROR        0x1007          /* get error status and clear */
00188 // __SYMBIAN32__
00189 #endif
00190 #define SO_TYPE         0x1008          /* get socket type */
00191 #if __BSD_VISIBLE
00192 #define SO_LABEL        0x1009          /* socket's MAC label */
00193 #define SO_PEERLABEL    0x1010          /* socket's peer's MAC label */
00194 #define SO_LISTENQLIMIT 0x1011          /* socket's backlog limit */
00195 #define SO_LISTENQLEN   0x1012          /* socket's complete queue length */
00196 #define SO_LISTENINCQLEN        0x1013  /* socket's incomplete queue length */
00197 #endif
00198 
00199 /*
00200  * Structure used for manipulating linger option.
00201  */
00202 struct linger {
00203         int     l_onoff;                /* option on/off */
00204         int     l_linger;               /* linger time */
00205 };
00206 
00207 #if __BSD_VISIBLE
00208 struct accept_filter_arg {
00209         char    af_name[16];
00210         char    af_arg[256-16];
00211 };
00212 #endif
00213 
00214 /*
00215  * Level number for (get/set)sockopt() to apply to socket itself.
00216  */
00217 #ifdef __SYMBIAN32__
00218 #define SOL_SOCKET      1                       /* options for socket level KSOLSocket */
00219 #else
00220 #define SOL_SOCKET      0xffff          /* options for socket level */
00221 // __SYMBIAN32__
00222 #endif
00223 /*
00224  * Address families.
00225  */
00226 #define AF_UNSPEC       0               /* unspecified */
00227 #if __BSD_VISIBLE
00228 #ifdef __SYMBIAN32__
00229 #define AF_LOCAL        0x666           /* local to host (pipes, portals) */
00230 #else
00231 #define AF_LOCAL        AF_UNIX         /* local to host (pipes, portals) */
00232 // __SYMBIAN32__
00233 #endif
00234 #endif
00235 #define AF_UNIX         1               /* standardized name for AF_LOCAL */
00236 #ifdef __SYMBIAN32__
00237 #define AF_INET         0x0800          /* internetwork: UDP, TCP, etc. */
00238 #else
00239 #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
00240 // __SYMBIAN32__
00241 #endif
00242 #if __BSD_VISIBLE
00243 #define AF_IMPLINK      3               /* arpanet imp addresses */
00244 #define AF_PUP          4               /* pup protocols: e.g. BSP */
00245 #define AF_CHAOS        5               /* mit CHAOS protocols */
00246 #define AF_NETBIOS      6               /* SMB protocols */
00247 #define AF_ISO          7               /* ISO protocols */
00248 #define AF_OSI          AF_ISO
00249 #define AF_ECMA         8               /* European computer manufacturers */
00250 #define AF_DATAKIT      9               /* datakit protocols */
00251 #define AF_CCITT        10              /* CCITT protocols, X.25 etc */
00252 #define AF_SNA          11              /* IBM SNA */
00253 #define AF_DECnet       12              /* DECnet */
00254 #define AF_DLI          13              /* DEC Direct data link interface */
00255 #define AF_LAT          14              /* LAT */
00256 #define AF_HYLINK       15              /* NSC Hyperchannel */
00257 #define AF_APPLETALK    16              /* Apple Talk */
00258 #define AF_ROUTE        17              /* Internal Routing Protocol */
00259 #define AF_LINK         18              /* Link layer interface */
00260 #define pseudo_AF_XTP   19              /* eXpress Transfer Protocol (no AF) */
00261 #define AF_COIP         20              /* connection-oriented IP, aka ST II */
00262 #define AF_CNT          21              /* Computer Network Technology */
00263 #define pseudo_AF_RTIP  22              /* Help Identify RTIP packets */
00264 #define AF_IPX          23              /* Novell Internet Protocol */
00265 #define AF_SIP          24              /* Simple Internet Protocol */
00266 #define pseudo_AF_PIP   25              /* Help Identify PIP packets */
00267 #define AF_ISDN         26              /* Integrated Services Digital Network*/
00268 #define AF_E164         AF_ISDN         /* CCITT E.164 recommendation */
00269 #define pseudo_AF_KEY   27              /* Internal key-management function */
00270 #endif
00271 #ifdef __SYMBIAN32__
00272 #define AF_INET6        0x0806          /* IPv6 */
00273 #else
00274 #define AF_INET6        28              /* IPv6 */
00275 #endif
00276 #if __BSD_VISIBLE
00277 #define AF_NATM         29              /* native ATM access */
00278 #define AF_ATM          30              /* ATM */
00279 #define pseudo_AF_HDRCMPLT 31           /* Used by BPF to not rewrite headers
00280                                          * in interface output routine
00281                                          */
00282 #define AF_NETGRAPH     32              /* Netgraph sockets */
00283 #define AF_SLOW         33              /* 802.3ad slow protocol */
00284 #define AF_SCLUSTER     34              /* Sitara cluster protocol */
00285 #define AF_ARP          35
00286 #define AF_BLUETOOTH    36              /* Bluetooth sockets */
00287 #define AF_MAX          37
00288 #endif
00289 #ifdef __SYMBIAN32__
00290 #define AF_IRDA         0x0100          /* IrDA */
00291 #define AF_PLP          273             /* Symbian link protocol */
00292 // __SYMBIAN32__
00293 #endif
00294 
00295 #ifndef __SYMBIAN32__
00296 /*
00297  * Structure used by kernel to store most
00298  * addresses.
00299  */
00300 struct sockaddr {
00301         unsigned char   sa_len;         /* total length */
00302         sa_family_t     sa_family;      /* address family */
00303         char            sa_data[14];    /* actually longer; address value */
00304 };
00305 #else 
00306 
00311 struct sockaddr {
00312         u_short sa_family;              /* address family */
00313         u_short sa_port;                /* port number - a common feature of most protocols */
00314         char    sa_data[24];            /* up to 24 bytes of direct address */
00315       unsigned char     sa_len; 
00316 };
00317 //__SYMBIAN32__
00318 #endif
00319 
00320 #if __BSD_VISIBLE
00321 #define SOCK_MAXADDRLEN 255             /* longest possible addresses */
00322 
00323 /*
00324  * Structure used by kernel to pass protocol
00325  * information in raw sockets.
00326  */
00327 struct sockproto {
00328         unsigned short  sp_family;              /* address family */
00329         unsigned short  sp_protocol;            /* protocol */
00330 };
00331 #endif
00332 
00333 /*
00334  * RFC 2553: protocol-independent placeholder for socket addresses
00335  */
00336 #define _SS_MAXSIZE     128U
00337 #define _SS_ALIGNSIZE   (sizeof(__int64_t))
00338 #define _SS_PAD1SIZE    (_SS_ALIGNSIZE - sizeof(unsigned char) - \
00339                             sizeof(sa_family_t))
00340 #define _SS_PAD2SIZE    (_SS_MAXSIZE - sizeof(unsigned char) - \
00341                             sizeof(sa_family_t) - _SS_PAD1SIZE - _SS_ALIGNSIZE)
00342 
00343 struct sockaddr_storage {
00344         unsigned char   ss_len;         /* address length */
00345         sa_family_t     ss_family;      /* address family */
00346         char            __ss_pad1[_SS_PAD1SIZE];
00347         __int64_t       __ss_align;     /* force desired struct alignment */
00348         char            __ss_pad2[_SS_PAD2SIZE];
00349 };
00350 
00351 #if __BSD_VISIBLE
00352 /*
00353  * Protocol families, same as address families for now.
00354  */
00355 #define PF_UNSPEC       AF_UNSPEC
00356 #define PF_LOCAL        AF_LOCAL
00357 #define PF_UNIX         PF_LOCAL        /* backward compatibility */
00358 #define PF_INET         AF_INET
00359 #define PF_IMPLINK      AF_IMPLINK
00360 #define PF_PUP          AF_PUP
00361 #define PF_CHAOS        AF_CHAOS
00362 #define PF_NETBIOS      AF_NETBIOS
00363 #define PF_ISO          AF_ISO
00364 #define PF_OSI          AF_ISO
00365 #define PF_ECMA         AF_ECMA
00366 #define PF_DATAKIT      AF_DATAKIT
00367 #define PF_CCITT        AF_CCITT
00368 #define PF_SNA          AF_SNA
00369 #define PF_DECnet       AF_DECnet
00370 #define PF_DLI          AF_DLI
00371 #define PF_LAT          AF_LAT
00372 #define PF_HYLINK       AF_HYLINK
00373 #define PF_APPLETALK    AF_APPLETALK
00374 #define PF_ROUTE        AF_ROUTE
00375 #define PF_LINK         AF_LINK
00376 #define PF_XTP          pseudo_AF_XTP   /* really just proto family, no AF */
00377 #define PF_COIP         AF_COIP
00378 #define PF_CNT          AF_CNT
00379 #define PF_SIP          AF_SIP
00380 #define PF_IPX          AF_IPX
00381 #define PF_RTIP         pseudo_AF_RTIP  /* same format as AF_INET */
00382 #define PF_PIP          pseudo_AF_PIP
00383 #define PF_ISDN         AF_ISDN
00384 #define PF_KEY          pseudo_AF_KEY
00385 #define PF_INET6        AF_INET6
00386 #define PF_NATM         AF_NATM
00387 #define PF_ATM          AF_ATM
00388 #define PF_NETGRAPH     AF_NETGRAPH
00389 #define PF_SLOW         AF_SLOW
00390 #define PF_SCLUSTER     AF_SCLUSTER
00391 #define PF_ARP          AF_ARP
00392 #define PF_BLUETOOTH    AF_BLUETOOTH
00393 
00394 #define PF_MAX          AF_MAX
00395 
00396 #ifdef __SYMBIAN32__
00397 #define PF_IRDA         AF_IRDA
00398 #define PF_PLP          AF_PLP
00399 // __SYMBIAN32__
00400 #endif
00401 /*
00402  * Definitions for network related sysctl, CTL_NET.
00403  *
00404  * Second level is protocol family.
00405  * Third level is protocol number.
00406  *
00407  * Further levels are defined by the individual families below.
00408  */
00409 #define NET_MAXID       AF_MAX
00410 
00411 #define CTL_NET_NAMES { \
00412         { 0, 0 }, \
00413         { "unix", CTLTYPE_NODE }, \
00414         { "inet", CTLTYPE_NODE }, \
00415         { "implink", CTLTYPE_NODE }, \
00416         { "pup", CTLTYPE_NODE }, \
00417         { "chaos", CTLTYPE_NODE }, \
00418         { "xerox_ns", CTLTYPE_NODE }, \
00419         { "iso", CTLTYPE_NODE }, \
00420         { "emca", CTLTYPE_NODE }, \
00421         { "datakit", CTLTYPE_NODE }, \
00422         { "ccitt", CTLTYPE_NODE }, \
00423         { "ibm_sna", CTLTYPE_NODE }, \
00424         { "decnet", CTLTYPE_NODE }, \
00425         { "dec_dli", CTLTYPE_NODE }, \
00426         { "lat", CTLTYPE_NODE }, \
00427         { "hylink", CTLTYPE_NODE }, \
00428         { "appletalk", CTLTYPE_NODE }, \
00429         { "route", CTLTYPE_NODE }, \
00430         { "link_layer", CTLTYPE_NODE }, \
00431         { "xtp", CTLTYPE_NODE }, \
00432         { "coip", CTLTYPE_NODE }, \
00433         { "cnt", CTLTYPE_NODE }, \
00434         { "rtip", CTLTYPE_NODE }, \
00435         { "ipx", CTLTYPE_NODE }, \
00436         { "sip", CTLTYPE_NODE }, \
00437         { "pip", CTLTYPE_NODE }, \
00438         { "isdn", CTLTYPE_NODE }, \
00439         { "key", CTLTYPE_NODE }, \
00440         { "inet6", CTLTYPE_NODE }, \
00441         { "natm", CTLTYPE_NODE }, \
00442         { "atm", CTLTYPE_NODE }, \
00443         { "hdrcomplete", CTLTYPE_NODE }, \
00444         { "netgraph", CTLTYPE_NODE }, \
00445         { "snp", CTLTYPE_NODE }, \
00446         { "scp", CTLTYPE_NODE }, \
00447 }
00448 
00449 /*
00450  * PF_ROUTE - Routing table
00451  *
00452  * Three additional levels are defined:
00453  *      Fourth: address family, 0 is wildcard
00454  *      Fifth: type of info, defined below
00455  *      Sixth: flag(s) to mask with for NET_RT_FLAGS
00456  */
00457 #define NET_RT_DUMP     1               /* dump; may limit to a.f. */
00458 #define NET_RT_FLAGS    2               /* by flags, e.g. RESOLVING */
00459 #define NET_RT_IFLIST   3               /* survey interface list */
00460 #define NET_RT_IFMALIST 4               /* return multicast address list */
00461 #define NET_RT_MAXID    5
00462 
00463 #define CTL_NET_RT_NAMES { \
00464         { 0, 0 }, \
00465         { "dump", CTLTYPE_STRUCT }, \
00466         { "flags", CTLTYPE_STRUCT }, \
00467         { "iflist", CTLTYPE_STRUCT }, \
00468         { "ifmalist", CTLTYPE_STRUCT }, \
00469 }
00470 #endif /* __BSD_VISIBLE */
00471 
00472 /*
00473  * Maximum queue length specifiable by listen.
00474  */
00475 #ifdef __SYMBIAN32__
00476 #define SOMAXCONN       5
00477 #else
00478 #define SOMAXCONN       128
00479 // __SYMBIAN32__
00480 #endif
00481 
00482 /*
00483  * Message header for recvmsg and sendmsg calls.
00484  * Used value-result for recvmsg, value only for sendmsg.
00485  */
00486 struct msghdr {
00487         void            *msg_name;              /* optional address */
00488         socklen_t        msg_namelen;           /* size of address */
00489         struct iovec    *msg_iov;               /* scatter/gather array */
00490         int              msg_iovlen;            /* # elements in msg_iov */
00491         void            *msg_control;           /* ancillary data, see below */
00492         socklen_t        msg_controllen;        /* ancillary data buffer len */
00493         int              msg_flags;             /* flags on received message */
00494 };
00495 
00496 #define MSG_OOB         0x1             /* process out-of-band data */
00497 #define MSG_PEEK        0x2             /* peek at incoming message */
00498 #define MSG_DONTROUTE   0x4             /* send without using routing tables */
00499 #define MSG_EOR         0x8             /* data completes record */
00500 #define MSG_TRUNC       0x10            /* data discarded before delivery */
00501 #define MSG_CTRUNC      0x20            /* control data lost before delivery */
00502 #define MSG_WAITALL     0x40            /* wait for full request or error */
00503 #if __BSD_VISIBLE
00504 #define MSG_DONTWAIT    0x80            /* this message should be nonblocking */
00505 #define MSG_EOF         0x100           /* data completes connection */
00506 #define MSG_NBIO        0x4000          /* FIONBIO mode, used by fifofs */
00507 #define MSG_COMPAT      0x8000          /* used in sendit() */
00508 #endif
00509 #ifdef _KERNEL
00510 #define MSG_SOCALLBCK   0x10000         /* for use by socket callbacks - soreceive (TCP) */
00511 #endif
00512 #if __BSD_VISIBLE
00513 #define MSG_NOSIGNAL    0x20000         /* do not generate SIGPIPE on EOF */
00514 #endif
00515 
00516 /*
00517  * Header for ancillary data objects in msg_control buffer.
00518  * Used for additional information with/about a datagram
00519  * not expressible by flags.  The format is a sequence
00520  * of message elements headed by cmsghdr structures.
00521  */
00522 struct cmsghdr {
00523         socklen_t       cmsg_len;               /* data byte count, including hdr */
00524         int             cmsg_level;             /* originating protocol */
00525         int             cmsg_type;              /* protocol-specific type */
00526 /* followed by  u_char  cmsg_data[]; */
00527 };
00528 
00529 #if __BSD_VISIBLE
00530 /*
00531  * While we may have more groups than this, the cmsgcred struct must
00532  * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
00533  * this.
00534 */
00535 #define CMGROUP_MAX 16
00536 
00537 /*
00538  * Credentials structure, used to verify the identity of a peer
00539  * process that has sent us a message. This is allocated by the
00540  * peer process but filled in by the kernel. This prevents the
00541  * peer from lying about its identity. (Note that cmcred_groups[0]
00542  * is the effective GID.)
00543  */
00544 struct cmsgcred {
00545         pid_t   cmcred_pid;             /* PID of sending process */
00546         uid_t   cmcred_uid;             /* real UID of sending process */
00547         uid_t   cmcred_euid;            /* effective UID of sending process */
00548         gid_t   cmcred_gid;             /* real GID of sending process */
00549         short   cmcred_ngroups;         /* number or groups */
00550         gid_t   cmcred_groups[CMGROUP_MAX];     /* groups */
00551 };
00552 
00553 /*
00554  * Socket credentials.
00555  */
00556 struct sockcred {
00557         uid_t   sc_uid;                 /* real user id */
00558         uid_t   sc_euid;                /* effective user id */
00559         gid_t   sc_gid;                 /* real group id */
00560         gid_t   sc_egid;                /* effective group id */
00561         int     sc_ngroups;             /* number of supplemental groups */
00562         gid_t   sc_groups[1];           /* variable length */
00563 };
00564 
00565 /*
00566  * Compute size of a sockcred structure with groups.
00567  */
00568 #define SOCKCREDSIZE(ngrps) \
00569         (sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
00570 
00571 #endif /* __BSD_VISIBLE */
00572 
00573 /* given pointer to struct cmsghdr, return pointer to data */
00574 #define CMSG_DATA(cmsg)         ((unsigned char *)(cmsg) + \
00575                                  _ALIGN(sizeof(struct cmsghdr)))
00576 
00577 /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
00578 #define CMSG_NXTHDR(mhdr, cmsg) \
00579         (((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \
00580           _ALIGN(sizeof(struct cmsghdr)) > \
00581             (char *)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
00582             (struct cmsghdr *)0 : \
00583             (struct cmsghdr *)((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len)))
00584 
00585 /*
00586  * RFC 2292 requires to check msg_controllen, in case that the kernel returns
00587  * an empty list for some reasons.
00588  */
00589 #define CMSG_FIRSTHDR(mhdr) \
00590         ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
00591          (struct cmsghdr *)(mhdr)->msg_control : \
00592          (struct cmsghdr *)NULL)
00593 
00594 #if __BSD_VISIBLE
00595 /* RFC 2292 additions */
00596 #define CMSG_SPACE(l)           (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l))
00597 #define CMSG_LEN(l)             (_ALIGN(sizeof(struct cmsghdr)) + (l))
00598 #endif
00599 
00600 #ifdef _KERNEL
00601 #define CMSG_ALIGN(n)   _ALIGN(n)
00602 #endif
00603 
00604 /* "Socket"-level control message types: */
00605 #define SCM_RIGHTS      0x01            /* access rights (array of int) */
00606 #if __BSD_VISIBLE
00607 #define SCM_TIMESTAMP   0x02            /* timestamp (struct timeval) */
00608 #define SCM_CREDS       0x03            /* process creds (struct cmsgcred) */
00609 #define SCM_BINTIME     0x04            /* timestamp (struct bintime) */
00610 #endif
00611 
00612 #if __BSD_VISIBLE
00613 /*
00614  * 4.3 compat sockaddr, move to compat file later
00615  */
00616 struct osockaddr {
00617         unsigned short sa_family;       /* address family */
00618         char    sa_data[14];            /* up to 14 bytes of direct address */
00619 };
00620 
00621 /*
00622  * 4.3-compat message header (move to compat file later).
00623  */
00624 struct omsghdr {
00625         char    *msg_name;              /* optional address */
00626         int     msg_namelen;            /* size of address */
00627         struct  iovec *msg_iov;         /* scatter/gather array */
00628         int     msg_iovlen;             /* # elements in msg_iov */
00629         char    *msg_accrights;         /* access rights sent/received */
00630         int     msg_accrightslen;
00631 };
00632 #endif
00633 
00634 /*
00635  * howto arguments for shutdown(2), specified by Posix.1g.
00636  */
00637 #define SHUT_RD         0               /* shut down the reading side */
00638 #define SHUT_WR         1               /* shut down the writing side */
00639 #define SHUT_RDWR       2               /* shut down both sides */
00640 
00641 #if __BSD_VISIBLE
00642 /*
00643  * sendfile(2) header/trailer struct
00644  */
00645 struct sf_hdtr {
00646         struct iovec *headers;  /* pointer to an array of header struct iovec's */
00647         int hdr_cnt;            /* number of header iovec's */
00648         struct iovec *trailers; /* pointer to an array of trailer struct iovec's */
00649         int trl_cnt;            /* number of trailer iovec's */
00650 };
00651 
00652 /*
00653  * Sendfile-specific flag(s)
00654  */
00655 #define        SF_NODISKIO     0x00000001
00656 #endif
00657 
00658 #ifndef _KERNEL
00659 
00660 #include <sys/cdefs.h>
00661 
00662 __BEGIN_DECLS
00663 IMPORT_C int    accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
00664 IMPORT_C int    bind(int, const struct sockaddr *, socklen_t);
00665 IMPORT_C int    connect(int, const struct sockaddr *, socklen_t);
00666 IMPORT_C int    getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
00667 IMPORT_C int    getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
00668 IMPORT_C int    getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
00669 IMPORT_C int    listen(int, int);
00670 IMPORT_C ssize_t        recv(int, void *, size_t, int);
00671 IMPORT_C ssize_t        recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict);
00672 IMPORT_C ssize_t        recvmsg(int, struct msghdr *, int);
00673 IMPORT_C ssize_t        send(int, const void *, size_t, int);
00674 IMPORT_C ssize_t        sendto(int, const void *,
00675             size_t, int, const struct sockaddr *, socklen_t);
00676 IMPORT_C ssize_t        sendmsg(int, const struct msghdr *, int);
00677 IMPORT_C int    setsockopt(int, int, int, const void *, socklen_t);
00678 IMPORT_C int    shutdown(int, int);
00679 IMPORT_C int    sockatmark(int);
00680 IMPORT_C int    socket(int, int, int);
00681 __END_DECLS
00682 
00683 #endif /* !_KERNEL */
00684 
00685 #endif /* !_SYS_SOCKET_H_ */

Copyright © Nokia Corporation 2001-2008
Back to top