4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
23 * Copyright 2015 Lauri Tirkkonen <lotheac@iki.fi>
25 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
26 * Copyright 2015, Joyent, Inc. All rights reserved.
29 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
30 /* All Rights Reserved */
33 * University Copyright- Copyright (c) 1982, 1986, 1988
34 * The Regents of the University of California
37 * University Acknowledgment- Portions of this document are derived from
38 * software developed by the University of California, Berkeley, and its
42 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
47 #include <sys/types.h>
49 #include <sys/feature_tests.h>
50 #include <sys/socket_impl.h>
51 #include <netinet/in.h>
61 * The socklen definitions are reproduced in netinet/in.h for the inet6_
62 * functions. Exposing all of sys/socket.h via netinet/in.h breaks existing
63 * applications and is not required by austin.
65 typedef uint32_t socklen_t
;
67 #endif /* _SOCKLEN_T */
72 #define SOCK_STREAM 2 /* stream socket */
73 #define SOCK_DGRAM 1 /* datagram socket */
74 #define SOCK_RAW 4 /* raw-protocol interface */
75 #define SOCK_SEQPACKET 6 /* sequenced packet stream */
76 #define SOCK_TYPE_MASK 0xffff /* type reside in these bits only */
79 * Flags for socket() and accept4()
81 #define SOCK_CLOEXEC 0x080000 /* like open(2) O_CLOEXEC for socket */
82 #define SOCK_NONBLOCK 0x100000 /* like O_NONBLOCK */
83 #define SOCK_NDELAY 0x200000 /* like O_NDELAY */
86 * Option flags per-socket.
88 #define SO_DEBUG 0x0001 /* turn on debugging info recording */
89 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
90 #define SO_REUSEADDR 0x0004 /* allow local address reuse */
91 #define SO_KEEPALIVE 0x0008 /* keep connections alive */
92 #define SO_DONTROUTE 0x0010 /* just use interface addresses */
93 #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
94 #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
95 #define SO_LINGER 0x0080 /* linger on close if data present */
96 #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
97 #define SO_DGRAM_ERRIND 0x0200 /* Application wants delayed error */
98 #define SO_RECVUCRED 0x0400 /* Application wants ucred of sender */
101 * Socket options are passed using a signed integer, but it is also rare
102 * for more than one to ever be passed at the same time with setsockopt
103 * and only one at a time can be retrieved with getsockopt.
105 * Since the lower numbers cannot be renumbered for compatibility reasons,
106 * it would seem that we need to start a new number space (0x40000000 -
107 * 0x7fffffff) for those that don't need to be stored as a bit flag
108 * somewhere. This limits the flag options to 30 but that seems to be
109 * plenty, anyway. 0x40000000 is reserved for future use.
111 #define SO_ATTACH_FILTER 0x40000001
112 #define SO_DETACH_FILTER 0x40000002
115 #define SO_SND_COPYAVOID 0x0800 /* Internal: use zero-copy */
116 #define SO_SND_BUFINFO 0x1000 /* Internal: get buffer info */
117 /* when doing zero-copy */
119 struct so_snd_bufinfo
{
120 ushort_t sbi_wroff
; /* Write offset */
121 ssize_t sbi_maxblk
; /* Max size of a single mblk */
122 ssize_t sbi_maxpsz
; /* Max total size of a mblk chain */
123 ushort_t sbi_tail
; /* Extra space available at the end */
128 * Additional options, not kept in so_options.
130 #define SO_SNDBUF 0x1001 /* send buffer size */
131 #define SO_RCVBUF 0x1002 /* receive buffer size */
132 #define SO_SNDLOWAT 0x1003 /* send low-water mark */
133 #define SO_RCVLOWAT 0x1004 /* receive low-water mark */
134 #define SO_SNDTIMEO 0x1005 /* send timeout */
135 #define SO_RCVTIMEO 0x1006 /* receive timeout */
136 #define SO_ERROR 0x1007 /* get error status and clear */
137 #define SO_TYPE 0x1008 /* get socket type */
138 #define SO_PROTOTYPE 0x1009 /* get/set protocol type */
139 #define SO_DOMAIN 0x100c /* get socket domain */
140 #define SO_RCVPSH 0x100d /* receive interval to push data */
142 /* "Socket"-level control message types: */
143 #define SCM_RIGHTS 0x1010 /* access rights (array of int) */
144 #define SO_SECATTR 0x1011 /* socket's security attributes */
145 #define SCM_UCRED 0x1012 /* sender's ucred */
146 #define SO_TIMESTAMP 0x1013 /* socket-level timestamp option */
147 #define SCM_TIMESTAMP SO_TIMESTAMP /* socket control message timestamp */
148 #define SO_ALLZONES 0x1014 /* bind in all zones */
149 #define SO_EXCLBIND 0x1015 /* exclusive binding */
150 #define SO_VRRP 0x1017 /* VRRP control socket */
153 #define SO_SRCADDR 0x2001 /* Internal: AF_UNIX source address */
154 #define SO_FILEP 0x2002 /* Internal: AF_UNIX file pointer */
155 #define SO_UNIX_CLOSE 0x2003 /* Internal: AF_UNIX peer closed */
159 * Socket filter options
161 #define FIL_ATTACH 0x1 /* attach filter */
162 #define FIL_DETACH 0x2 /* detach filter */
163 #define FIL_LIST 0x3 /* list attached filters */
165 #define FILNAME_MAX 32
167 * Structure returned by FIL_LIST
170 int fi_flags
; /* see below (FILF_*) */
171 int fi_pos
; /* position (0 is bottom) */
172 char fi_name
[FILNAME_MAX
]; /* filter name */
175 #define FILF_PROG 0x1 /* programmatic attach */
176 #define FILF_AUTO 0x2 /* automatic attach */
177 #define FILF_BYPASS 0x4 /* filter is not active */
181 * new socket open flags to identify socket and acceptor streams
183 #define SO_ACCEPTOR 0x20000 /* acceptor socket */
184 #define SO_SOCKSTR 0x40000 /* normal socket stream */
185 #define SO_FALLBACK 0x80000 /* fallback to TPI socket */
188 * Flags for socket_create() and socket_newconn()
190 #define SOCKET_SLEEP KM_SLEEP
191 #define SOCKET_NOSLEEP KM_NOSLEEP
196 * Structure used for manipulating linger option.
199 int l_onoff
; /* option on/off */
200 int l_linger
; /* linger time */
204 * Levels for (get/set)sockopt() that don't apply to a specific protocol.
206 #define SOL_SOCKET 0xffff /* options for socket level */
207 #if defined(_KERNEL) || defined(__EXTENSIONS__)
208 #define SOL_ROUTE 0xfffe /* options for routing socket level */
210 #define SOL_PACKET 0xfffd /* options for packet level */
211 #define SOL_FILTER 0xfffc /* options for socket filter level */
216 * Some of these constant names are copied for the DTrace IP provider in
217 * usr/src/lib/libdtrace/common/{ip.d.in, ip.sed.in}, which should be kept
220 #define AF_UNSPEC 0 /* unspecified */
221 #define AF_UNIX 1 /* local to host (pipes, portals) */
222 #define AF_LOCAL AF_UNIX /* Synonym for AF_UNIX */
223 #define AF_FILE AF_UNIX /* Synonym for AF_UNIX */
224 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
225 #define AF_IMPLINK 3 /* arpanet imp addresses */
226 #define AF_PUP 4 /* pup protocols: e.g. BSP */
227 #define AF_CHAOS 5 /* mit CHAOS protocols */
228 #define AF_NS 6 /* XEROX NS protocols */
229 #define AF_NBS 7 /* nbs protocols */
230 #define AF_ECMA 8 /* european computer manufacturers */
231 #define AF_DATAKIT 9 /* datakit protocols */
232 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
233 #define AF_SNA 11 /* IBM SNA */
234 #define AF_DECnet 12 /* DECnet */
235 #define AF_DLI 13 /* Direct data link interface */
236 #define AF_LAT 14 /* LAT */
237 #define AF_HYLINK 15 /* NSC Hyperchannel */
238 #define AF_APPLETALK 16 /* Apple Talk */
239 #define AF_NIT 17 /* Network Interface Tap */
240 #define AF_802 18 /* IEEE 802.2, also ISO 8802 */
241 #define AF_OSI 19 /* umbrella for all families used */
242 #define AF_X25 20 /* CCITT X.25 in particular */
243 #define AF_OSINET 21 /* AFI = 47, IDI = 4 */
244 #define AF_GOSIP 22 /* U.S. Government OSI */
245 #define AF_IPX 23 /* Novell Internet Protocol */
246 #define AF_ROUTE 24 /* Internal Routing Protocol */
247 #define AF_LINK 25 /* Link-layer interface */
248 #define AF_INET6 26 /* Internet Protocol, Version 6 */
249 #define AF_KEY 27 /* Security Association DB socket */
250 #define AF_POLICY 29 /* Security Policy DB socket */
251 #define AF_INET_OFFLOAD 30 /* Sun private; do not use */
252 #define AF_TRILL 31 /* TRILL interface */
253 #define AF_PACKET 32 /* PF_PACKET Linux socket interface */
258 * Protocol families, same as address families for now.
260 #define PF_UNSPEC AF_UNSPEC
261 #define PF_UNIX AF_UNIX
262 #define PF_LOCAL PF_UNIX
263 #define PF_FILE PF_UNIX
264 #define PF_INET AF_INET
265 #define PF_IMPLINK AF_IMPLINK
266 #define PF_PUP AF_PUP
267 #define PF_CHAOS AF_CHAOS
269 #define PF_NBS AF_NBS
270 #define PF_ECMA AF_ECMA
271 #define PF_DATAKIT AF_DATAKIT
272 #define PF_CCITT AF_CCITT
273 #define PF_SNA AF_SNA
274 #define PF_DECnet AF_DECnet
275 #define PF_DLI AF_DLI
276 #define PF_LAT AF_LAT
277 #define PF_HYLINK AF_HYLINK
278 #define PF_APPLETALK AF_APPLETALK
279 #define PF_NIT AF_NIT
280 #define PF_802 AF_802
281 #define PF_OSI AF_OSI
282 #define PF_X25 AF_X25
283 #define PF_OSINET AF_OSINET
284 #define PF_GOSIP AF_GOSIP
285 #define PF_IPX AF_IPX
286 #define PF_ROUTE AF_ROUTE
287 #define PF_LINK AF_LINK
288 #define PF_INET6 AF_INET6
289 #define PF_KEY AF_KEY
290 #define PF_POLICY AF_POLICY
291 #define PF_INET_OFFLOAD AF_INET_OFFLOAD /* Sun private; do not use */
292 #define PF_TRILL AF_TRILL
293 #define PF_PACKET AF_PACKET
295 #define PF_MAX AF_MAX
298 * Maximum queue length specifiable by listen.
300 #define SOMAXCONN 128
303 * Message header for recvmsg and sendmsg calls.
306 void *msg_name
; /* optional address */
307 socklen_t msg_namelen
; /* size of address */
308 struct iovec
*msg_iov
; /* scatter/gather array */
309 int msg_iovlen
; /* # elements in msg_iov */
311 void *msg_control
; /* ancillary data */
312 socklen_t msg_controllen
; /* ancillary data buffer len */
313 int msg_flags
; /* flags on received message */
318 #if defined(_SYSCALL32)
321 caddr32_t msg_name
; /* optional address */
322 uint32_t msg_namelen
; /* size of address */
323 caddr32_t msg_iov
; /* scatter/gather array */
324 int32_t msg_iovlen
; /* # elements in msg_iov */
325 caddr32_t msg_control
; /* ancillary data */
326 uint32_t msg_controllen
; /* ancillary data buffer len */
327 int32_t msg_flags
; /* flags on received message */
330 #endif /* _SYSCALL32 */
333 #define MSG_OOB 0x1 /* process out-of-band data */
334 #define MSG_PEEK 0x2 /* peek at incoming message */
335 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
336 /* Added for XPGv2 compliance */
337 #define MSG_EOR 0x8 /* Terminates a record */
338 #define MSG_CTRUNC 0x10 /* Control data truncated */
339 #define MSG_TRUNC 0x20 /* Normal data truncated */
340 #define MSG_WAITALL 0x40 /* Wait for complete recv or error */
341 #define MSG_DUPCTRL 0x800 /* Save control message for use with */
342 /* with left over data */
343 /* End of XPGv2 compliance */
344 #define MSG_DONTWAIT 0x80 /* Don't block for this recv */
345 #define MSG_NOTIFICATION 0x100 /* Notification, not data */
347 /* Obsolete but kept for compilation compatability. Use IOV_MAX. */
348 #define MSG_MAXIOVLEN 16
353 * for kernel socket only
355 #define MSG_MBLK_QUICKRELE 0x10000000 /* free mblk chain */
356 /* in timely manner */
357 #define MSG_USERSPACE 0x20000000 /* buffer from user space */
362 /* Added for XPGv2 compliance */
368 socklen_t cmsg_len
; /* data byte count, including hdr */
369 int cmsg_level
; /* originating protocol */
370 int cmsg_type
; /* protocol-specific type */
374 /* To maintain backward compatibility, alignment needs to be 8 on sparc. */
375 #define _CMSG_HDR_ALIGNMENT 8
377 /* for __i386 (and other future architectures) */
378 #define _CMSG_HDR_ALIGNMENT 4
379 #endif /* defined(__sparc) */
381 #define _CMSG_DATA_ALIGNMENT (sizeof (int))
382 #define _CMSG_HDR_ALIGN(x) (((uintptr_t)(x) + _CMSG_HDR_ALIGNMENT - 1) & \
383 ~(_CMSG_HDR_ALIGNMENT - 1))
384 #define _CMSG_DATA_ALIGN(x) (((uintptr_t)(x) + _CMSG_DATA_ALIGNMENT - 1) & \
385 ~(_CMSG_DATA_ALIGNMENT - 1))
386 #define CMSG_DATA(c) \
387 ((unsigned char *)_CMSG_DATA_ALIGN((struct cmsghdr *)(c) + 1))
389 #define CMSG_FIRSTHDR(m) \
390 (((m)->msg_controllen < sizeof (struct cmsghdr)) ? \
391 NULL : (struct cmsghdr *)((m)->msg_control))
393 #define CMSG_NXTHDR(m, c) \
394 (((c) == 0) ? CMSG_FIRSTHDR(m) : \
395 ((((uintptr_t)_CMSG_HDR_ALIGN((char *)(c) + \
396 ((struct cmsghdr *)(c))->cmsg_len) + sizeof (struct cmsghdr)) > \
397 (((uintptr_t)((struct msghdr *)(m))->msg_control) + \
398 ((uintptr_t)((struct msghdr *)(m))->msg_controllen))) ? \
399 NULL : ((struct cmsghdr *)_CMSG_HDR_ALIGN((char *)(c) + \
400 ((struct cmsghdr *)(c))->cmsg_len))))
402 /* Amount of space + padding needed for a message of length l */
403 #define CMSG_SPACE(l) \
404 ((unsigned int)_CMSG_HDR_ALIGN(sizeof (struct cmsghdr) + (l)))
406 /* Value to be used in cmsg_len, does not include trailing padding */
407 #define CMSG_LEN(l) \
408 ((unsigned int)_CMSG_DATA_ALIGN(sizeof (struct cmsghdr)) + (l))
410 #if !defined(_KERNEL) || defined(_BOOT)
411 extern int accept(int, struct sockaddr
*_RESTRICT_KYWD
, socklen_t
*);
412 extern int accept4(int, struct sockaddr
*_RESTRICT_KYWD
, socklen_t
*, int);
413 extern int bind(int, const struct sockaddr
*, socklen_t
);
414 extern int connect(int, const struct sockaddr
*, socklen_t
);
415 extern int getpeername(int, struct sockaddr
*_RESTRICT_KYWD
, socklen_t
*);
416 extern int getsockname(int, struct sockaddr
*_RESTRICT_KYWD
, socklen_t
*);
417 extern int getsockopt(int, int, int, void *_RESTRICT_KYWD
, socklen_t
*);
418 extern int listen(int, int);
419 extern int socketpair(int, int, int, int *);
420 extern ssize_t
recv(int, void *, size_t, int);
421 extern ssize_t
recvfrom(int, void *_RESTRICT_KYWD
, size_t, int,
422 struct sockaddr
*_RESTRICT_KYWD
, socklen_t
*);
423 extern ssize_t
recvmsg(int, struct msghdr
*, int);
424 extern ssize_t
send(int, const void *, size_t, int);
425 extern ssize_t
sendmsg(int, const struct msghdr
*, int);
426 extern ssize_t
sendto(int, const void *, size_t, int, const struct sockaddr
*,
428 extern int setsockopt(int, int, int, const void *, socklen_t
);
429 extern int shutdown(int, int);
430 extern int socket(int, int, int);
431 extern int sockatmark(int);
432 #endif /* !defined(_KERNEL) || defined(_BOOT) */
438 #endif /* _SYS_SOCKET_H */