Back to index

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