Update.
[glibc.git] / sysdeps / unix / sysv / linux / socketbits.h
blob101afc268c75b71f6ec10c8b9bdbffec497f3f7b
1 /* System-specific socket constants and types. Linux version.
2 Copyright (C) 1991, 92, 94, 95, 96, 97 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #ifndef _SOCKETBITS_H
22 #define _SOCKETBITS_H 1
23 #include <features.h>
25 #define __need_size_t
26 #define __need_NULL
27 #include <stddef.h>
30 __BEGIN_DECLS
32 /* Types of sockets. */
33 enum __socket_type
35 SOCK_STREAM = 1, /* Sequenced, reliable, connection-based
36 byte streams. */
37 #define SOCK_STREAM SOCK_STREAM
38 SOCK_DGRAM = 2, /* Connectionless, unreliable datagrams
39 of fixed maximum length. */
40 #define SOCK_DGRAM SOCK_DGRAM
41 SOCK_RAW = 3, /* Raw protocol interface. */
42 #define SOCK_RAW SOCK_RAW
43 SOCK_RDM = 4, /* Reliably-delivered messages. */
44 #define SOCK_RDM SOCK_RDM
45 SOCK_SEQPACKET = 5, /* Sequenced, reliable, connection-based,
46 datagrams of fixed maximum length. */
47 #define SOCK_SEQPACKET SOCK_SEQPACKET
48 SOCK_PACKET = 10 /* Linux specific way of getting packets
49 at the dev level. For writing rarp and
50 other similar things on the user level. */
51 #define SOCK_PACKET SOCK_PACKET
54 /* Protocol families. */
55 #define PF_UNSPEC 0 /* Unspecified. */
56 #define PF_LOCAL 1 /* Local to host (pipes and file-domain). */
57 #define PF_UNIX PF_LOCAL /* Old BSD name for PF_LOCAL. */
58 #define PF_FILE PF_LOCAL /* POSIX name for PF_LOCAL. */
59 #define PF_INET 2 /* IP protocol family. */
60 #define PF_AX25 3 /* Amateur Radio AX.25. */
61 #define PF_IPX 4 /* Novell Internet Protocol. */
62 #define PF_APPLETALK 5 /* Don't use this. */
63 #define PF_NETROM 6 /* Amateur radio NetROM. */
64 #define PF_BRIDGE 7 /* Multiprotocol bridge. */
65 #define PF_AAL5 8 /* Reserved for Werner's ATM. */
66 #define PF_X25 9 /* Reserved for X.25 project. */
67 #define PF_INET6 10 /* IP version 6. */
68 #define PF_MAX 12 /* For now.. */
70 /* Address families. */
71 #define AF_UNSPEC PF_UNSPEC
72 #define AF_LOCAL PF_LOCAL
73 #define AF_UNIX PF_UNIX
74 #define AF_FILE PF_FILE
75 #define AF_INET PF_INET
76 #define AF_AX25 PF_AX25
77 #define AF_IPX PF_IPX
78 #define AF_APPLETALK PF_APPLETALK
79 #define AF_NETROM PF_NETROM
80 #define AF_BRIDGE PF_BRIDGE
81 #define AF_AAL5 PF_AAL5
82 #define AF_X25 PF_X25
83 #define AF_INET6 PF_INET6
84 #define AF_MAX PF_MAX
86 /* Socket level values. Others are defined in the appropriate headers.
88 XXX These definitions also should go into the appropriate headers as
89 far as they are available. */
90 #define SOL_IPV6 41
91 #define SOL_ICMPV6 58
92 #define SOL_RAW 255
93 #define SOL_AX25 257
94 #define SOL_ATALK 258
95 #define SOL_NETROM 259
96 #define SOL_ROSE 260
97 #define SOL_DECNET 261
98 #define SOL_X25 262
100 /* Maximum queue length specifiable by listen. */
101 #define SOMAXCONN 128
103 /* Get the definition of the macro to define the common sockaddr members. */
104 #include <sockaddrcom.h>
106 /* Structure describing a generic socket address. */
107 struct sockaddr
109 __SOCKADDR_COMMON (sa_); /* Common data: address family and length. */
110 char sa_data[14]; /* Address data. */
114 /* Bits in the FLAGS argument to `send', `recv', et al. */
115 enum
117 MSG_OOB = 0x01, /* Process out-of-band data. */
118 MSG_PEEK = 0x02, /* Peek at incoming messages. */
119 MSG_DONTROUTE = 0x04, /* Don't use local routing. */
120 MSG_CTRUNC = 0x08, /* Control data lost before delivery. */
121 MSG_PROXY = 0x10 /* Supply or ask second address. */
125 /* Structure describing messages sent by
126 `sendmsg' and received by `recvmsg'. */
127 struct msghdr
129 __ptr_t msg_name; /* Address to send to/receive from. */
130 int msg_namelen; /* Length of address data. */
131 /* XXX Should be type `size_t' according to POSIX.1g. */
133 struct iovec *msg_iov; /* Vector of data to send/receive into. */
134 size_t msg_iovlen; /* Number of elements in the vector. */
136 __ptr_t msg_control; /* Ancillary data (eg BSD filedesc passing). */
137 size_t msg_controllen; /* Ancillary data buffer length. */
138 int msg_flags; /* Flags on received message. */
141 /* Structure used for storage of ancillary data object information. */
142 struct cmsghdr
144 size_t cmsg_len; /* Length of data in cmsg_data plus length
145 of cmsghdr structure. */
146 int cmsg_level; /* Originating protocol. */
147 int cmsg_type; /* Protocol specific type. */
148 #if !defined __STRICT_ANSI__ && defined __GNUC__ && __GNUC__ >= 2
149 unsigned char __cmsg_data[0]; /* Ancillary data. */
150 #endif
153 /* Ancillary data object manipulation macros. */
154 #if !defined __STRICT_ANSI__ && defined __GNUC__ && __GNUC__ >= 2
155 # define CMSG_DATA(cmsg) ((cmsg)->__cmsg_data)
156 #else
157 # define CMSG_DATA(cmsg) ((unsigned char *) ((struct cmsghdr *) (cmsg) + 1))
158 #endif
159 #define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr (mhdr, cmsg)
160 #define CMSG_FIRSTHDR(mhdr) \
161 ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) \
162 ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) NULL)
165 #ifndef _EXTERN_INLINE
166 # define _EXTERN_INLINE extern __inline
167 #endif
168 extern struct cmsghdr *__cmsg_nxthdr __P ((struct msghdr *__mhdr,
169 struct cmsghdr *__cmsg));
170 _EXTERN_INLINE struct cmsghdr *
171 __cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg)
173 unsigned char *__p;
175 if ((size_t) __cmsg->cmsg_len < sizeof (struct cmsghdr))
176 /* The kernel header does this so there may be a reason. */
177 return NULL;
179 __p = (((unsigned char *) __cmsg)
180 + ((__cmsg->cmsg_len + sizeof (long int) - 1) & ~sizeof (long int)));
181 if (__p >= (unsigned char *) __mhdr->msg_control + __mhdr->msg_controllen)
182 /* No more entries. */
183 return NULL;
184 return (struct cmsghdr *) __p;
188 /* Get socket manipulation related informations from kernel headers. */
189 #include <asm/socket.h>
192 /* Structure used to manipulate the SO_LINGER option. */
193 struct linger
195 int l_onoff; /* Nonzero to linger on close. */
196 int l_linger; /* Time to linger. */
199 __END_DECLS
201 #endif /* socketbits.h */