Back to index

glibc  2.9
socket.h
Go to the documentation of this file.
00001 /* System-specific socket constants and types.  Linux/SPARC version.
00002    Copyright (C) 1991, 1992, 1994-2001, 2004, 2006, 2007, 2008
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef __BITS_SOCKET_H
00022 #define __BITS_SOCKET_H
00023 
00024 #ifndef _SYS_SOCKET_H
00025 # error "Never include <bits/socket.h> directly; use <sys/socket.h> instead."
00026 #endif
00027 
00028 #define       __need_size_t
00029 #include <stddef.h>
00030 
00031 #include <sys/types.h>
00032 
00033 /* Type for length arguments in socket calls.  */
00034 #ifndef __socklen_t_defined
00035 typedef __socklen_t socklen_t;
00036 # define __socklen_t_defined
00037 #endif
00038 
00039 /* Types of sockets.  */
00040 enum __socket_type
00041 {
00042   SOCK_STREAM = 1,          /* Sequenced, reliable, connection-based
00043                                byte streams.  */
00044 #define SOCK_STREAM SOCK_STREAM
00045   SOCK_DGRAM = 2,           /* Connectionless, unreliable datagrams
00046                                of fixed maximum length.  */
00047 #define SOCK_DGRAM SOCK_DGRAM
00048   SOCK_RAW = 3,                    /* Raw protocol interface.  */
00049 #define SOCK_RAW SOCK_RAW
00050   SOCK_RDM = 4,                    /* Reliably-delivered messages.  */
00051 #define SOCK_RDM SOCK_RDM
00052   SOCK_SEQPACKET = 5,              /* Sequenced, reliable, connection-based,
00053                                datagrams of fixed maximum length.  */
00054 #define SOCK_SEQPACKET SOCK_SEQPACKET
00055   SOCK_DCCP = 6,            /* Datagram Congestion Control Protocol.  */
00056 #define SOCK_DCCP SOCK_DCCP
00057   SOCK_PACKET = 10,         /* Linux specific way of getting packets
00058                                at the dev level.  For writing rarp and
00059                                other similar things on the user level. */
00060 #define SOCK_PACKET SOCK_PACKET
00061 
00062   /* Flags to be ORed into the type parameter of socket and socketpair.  */
00063 
00064   SOCK_CLOEXEC = 0x400000,  /* Atomically set close-on-exec flag for the
00065                                new descriptor(s).  */
00066 #define SOCK_CLOEXEC SOCK_CLOEXEC
00067   SOCK_NONBLOCK = 0x4000    /* Atomically mark descriptor(s) as
00068                                non-blocking.  */
00069 #define SOCK_NONBLOCK SOCK_NONBLOCK
00070 };
00071 
00072 /* Protocol families.  */
00073 #define       PF_UNSPEC     0      /* Unspecified.  */
00074 #define       PF_LOCAL      1      /* Local to host (pipes and file-domain).  */
00075 #define       PF_UNIX              PF_LOCAL /* POSIX name for PF_LOCAL.  */
00076 #define       PF_FILE              PF_LOCAL /* Another non-standard name for PF_LOCAL.  */
00077 #define       PF_INET              2      /* IP protocol family.  */
00078 #define       PF_AX25              3      /* Amateur Radio AX.25.  */
00079 #define       PF_IPX        4      /* Novell Internet Protocol.  */
00080 #define       PF_APPLETALK  5      /* Appletalk DDP.  */
00081 #define       PF_NETROM     6      /* Amateur radio NetROM.  */
00082 #define       PF_BRIDGE     7      /* Multiprotocol bridge.  */
00083 #define       PF_ATMPVC     8      /* ATM PVCs.  */
00084 #define       PF_X25        9      /* Reserved for X.25 project.  */
00085 #define       PF_INET6      10     /* IP version 6.  */
00086 #define       PF_ROSE              11     /* Amateur Radio X.25 PLP.  */
00087 #define       PF_DECnet     12     /* Reserved for DECnet project.  */
00088 #define       PF_NETBEUI    13     /* Reserved for 802.2LLC project.  */
00089 #define       PF_SECURITY   14     /* Security callback pseudo AF.  */
00090 #define       PF_KEY        15     /* PF_KEY key management API.  */
00091 #define       PF_NETLINK    16
00092 #define       PF_ROUTE      PF_NETLINK /* Alias to emulate 4.4BSD.  */
00093 #define       PF_PACKET     17     /* Packet family.  */
00094 #define       PF_ASH        18     /* Ash.  */
00095 #define       PF_ECONET     19     /* Acorn Econet.  */
00096 #define       PF_ATMSVC     20     /* ATM SVCs.  */
00097 #define       PF_SNA        22     /* Linux SNA Project */
00098 #define       PF_IRDA              23     /* IRDA sockets.  */
00099 #define       PF_PPPOX      24     /* PPPoX sockets.  */
00100 #define       PF_WANPIPE    25     /* Wanpipe API sockets.  */
00101 #define       PF_BLUETOOTH  31     /* Bluetooth sockets.  */
00102 #define       PF_IUCV              32     /* IUCV sockets.  */
00103 #define PF_RXRPC     33     /* RxRPC sockets.  */
00104 #define PF_ISDN             34     /* mISDN sockets.  */
00105 #define       PF_MAX        35     /* For now..  */
00106 
00107 /* Address families.  */
00108 #define       AF_UNSPEC     PF_UNSPEC
00109 #define       AF_LOCAL      PF_LOCAL
00110 #define       AF_UNIX              PF_UNIX
00111 #define       AF_FILE              PF_FILE
00112 #define       AF_INET              PF_INET
00113 #define       AF_AX25              PF_AX25
00114 #define       AF_IPX        PF_IPX
00115 #define       AF_APPLETALK  PF_APPLETALK
00116 #define       AF_NETROM     PF_NETROM
00117 #define       AF_BRIDGE     PF_BRIDGE
00118 #define       AF_ATMPVC     PF_ATMPVC
00119 #define       AF_X25        PF_X25
00120 #define       AF_INET6      PF_INET6
00121 #define       AF_ROSE              PF_ROSE
00122 #define       AF_DECnet     PF_DECnet
00123 #define       AF_NETBEUI    PF_NETBEUI
00124 #define       AF_SECURITY   PF_SECURITY
00125 #define       AF_KEY        PF_KEY
00126 #define       AF_NETLINK    PF_NETLINK
00127 #define       AF_ROUTE      PF_ROUTE
00128 #define       AF_PACKET     PF_PACKET
00129 #define       AF_ASH        PF_ASH
00130 #define       AF_ECONET     PF_ECONET
00131 #define       AF_ATMSVC     PF_ATMSVC
00132 #define       AF_SNA        PF_SNA
00133 #define       AF_IRDA              PF_IRDA
00134 #define       AF_PPPOX      PF_PPPOX
00135 #define       AF_WANPIPE    PF_WANPIPE
00136 #define       AF_BLUETOOTH  PF_BLUETOOTH
00137 #define       AF_IUCV              PF_IUCV
00138 #define AF_RXRPC     PF_RXRPC
00139 #define AF_ISDN             PF_ISDN
00140 #define       AF_MAX        PF_MAX
00141 
00142 /* Socket level values.  Others are defined in the appropriate headers.
00143 
00144    XXX These definitions also should go into the appropriate headers as
00145    far as they are available.  */
00146 #define SOL_RAW             255
00147 #define SOL_DECNET      261
00148 #define SOL_X25         262
00149 #define SOL_PACKET   263
00150 #define SOL_ATM             264    /* ATM layer (cell level).  */
00151 #define SOL_AAL             265    /* ATM Adaption Layer (packet level).  */
00152 #define SOL_IRDA     266
00153 
00154 /* Maximum queue length specifiable by listen.  */
00155 #define SOMAXCONN    128
00156 
00157 /* Get the definition of the macro to define the common sockaddr members.  */
00158 #include <bits/sockaddr.h>
00159 
00160 /* Structure describing a generic socket address.  */
00161 struct sockaddr
00162   {
00163     __SOCKADDR_COMMON (sa_);       /* Common data: address family and length.  */
00164     char sa_data[14];              /* Address data.  */
00165   };
00166 
00167 
00168 /* Structure large enough to hold any socket address (with the historical
00169    exception of AF_UNIX).  We reserve 128 bytes.  */
00170 #define __ss_aligntype      unsigned long int
00171 #define _SS_SIZE     128
00172 #define _SS_PADSIZE  (_SS_SIZE - (2 * sizeof (__ss_aligntype)))
00173 
00174 struct sockaddr_storage
00175   {
00176     __SOCKADDR_COMMON (ss_);       /* Address family, etc.  */
00177     __ss_aligntype __ss_align;     /* Force desired alignment.  */
00178     char __ss_padding[_SS_PADSIZE];
00179   };
00180 
00181 
00182 /* Bits in the FLAGS argument to `send', `recv', et al.  */
00183 enum
00184   {
00185     MSG_OOB          = 0x01,       /* Process out-of-band data.  */
00186 #define MSG_OOB             MSG_OOB
00187     MSG_PEEK         = 0x02,       /* Peek at incoming messages.  */
00188 #define MSG_PEEK     MSG_PEEK
00189     MSG_DONTROUTE    = 0x04,       /* Don't use local routing.  */
00190 #define MSG_DONTROUTE       MSG_DONTROUTE
00191 #ifdef __USE_GNU
00192     /* DECnet uses a different name.  */
00193     MSG_TRYHARD             = MSG_DONTROUTE,
00194 # define MSG_TRYHARD MSG_DONTROUTE
00195 #endif
00196     MSG_CTRUNC              = 0x08,       /* Control data lost before delivery.  */
00197 #define MSG_CTRUNC   MSG_CTRUNC
00198     MSG_PROXY        = 0x10,       /* Supply or ask second address.  */
00199 #define MSG_PROXY    MSG_PROXY
00200     MSG_TRUNC        = 0x20,
00201 #define       MSG_TRUNC     MSG_TRUNC
00202     MSG_DONTWAIT     = 0x40, /* Nonblocking IO.  */
00203 #define       MSG_DONTWAIT  MSG_DONTWAIT
00204     MSG_EOR          = 0x80, /* End of record.  */
00205 #define       MSG_EOR              MSG_EOR
00206     MSG_WAITALL             = 0x100, /* Wait for a full request.  */
00207 #define       MSG_WAITALL   MSG_WAITALL
00208     MSG_FIN          = 0x200,
00209 #define       MSG_FIN              MSG_FIN
00210     MSG_SYN          = 0x400,
00211 #define       MSG_SYN              MSG_SYN
00212     MSG_CONFIRM             = 0x800, /* Confirm path validity.  */
00213 #define       MSG_CONFIRM   MSG_CONFIRM
00214     MSG_RST          = 0x1000,
00215 #define       MSG_RST              MSG_RST
00216     MSG_ERRQUEUE     = 0x2000, /* Fetch message from error queue.  */
00217 #define       MSG_ERRQUEUE  MSG_ERRQUEUE
00218     MSG_NOSIGNAL     = 0x4000, /* Do not generate SIGPIPE.  */
00219 #define       MSG_NOSIGNAL  MSG_NOSIGNAL
00220     MSG_MORE         = 0x8000,  /* Sender will send more.  */
00221 #define       MSG_MORE      MSG_MORE
00222 
00223     MSG_CMSG_CLOEXEC = 0x40000000  /* Set close_on_exit for file
00224                                            descriptor received through
00225                                            SCM_RIGHTS.  */
00226 #define MSG_CMSG_CLOEXEC MSG_CMSG_CLOEXEC
00227   };
00228 
00229 
00230 /* Structure describing messages sent by
00231    `sendmsg' and received by `recvmsg'.  */
00232 struct msghdr
00233   {
00234     void *msg_name;         /* Address to send to/receive from.  */
00235     socklen_t msg_namelen;  /* Length of address data.  */
00236 
00237     struct iovec *msg_iov;  /* Vector of data to send/receive into.  */
00238     size_t msg_iovlen;             /* Number of elements in the vector.  */
00239 
00240     void *msg_control;             /* Ancillary data (eg BSD filedesc passing). */
00241     size_t msg_controllen;  /* Ancillary data buffer length.
00242                                !! The type should be socklen_t but the
00243                                definition of the kernel is incompatible
00244                                with this.  */
00245 
00246     int msg_flags;          /* Flags on received message.  */
00247   };
00248 
00249 /* Structure used for storage of ancillary data object information.  */
00250 struct cmsghdr
00251   {
00252     size_t cmsg_len;        /* Length of data in cmsg_data plus length
00253                                of cmsghdr structure.
00254                                !! The type should be socklen_t but the
00255                                definition of the kernel is incompatible
00256                                with this.  */
00257     int cmsg_level;         /* Originating protocol.  */
00258     int cmsg_type;          /* Protocol specific type.  */
00259 #if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L
00260     __extension__ unsigned char __cmsg_data __flexarr; /* Ancillary data.  */
00261 #endif
00262   };
00263 
00264 /* Ancillary data object manipulation macros.  */
00265 #if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L
00266 # define CMSG_DATA(cmsg) ((cmsg)->__cmsg_data)
00267 #else
00268 # define CMSG_DATA(cmsg) ((unsigned char *) ((struct cmsghdr *) (cmsg) + 1))
00269 #endif
00270 #define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr (mhdr, cmsg)
00271 #define CMSG_FIRSTHDR(mhdr) \
00272   ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr)               \
00273    ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0)
00274 #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) \
00275                       & (size_t) ~(sizeof (size_t) - 1))
00276 #define CMSG_SPACE(len) (CMSG_ALIGN (len) \
00277                       + CMSG_ALIGN (sizeof (struct cmsghdr)))
00278 #define CMSG_LEN(len)   (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
00279 
00280 extern struct cmsghdr *__cmsg_nxthdr (struct msghdr *__mhdr,
00281                                   struct cmsghdr *__cmsg) __THROW;
00282 #ifdef __USE_EXTERN_INLINES
00283 # ifndef _EXTERN_INLINE
00284 #  define _EXTERN_INLINE __extern_inline
00285 # endif
00286 _EXTERN_INLINE struct cmsghdr *
00287 __NTH (__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg))
00288 {
00289   if ((size_t) __cmsg->cmsg_len < sizeof (struct cmsghdr))
00290     /* The kernel header does this so there may be a reason.  */
00291     return 0;
00292 
00293   __cmsg = (struct cmsghdr *) ((unsigned char *) __cmsg
00294                             + CMSG_ALIGN (__cmsg->cmsg_len));
00295   if ((unsigned char *) (__cmsg + 1) > ((unsigned char *) __mhdr->msg_control
00296                                    + __mhdr->msg_controllen)
00297       || ((unsigned char *) __cmsg + CMSG_ALIGN (__cmsg->cmsg_len)
00298          > ((unsigned char *) __mhdr->msg_control + __mhdr->msg_controllen)))
00299     /* No more entries.  */
00300     return 0;
00301   return __cmsg;
00302 }
00303 #endif /* Use `extern inline'.  */
00304 
00305 /* Socket level message types.  This must match the definitions in
00306    <linux/socket.h>.  */
00307 enum
00308   {
00309     SCM_RIGHTS = 0x01              /* Transfer file descriptors.  */
00310 #define SCM_RIGHTS SCM_RIGHTS
00311 #ifdef __USE_BSD
00312     , SCM_CREDENTIALS = 0x02       /* Credentials passing.  */
00313 # define SCM_CREDENTIALS SCM_CREDENTIALS
00314 #endif
00315   };
00316 
00317 #ifdef __USE_GNU
00318 /* User visible structure for SCM_CREDENTIALS message */
00319 struct ucred
00320 {
00321   pid_t pid;                /* PID of sending process.  */
00322   uid_t uid;                /* UID of sending process.  */
00323   gid_t gid;                /* GID of sending process.  */
00324 };
00325 #endif
00326 
00327 /* Ugly workaround for unclean kernel headers.  */
00328 #if !defined __USE_MISC && !defined __USE_GNU
00329 # ifndef FIOGETOWN
00330 #  define __SYS_SOCKET_H_undef_FIOGETOWN
00331 # endif
00332 # ifndef FIOSETOWN
00333 #  define __SYS_SOCKET_H_undef_FIOSETOWN
00334 # endif
00335 # ifndef SIOCATMARK
00336 #  define __SYS_SOCKET_H_undef_SIOCATMARK
00337 # endif
00338 # ifndef SIOCGPGRP
00339 #  define __SYS_SOCKET_H_undef_SIOCGPGRP
00340 # endif
00341 # ifndef SIOCGSTAMP
00342 #  define __SYS_SOCKET_H_undef_SIOCGSTAMP
00343 # endif
00344 # ifndef SIOCGSTAMPNS
00345 #  define __SYS_SOCKET_H_undef_SIOCGSTAMPNS
00346 # endif
00347 # ifndef SIOCSPGRP
00348 #  define __SYS_SOCKET_H_undef_SIOCSPGRP
00349 # endif
00350 #endif
00351 
00352 /* Get socket manipulation related informations from kernel headers.  */
00353 #include <asm/socket.h>
00354 
00355 #if !defined __USE_MISC && !defined __USE_GNU
00356 # ifdef __SYS_SOCKET_H_undef_FIOGETOWN
00357 #  undef __SYS_SOCKET_H_undef_FIOGETOWN
00358 #  undef FIOGETOWN
00359 # endif
00360 # ifdef __SYS_SOCKET_H_undef_FIOSETOWN
00361 #  undef __SYS_SOCKET_H_undef_FIOSETOWN
00362 #  undef FIOSETOWN
00363 # endif
00364 # ifdef __SYS_SOCKET_H_undef_SIOCATMARK
00365 #  undef __SYS_SOCKET_H_undef_SIOCATMARK
00366 #  undef SIOCATMARK
00367 # endif
00368 # ifdef __SYS_SOCKET_H_undef_SIOCGPGRP
00369 #  undef __SYS_SOCKET_H_undef_SIOCGPGRP
00370 #  undef SIOCGPGRP
00371 # endif
00372 # ifdef __SYS_SOCKET_H_undef_SIOCGSTAMP
00373 #  undef __SYS_SOCKET_H_undef_SIOCGSTAMP
00374 #  undef SIOCGSTAMP
00375 # endif
00376 # ifdef __SYS_SOCKET_H_undef_SIOCGSTAMPNS
00377 #  undef __SYS_SOCKET_H_undef_SIOCGSTAMPNS
00378 #  undef SIOCGSTAMPNS
00379 # endif
00380 # ifdef __SYS_SOCKET_H_undef_SIOCSPGRP
00381 #  undef __SYS_SOCKET_H_undef_SIOCSPGRP
00382 #  undef SIOCSPGRP
00383 # endif
00384 #endif
00385 
00386 /* Structure used to manipulate the SO_LINGER option.  */
00387 struct linger
00388   {
00389     int l_onoff;            /* Nonzero to linger on close.  */
00390     int l_linger;           /* Time to linger.  */
00391   };
00392 
00393 #endif /* bits/socket.h */