initial commit
[glibc.git] / sysdeps / unix / bsd / bsd4.4 / kfreebsd / bits / socket.h
1 /* System-specific socket constants and types. FreeBSD version.
2 Copyright (C) 1991-1992,1994-1999,2000-2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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. */
19
20 #ifndef __BITS_SOCKET_H
21 #define __BITS_SOCKET_H 1
22
23 #if !defined _SYS_SOCKET_H && !defined _NETINET_IN_H
24 # error "Never include <bits/socket.h> directly; use <sys/socket.h> instead."
25 #endif
26
27 #define __need_size_t
28 #define __need_NULL
29 #include <stddef.h>
30
31 #include <limits.h> /* XXX Is this allowed? */
32 #include <bits/types.h>
33
34 /* Type for length arguments in socket calls. */
35 #ifndef __socklen_t_defined
36 typedef __socklen_t socklen_t;
37 # define __socklen_t_defined
38 #endif
39
40
41 /* Types of sockets. */
42 enum __socket_type
43 {
44 SOCK_STREAM = 1, /* Sequenced, reliable, connection-based
45 byte streams. */
46 #define SOCK_STREAM SOCK_STREAM
47 SOCK_DGRAM = 2, /* Connectionless, unreliable datagrams
48 of fixed maximum length. */
49 #define SOCK_DGRAM SOCK_DGRAM
50 SOCK_RAW = 3, /* Raw protocol interface. */
51 #define SOCK_RAW SOCK_RAW
52 SOCK_RDM = 4, /* Reliably-delivered messages. */
53 #define SOCK_RDM SOCK_RDM
54 SOCK_SEQPACKET = 5, /* Sequenced, reliable, connection-based,
55 datagrams of fixed maximum length. */
56 #define SOCK_SEQPACKET SOCK_SEQPACKET
57
58 /* Flags to be ORed into the type parameter of socket and socketpair and
59 used for the flags parameter of paccept. */
60
61 SOCK_CLOEXEC = 0x10000000, /* Atomically set close-on-exec flag for the
62 new descriptor(s). */
63 #define SOCK_CLOEXEC SOCK_CLOEXEC
64 SOCK_NONBLOCK = 0x20000000 /* Atomically mark descriptor(s) as
65 non-blocking. */
66 #define SOCK_NONBLOCK SOCK_NONBLOCK
67 };
68
69 /*
70 * Structure used by kernel to pass protocol
71 * information in raw sockets.
72 */
73 struct sockproto {
74 unsigned short sp_family; /* address family */
75 unsigned short sp_protocol; /* protocol */
76 };
77
78 /* Protocol families. */
79 #define PF_UNSPEC 0 /* Unspecified. */
80 #define PF_LOCAL 1 /* Local to host (pipes and file-domain). */
81 #define PF_UNIX PF_LOCAL /* Old BSD name for PF_LOCAL. */
82 #define PF_FILE PF_LOCAL /* POSIX name for PF_LOCAL. */
83 #define PF_INET 2 /* IP protocol family. */
84 #define PF_IMPLINK 3 /* ARPAnet IMP protocol. */
85 #define PF_PUP 4 /* PUP protocols. */
86 #define PF_CHAOS 5 /* MIT Chaos protocols. */
87 #define PF_NETBIOS 6 /* SMB protocols. */
88 #define PF_ISO 7 /* ISO protocols. */
89 #define PF_OSI PF_ISO
90 #define PF_ECMA 8 /* ECMA protocols. */
91 #define PF_DATAKIT 9 /* AT&T Datakit protocols. */
92 #define PF_CCITT 10 /* CCITT protocols (X.25 et al). */
93 #define PF_SNA 11 /* IBM SNA protocol. */
94 #define PF_DECnet 12 /* DECnet protocols. */
95 #define PF_DLI 13 /* Direct data link interface. */
96 #define PF_LAT 14 /* DEC Local Area Transport protocol. */
97 #define PF_HYLINK 15 /* NSC Hyperchannel protocol. */
98 #define PF_APPLETALK 16 /* Don't use this. */
99 #define PF_ROUTE 17 /* Internal Routing Protocol. */
100 #define PF_LINK 18 /* Link layer interface. */
101 #define PF_XTP 19 /* eXpress Transfer Protocol (no AF). */
102 #define PF_COIP 20 /* Connection-oriented IP, aka ST II. */
103 #define PF_CNT 21 /* Computer Network Technology. */
104 #define PF_RTIP 22 /* Help Identify RTIP packets. **/
105 #define PF_IPX 23 /* Novell Internet Protocol. */
106 #define PF_SIP 24 /* Simple Internet Protocol. */
107 #define PF_PIP 25 /* Help Identify PIP packets. */
108 #define PF_ISDN 26 /* Integrated Services Digital Network. */
109 #define PF_KEY 27 /* Internal key-management function. */
110 #define PF_INET6 28 /* IP version 6. */
111 #define PF_NATM 29 /* Native ATM access. */
112 #define PF_ATM 30 /* ATM. */
113 #define PF_HDRCMPLT 31 /* Used by BPF to not rewrite headers in
114 interface output routine. */
115 #define PF_NETGRAPH 32 /* Netgraph sockets. */
116 #define PF_MAX 33
117
118 /* Address families. */
119 #define AF_UNSPEC PF_UNSPEC
120 #define AF_LOCAL PF_LOCAL
121 #define AF_UNIX PF_UNIX
122 #define AF_FILE PF_FILE
123 #define AF_INET PF_INET
124 #define AF_IMPLINK PF_IMPLINK
125 #define AF_PUP PF_PUP
126 #define AF_CHAOS PF_CHAOS
127 #define AF_NETBIOS PF_NETBIOS
128 #define AF_ISO PF_ISO
129 #define AF_OSI PF_OSI
130 #define AF_ECMA PF_ECMA
131 #define AF_DATAKIT PF_DATAKIT
132 #define AF_CCITT PF_CCITT
133 #define AF_SNA PF_SNA
134 #define AF_DECnet PF_DECnet
135 #define AF_DLI PF_DLI
136 #define AF_LAT PF_LAT
137 #define AF_HYLINK PF_HYLINK
138 #define AF_APPLETALK PF_APPLETALK
139 #define AF_ROUTE PF_ROUTE
140 #define AF_LINK PF_LINK
141 #define pseudo_AF_XTP PF_XTP
142 #define AF_COIP PF_COIP
143 #define AF_CNT PF_CNT
144 #define pseudo_AF_RTIP PF_RTIP
145 #define AF_IPX PF_IPX
146 #define AF_SIP PF_SIP
147 #define pseudo_AF_PIP PF_PIP
148 #define AF_ISDN PF_ISDN
149 #define AF_E164 AF_ISDN /* CCITT E.164 recommendation. */
150 #define pseudo_AF_KEY PF_KEY
151 #define AF_INET6 PF_INET6
152 #define AF_NATM PF_NATM
153 #define AF_ATM PF_ATM
154 #define pseudo_AF_HDRCMPLT PF_HDRCMPLT
155 #define AF_NETGRAPH PF_NETGRAPH
156 #define AF_MAX PF_MAX
157
158 /* Maximum queue length specifiable by listen. */
159 #define SOMAXCONN 128 /* 5 on the original 4.4 BSD. */
160
161 /* Get the definition of the macro to define the common sockaddr members. */
162 #include <bits/sockaddr.h>
163
164 /* Structure describing a generic socket address. */
165 struct sockaddr
166 {
167 __SOCKADDR_COMMON (sa_); /* Common data: address family and length. */
168 char sa_data[14]; /* Address data. */
169 };
170
171
172 /* Structure large enough to hold any socket address (with the historical
173 exception of AF_UNIX). */
174 #if ULONG_MAX > 0xffffffff
175 # define __ss_aligntype __uint64_t
176 #else
177 # define __ss_aligntype __uint32_t
178 #endif
179 #define _SS_PADSIZE \
180 (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype))
181
182 struct sockaddr_storage
183 {
184 __SOCKADDR_COMMON (ss_); /* Address family, etc. */
185 char __ss_padding[_SS_PADSIZE];
186 __ss_aligntype __ss_align; /* Force desired alignment. */
187 };
188
189
190 /* Bits in the FLAGS argument to `send', `recv', et al. */
191 enum
192 {
193 MSG_OOB = 0x01, /* Process out-of-band data. */
194 #define MSG_OOB MSG_OOB
195 MSG_PEEK = 0x02, /* Peek at incoming messages. */
196 #define MSG_PEEK MSG_PEEK
197 MSG_DONTROUTE = 0x04, /* Don't use local routing. */
198 #define MSG_DONTROUTE MSG_DONTROUTE
199 MSG_EOR = 0x08, /* Data completes record. */
200 #define MSG_EOR MSG_EOR
201 MSG_TRUNC = 0x10, /* Data discarded before delivery. */
202 #define MSG_TRUNC MSG_TRUNC
203 MSG_CTRUNC = 0x20, /* Control data lost before delivery. */
204 #define MSG_CTRUNC MSG_CTRUNC
205 MSG_WAITALL = 0x40, /* Wait for full request or error. */
206 #define MSG_WAITALL MSG_WAITALL
207 MSG_DONTWAIT = 0x80, /* This message should be nonblocking. */
208 #define MSG_DONTWAIT MSG_DONTWAIT
209 MSG_EOF = 0x100, /* Data completes connection. */
210 #define MSG_EOF MSG_EOF
211 MSG_NOTIFICATION = 0x2000,/* SCTP notification */
212 #define MSG_NOTIFICATION MSG_NOTIFICATION
213 MSG_NBIO = 0x4000,/*FIONBIO mode, used by fifofs */
214 #define MSG_NBIO MSG_NBIO
215 MSG_COMPAT = 0x8000,/* Used in sendit(). */
216 #define MSG_COMPAT MSG_COMPAT
217 MSG_NOSIGNAL = 0x20000 /* do not generate SIGPIPE on EOF */
218 #define MSG_NOSIGNAL MSG_NOSIGNAL
219 };
220
221
222 /* Structure describing messages sent by
223 `sendmsg' and received by `recvmsg'. */
224 struct msghdr
225 {
226 void *msg_name; /* Address to send to/receive from. */
227 socklen_t msg_namelen; /* Length of address data. */
228
229 struct iovec *msg_iov; /* Vector of data to send/receive into. */
230 int msg_iovlen; /* Number of elements in the vector. */
231
232 void *msg_control; /* Ancillary data (eg BSD filedesc passing). */
233 socklen_t msg_controllen; /* Ancillary data buffer length. */
234
235 int msg_flags; /* Flags in received message. */
236 };
237
238 /* Structure used for storage of ancillary data object information. */
239 struct cmsghdr
240 {
241 socklen_t cmsg_len; /* Length of data in cmsg_data plus length
242 of cmsghdr structure. */
243 int cmsg_level; /* Originating protocol. */
244 int cmsg_type; /* Protocol specific type. */
245 #if __glibc_c99_flexarr_available
246 __extension__ unsigned char __cmsg_data __flexarr __attribute__ ((aligned (__alignof__(size_t)))); /* Ancillary data. */
247 #endif
248 };
249
250 #define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr (mhdr, cmsg)
251
252 #define CMSG_FIRSTHDR(mhdr) \
253 ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) \
254 ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) NULL)
255
256 #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) \
257 & (size_t) ~(sizeof (size_t) - 1))
258 #define CMSG_SPACE(len) (CMSG_ALIGN (len) \
259 + CMSG_ALIGN (sizeof (struct cmsghdr)))
260 #define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
261
262 /* Ancillary data object manipulation macros. */
263 #if __glibc_c99_flexarr_available
264 # define CMSG_DATA(cmsg) ((cmsg)->__cmsg_data)
265 #else
266 # define CMSG_DATA(cmsg) ((unsigned char *) (cmsg) + CMSG_ALIGN(sizeof (struct cmsghdr)))
267 #endif
268
269 extern struct cmsghdr *__cmsg_nxthdr (struct msghdr *__mhdr,
270 struct cmsghdr *__cmsg) __THROW;
271 #ifdef __USE_EXTERN_INLINES
272 # ifndef _EXTERN_INLINE
273 # define _EXTERN_INLINE __extern_inline
274 # endif
275 _EXTERN_INLINE struct cmsghdr *
276 __NTH (__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg))
277 {
278 if ((size_t) __cmsg->cmsg_len < sizeof (struct cmsghdr))
279 /* The kernel header does this so there may be a reason. */
280 return 0;
281
282 __cmsg = (struct cmsghdr *) ((unsigned char *) __cmsg
283 + CMSG_ALIGN (__cmsg->cmsg_len));
284 if ((unsigned char *) (__cmsg + 1) > ((unsigned char *) __mhdr->msg_control
285 + __mhdr->msg_controllen)
286 || ((unsigned char *) __cmsg + CMSG_ALIGN (__cmsg->cmsg_len)
287 > ((unsigned char *) __mhdr->msg_control + __mhdr->msg_controllen)))
288 /* No more entries. */
289 return 0;
290 return __cmsg;
291 }
292 #endif /* Use `extern inline'. */
293
294 /* Socket level message types. */
295 enum
296 {
297 SCM_RIGHTS = 0x01, /* Access rights (array of int). */
298 #define SCM_RIGHTS SCM_RIGHTS
299 SCM_TIMESTAMP = 0x02, /* Timestamp (struct timeval). */
300 #define SCM_TIMESTAMP SCM_TIMESTAMP
301 SCM_CREDS = 0x03 /* Process creds (struct cmsgcred). */
302 #define SCM_CREDS SCM_CREDS
303 };
304
305 /* Unfortunately, BSD practice dictates this structure be of fixed size.
306 If there are more than CMGROUP_MAX groups, the list is truncated.
307 (On GNU systems, the `cmcred_euid' field is just the first in the
308 list of effective UIDs.) */
309 #define CMGROUP_MAX 16
310
311 /* Structure delivered by SCM_CREDS. This describes the identity of the
312 sender of the data simultaneously received on the socket. By BSD
313 convention, this is included only when a sender on a AF_LOCAL socket
314 sends cmsg data of this type and size; the sender's structure is
315 ignored, and the system fills in the various IDs of the sender process. */
316 struct cmsgcred
317 {
318 __pid_t cmcred_pid;
319 __uid_t cmcred_uid;
320 __uid_t cmcred_euid;
321 __gid_t cmcred_gid;
322 short cmcred_ngroups;
323 __gid_t cmcred_groups[CMGROUP_MAX];
324 };
325
326 /* Protocol number used to manipulate socket-level options
327 with `getsockopt' and `setsockopt'. */
328 #define SOL_SOCKET 0xffff
329
330 /* Socket-level options for `getsockopt' and `setsockopt'. */
331 enum
332 {
333 SO_DEBUG = 0x0001, /* Record debugging information. */
334 #define SO_DEBUG SO_DEBUG
335 SO_ACCEPTCONN = 0x0002, /* Accept connections on socket. */
336 #define SO_ACCEPTCONN SO_ACCEPTCONN
337 SO_REUSEADDR = 0x0004, /* Allow reuse of local addresses. */
338 #define SO_REUSEADDR SO_REUSEADDR
339 SO_KEEPALIVE = 0x0008, /* Keep connections alive and send
340 SIGPIPE when they die. */
341 #define SO_KEEPALIVE SO_KEEPALIVE
342 SO_DONTROUTE = 0x0010, /* Don't do local routing. */
343 #define SO_DONTROUTE SO_DONTROUTE
344 SO_BROADCAST = 0x0020, /* Allow transmission of
345 broadcast messages. */
346 #define SO_BROADCAST SO_BROADCAST
347 SO_USELOOPBACK = 0x0040, /* Use the software loopback to avoid
348 hardware use when possible. */
349 #define SO_USELOOPBACK SO_USELOOPBACK
350 SO_LINGER = 0x0080, /* Block on close of a reliable
351 socket to transmit pending data. */
352 #define SO_LINGER SO_LINGER
353 SO_OOBINLINE = 0x0100, /* Receive out-of-band data in-band. */
354 #define SO_OOBINLINE SO_OOBINLINE
355 SO_REUSEPORT = 0x0200, /* Allow local address and port reuse. */
356 #define SO_REUSEPORT SO_REUSEPORT
357 SO_TIMESTAMP = 0x0400, /* Timestamp received dgram traffic. */
358 #define SO_TIMESTAMP SO_TIMESTAMP
359 SO_SNDBUF = 0x1001, /* Send buffer size. */
360 #define SO_SNDBUF SO_SNDBUF
361 SO_RCVBUF = 0x1002, /* Receive buffer. */
362 #define SO_RCVBUF SO_RCVBUF
363 SO_SNDLOWAT = 0x1003, /* Send low-water mark. */
364 #define SO_SNDLOWAT SO_SNDLOWAT
365 SO_RCVLOWAT = 0x1004, /* Receive low-water mark. */
366 #define SO_RCVLOWAT SO_RCVLOWAT
367 SO_SNDTIMEO = 0x1005, /* Send timeout. */
368 #define SO_SNDTIMEO SO_SNDTIMEO
369 SO_RCVTIMEO = 0x1006, /* Receive timeout. */
370 #define SO_RCVTIMEO SO_RCVTIMEO
371 SO_ERROR = 0x1007, /* Get and clear error status. */
372 #define SO_ERROR SO_ERROR
373 SO_STYLE = 0x1008, /* Get socket connection style. */
374 #define SO_STYLE SO_STYLE
375 SO_TYPE = SO_STYLE, /* Compatible name for SO_STYLE. */
376 #define SO_TYPE SO_TYPE
377 SO_LABEL = 0x1009,
378 #define SO_LABEL SO_LABEL
379 SO_PEERLABEL = 0x1010,
380 #define SO_PEERLABEL SO_PEERLABEL
381 SO_LISTENQLIMIT = 0x1011,
382 #define SO_LISTENQLIMIT SO_LISTENQLIMIT
383 SO_LISTENQLEN = 0x1012,
384 #define SO_LISTENQLEN SO_LISTENQLEN
385 SO_LISTENINCQLEN = 0x1013,
386 #define SO_LISTENINCQLEN SO_LISTENINCQLEN
387 SO_SETFIB = 0x1014,
388 #define SO_SETFIB SO_SETFIB
389 SO_USER_COOKIE = 0x1015,
390 #define SO_USER_COOKIE SO_USER_COOKIE
391 SO_PROTOCOL = 0x1016,
392 #define SO_PROTOCOL SO_PROTOCOL
393 SO_PROTOTYPE = SO_PROTOCOL
394 #define SO_PROTOTYPE SO_PROTOTYPE
395 };
396
397 /* Socket options. */
398 #define LOCAL_PEERCRED 0x001 /* retrieve peer credentials */
399 #define LOCAL_CREDS 0x002 /* pass credentials to receiver */
400 #define LOCAL_CONNWAIT 0x004 /* connects block until accepted */
401
402 /* Structure used to manipulate the SO_LINGER option. */
403 struct linger
404 {
405 int l_onoff; /* Nonzero to linger on close. */
406 int l_linger; /* Time to linger. */
407 };
408
409 /* Magic IPv4 addresses defined in FreeBSD version of <netinet/in.h>, but not
410 included in Glibc version of the same header. */
411 #define INADDR_ALLRPTS_GROUP (uint32_t)0xe0000016 /* 224.0.0.22, IGMPv3 */
412 #define INADDR_CARP_GROUP (uint32_t)0xe0000012 /* 224.0.0.18 */
413 #define INADDR_PFSYNC_GROUP (uint32_t)0xe00000f0 /* 224.0.0.240 */
414 #define INADDR_ALLMDNS_GROUP (uint32_t)0xe00000fb /* 224.0.0.251 */
415
416 #ifdef __USE_MISC
417
418 struct sf_hdtr;
419
420 __BEGIN_DECLS
421
422 extern int bsd_sendfile (int __in_fd, int __out_sock,
423 __off_t __in_offset, size_t __nbytes,
424 struct sf_hdtr *__hdtr, __off_t *__sockbytes,
425 int __flags) __THROW;
426
427 __END_DECLS
428
429 #endif /* Use BSD */
430
431 #endif /* bits/socket.h */