1
/* @(#)socket.h 6.23 7/18/94 - STREAMware TCP/IP source */
3
* Copyrighted as an unpublished work.
4
* (c) Copyright 1987-1994 Legent Corporation
9
* These programs are supplied under a license. They may be used,
10
* disclosed, and/or copied only as permitted under such license
11
* agreement. Any copy must contain the above copyright notice and
12
* this restricted rights notice. Use, copying, and/or disclosure
13
* of the programs is strictly prohibited unless otherwise provided
14
* in the license agreement.
17
/* SCCS IDENTIFICATION */
19
* Copyright (c) 1985 Regents of the University of California.
20
* All rights reserved.
22
* Redistribution and use in source and binary forms are permitted
23
* provided that the above copyright notice and this paragraph are
24
* duplicated in all such forms and that any documentation,
25
* advertising materials, and other materials related to such
26
* distribution and use acknowledge that the software was developed
27
* by the University of California, Berkeley. The name of the
28
* University may not be used to endorse or promote products derived
29
* from this software without specific prior written permission.
30
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
31
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
32
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
35
#ifndef __sys_socket_h
36
#define __sys_socket_h
38
#if !defined(FD_SETSIZE)
39
/* Pick up select stuff from standard system include */
40
#include <sys/types.h>
43
/* socket.h 6.1 83/07/29 */
46
* Definitions related to sockets: types, address families, options.
52
#define SOCK_STREAM 1 /* stream socket */
53
#define SOCK_DGRAM 2 /* datagram socket */
54
#define SOCK_RAW 3 /* raw-protocol interface */
55
#define SOCK_RDM 4 /* reliably-delivered message */
56
#define SOCK_SEQPACKET 5 /* sequenced packet stream */
59
* Option flags per-socket.
61
#define SO_DEBUG 0x0001 /* turn on debugging info recording */
62
#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
63
#define SO_REUSEADDR 0x0004 /* allow local address reuse */
64
#define SO_KEEPALIVE 0x0008 /* keep connections alive */
65
#define SO_DONTROUTE 0x0010 /* just use interface addresses */
66
#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
67
#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
68
#define SO_LINGER 0x0080 /* linger on close if data present */
69
#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
70
#define SO_ORDREL 0x0200 /* give use orderly release */
71
#define SO_IMASOCKET 0x0400 /* use socket semantics (affects bind) */
72
#define SO_MGMT 0x0800 /* => it is used for mgmt. purposes */
73
#define SO_REUSEPORT 0x1000 /* allow local port reuse */
76
* Additional options, not kept in so_options.
78
#define SO_SNDBUF 0x1001 /* send buffer size */
79
#define SO_RCVBUF 0x1002 /* receive buffer size */
80
#define SO_SNDLOWAT 0x1003 /* send low-water mark */
81
#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
82
#define SO_SNDTIMEO 0x1005 /* send timeout */
83
#define SO_RCVTIMEO 0x1006 /* receive timeout */
84
#define SO_ERROR 0x1007 /* get error status and clear */
85
#define SO_TYPE 0x1008 /* get socket type */
86
#define SO_PROTOTYPE 0x1009 /* get/set protocol type */
89
* Structure used for manipulating linger option.
92
int l_onoff; /* option on/off */
93
int l_linger; /* linger time */
97
* Level number for (get/set)sockopt() to apply to socket itself.
99
#define SOL_SOCKET 0xffff /* options for socket level */
102
* An option specification consists of an opthdr, followed by the value of
103
* the option. An options buffer contains one or more options. The len
104
* field of opthdr specifies the length of the option value in bytes. This
105
* length must be a multiple of sizeof(long) (use OPTLEN macro).
109
long level; /* protocol level affected */
110
long name; /* option to modify */
111
long len; /* length of option value */
114
#define OPTLEN(x) ((((x) + sizeof(long) - 1) / sizeof(long)) * sizeof(long))
115
#define OPTVAL(opt) ((char *)(opt + 1))
117
#if defined(INKERNEL) || defined(_KERNEL) || defined(_INKERNEL)
119
* the optdefault structure is used for internal tables of option default
123
int optname;/* the option */
124
char *val; /* ptr to default value */
125
int len; /* length of value */
129
* the opproc structure is used to build tables of options processing
130
* functions for in_dooptions().
133
int level; /* options level this function handles */
134
int (*func) (); /* the function */
141
#define AF_UNSPEC 0 /* unspecified */
142
#define AF_UNIX 1 /* local to host (pipes, portals) */
143
#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
144
#define AF_IMPLINK 3 /* arpanet imp addresses */
145
#define AF_PUP 4 /* pup protocols: e.g. BSP */
146
#define AF_CHAOS 5 /* mit CHAOS protocols */
147
#define AF_NS 6 /* XEROX NS protocols */
148
#define AF_ISO 7 /* ISO protocols */
149
#define AF_OSI AF_ISO
150
#define AF_ECMA 8 /* european computer manufacturers */
151
#define AF_DATAKIT 9 /* datakit protocols */
152
#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
153
#define AF_SNA 11 /* IBM SNA */
154
#define AF_DECnet 12 /* DECnet */
155
#define AF_DLI 13 /* Direct data link interface */
156
#define AF_LAT 14 /* LAT */
157
#define AF_HYLINK 15 /* NSC Hyperchannel */
158
#define AF_APPLETALK 16 /* Apple Talk */
159
#define AF_ROUTE 17 /* Internal Routing Protocol */
160
#define AF_LINK 18 /* Link layer interface */
161
#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
166
* Structure used by kernel to store most addresses.
169
u_short sa_family; /* address family */
170
char sa_data[14]; /* up to 14 bytes of direct address */
174
* Structure used by kernel to pass protocol information in raw sockets.
177
unsigned short sp_family; /* address family */
178
unsigned short sp_protocol; /* protocol */
182
* Protocol families, same as address families for now.
184
#define PF_UNSPEC AF_UNSPEC
185
#define PF_UNIX AF_UNIX
186
#define PF_INET AF_INET
187
#define PF_IMPLINK AF_IMPLINK
188
#define PF_PUP AF_PUP
189
#define PF_CHAOS AF_CHAOS
191
#define PF_NBS AF_NBS
192
#define PF_ECMA AF_ECMA
193
#define PF_DATAKIT AF_DATAKIT
194
#define PF_CCITT AF_CCITT
195
#define PF_SNA AF_SNA
196
#define PF_DECnet AF_DECnet
197
#define PF_DLI AF_DLI
198
#define PF_LAT AF_LAT
199
#define PF_HYLINK AF_HYLINK
200
#define PF_APPLETALK AF_APPLETALK
201
#define PF_ROUTE AF_ROUTE
202
#define PF_LINK AF_LINK
203
#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
205
#define PF_MAX AF_MAX
208
* Maximum queue length specifiable by listen.
213
* Message header for recvmsg and sendmsg calls.
214
* Used value-result for recmvsg, value only for sendmsg.
217
caddr_t msg_name; /* optional address */
218
u_int msg_namelen; /* size of address */
219
struct iovec *msg_iov; /* scatter/gather array */
220
u_int msg_iovlen; /* # elements msg_iov */
221
caddr_t msg_control; /* ancillary data, see below */
222
u_int msg_controllen; /* ancillary data buffer len */
223
int msg_flags; /* flags on received message */
225
#define msg_accrights msg_control
226
#define msg_accrightslen msg_controllen
228
#define MSG_OOB 0x1 /* process out-of-band data */
229
#define MSG_PEEK 0x2 /* peek at incoming message */
230
#define MSG_DONTROUTE 0x4 /* send without using routing tables */
231
#define MSG_EOR 0x8 /* data completes record */ /*notused*/
232
#define MSG_TRUNC 0x10 /* data discarded before delivery */
233
#define MSG_CTRUNC 0x20 /* control data lost before delivery */
234
#define MSG_WAITALL 0x40 /* wait for full request or error */ /*notused*/
236
#define MSG_MAXIOVLEN 16
239
* Header for ancillary data objects in msg_control buffer.
240
* Used for additional information with/about a datagram
241
* not expressible by flags. The format is a sequence
242
* of message elements headed by cmsghdr structures.
243
* In STREAMware, we shuffle the fields around a little from what
244
* they were in net-2, so that they line up the same as an opthdr
245
* which simplifies our socket implementation amazingly.
247
* Unfortunately, the opthdrs don't include their own length, which the
248
* cmsghdrs do. What this means is that TLI programmers will not be
249
* able to take something returned using these macros and immediately give
250
* it back to the stack. The size of the struct cmsghdr will have to be
252
* There doesn't seem to be a way to avoid this, since several applications
253
* look into the cmsg_len field and won't work if it doesn't include the size
254
* of the struct cmsghdr.
257
int cmsg_level; /* originating protocol */
258
int cmsg_type; /* protocol-specific type */
259
u_int cmsg_len; /* data byte count, including hdr */
260
/* followed by u_char cmsg_data[]; */
263
/* given pointer to struct adatahdr, return pointer to data */
264
#define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1))
266
/* given pointer to struct adatahdr, return pointer to next adatahdr */
267
#define CMSG_NXTHDR(mhdr, cmsg) \
268
(((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
269
(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
270
(struct cmsghdr *)NULL : \
271
(struct cmsghdr *)((caddr_t)(cmsg) + OPTLEN((cmsg)->cmsg_len)))
273
#define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
275
/* "Socket"-level control message types: */
276
#define SCM_RIGHTS 0x01 /* access rights (array of int) */
279
* This ioctl code uses BSD style ioctls to avoid copyin/out problems.
280
* Ioctls have the command encoded in the lower word, and the size of any in
281
* or out parameters in the upper word. The high 2 bits of the upper word
282
* are used to encode the in/out status of the parameter; for now we restrict
283
* parameters to at most 128 bytes.
285
#define IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
286
#define IOC_VOID 0x20000000 /* no parameters */
287
#define IOC_OUT 0x40000000 /* copy out parameters */
288
#define IOC_IN 0x80000000 /* copy in parameters */
289
#define IOC_INOUT (IOC_IN|IOC_OUT)
290
/* the 0x20000000 is so we can distinguish new ioctls from old */
291
#define _IOS(x,y) (IOC_VOID|(x<<8)|y)
292
#define _IOSR(x,y,t) (IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
293
#define _IOSW(x,y,t) (IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
294
/* this should be _IOSRW, but stdio got there first */
295
#define _IOSWR(x,y,t) (IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
298
* Socket ioctl commands
301
#define SIOCSHIWAT _IOSW('S', 1, int) /* set high watermark */
302
#define SIOCGHIWAT _IOSR('S', 2, int) /* get high watermark */
303
#define SIOCSLOWAT _IOSW('S', 3, int) /* set low watermark */
304
#define SIOCGLOWAT _IOSR('S', 4, int) /* get low watermark */
305
#define SIOCATMARK _IOSR('S', 5, int) /* at oob mark? */
306
#define SIOCSPGRP _IOSW('S', 6, int) /* set process group */
307
#define SIOCGPGRP _IOSR('S', 7, int) /* get process group */
308
#define FIONREAD _IOSR('S', 8, int) /* BSD compatibilty */
309
#define FIONBIO _IOSW('S', 9, int) /* BSD compatibilty */
310
#define FIOASYNC _IOSW('S', 10, int) /* BSD compatibilty */
311
#define SIOCPROTO _IOSW('S', 11, struct socknewproto) /* link proto */
312
#define SIOCGETNAME _IOSR('S', 12, struct sockaddr) /* getsockname */
313
#define SIOCGETPEER _IOSR('S', 13, struct sockaddr) /* getpeername */
314
#define IF_UNITSEL _IOSW('S', 14, int) /* set unit number */
315
#define SIOCXPROTO _IOS('S', 15) /* empty proto table */
316
#define SIOCSHRDTYPE _IOSW('S', 16, int) /* set hardware type */
318
#define SIOCADDRT _IOSW('R', 9, struct ortentry) /* add route */
319
#define SIOCDELRT _IOSW('R', 10, struct ortentry) /* delete route */
321
#define SIOCSIFADDR _IOSW('I', 11, struct ifreq) /* set ifnet address */
322
#define SIOCGIFADDR _IOSWR('I', 12, struct ifreq) /* get ifnet address */
323
#define SIOCSIFDSTADDR _IOSW('I', 13, struct ifreq) /* set p-p address */
324
#define SIOCGIFDSTADDR _IOSWR('I', 14, struct ifreq) /* get p-p address */
325
#define SIOCSIFFLAGS _IOSW('I', 15, struct ifreq) /* set ifnet flags */
326
#define SIOCGIFFLAGS _IOSWR('I', 16, struct ifreq) /* get ifnet flags */
327
#define SIOCGIFCONF _IOSWR('I', 17, struct ifconf) /* get ifnet list */
329
#define SIOCSIFMTU _IOSW('I', 21, struct ifreq) /* get if_mtu */
330
#define SIOCGIFMTU _IOSWR('I', 22, struct ifreq) /* set if_mtu */
333
#define SIOCGIFBRDADDR _IOSWR('I', 32, struct ifreq) /* get broadcast addr */
334
#define SIOCSIFBRDADDR _IOSW('I', 33, struct ifreq) /* set broadcast addr */
335
#define SIOCGIFNETMASK _IOSWR('I', 34, struct ifreq) /* get net addr mask */
336
#define SIOCSIFNETMASK _IOSW('I', 35, struct ifreq) /* set net addr mask */
337
#define SIOCGIFMETRIC _IOSWR('I', 36, struct ifreq) /* get IF metric */
338
#define SIOCSIFMETRIC _IOSW('I', 37, struct ifreq) /* set IF metric */
340
#define SIOCSARP _IOSW('I', 38, struct arpreq) /* set arp entry */
341
#define SIOCGARP _IOSWR('I', 39, struct arpreq) /* get arp entry */
342
#define SIOCDARP _IOSW('I', 40, struct arpreq) /* delete arp entry */
344
#define SIOCSIFNAME _IOSW('I', 41, struct ifreq) /* set interface name */
345
#define SIOCGIFONEP _IOSWR('I', 42, struct ifreq) /* get one-packet params */
346
#define SIOCSIFONEP _IOSW('I', 43, struct ifreq) /* set one-packet params */
347
#define SIOCDIFADDR _IOSW('I', 44, struct ifreq) /* delete IF addr */
348
#define SIOCAIFADDR _IOSW('I', 45, struct ifaliasreq) /*add/change IF alias*/
349
#define SIOCADDMULTI _IOSW('I', 49, struct ifreq) /* add m'cast addr */
350
#define SIOCDELMULTI _IOSW('I', 50, struct ifreq) /* del m'cast addr */
351
#define SIOCGIFALIAS _IOSWR('I', 51, struct ifaliasreq) /* get IF alias */
354
#define SIOCSOCKSYS _IOSW('I', 66, struct socksysreq) /* Pseudo socket syscall */
356
/* these use ifr_metric to pass the information */
357
#define SIOCSIFDEBUG _IOSW('I', 67, struct ifreq) /* set if debug level */
358
#define SIOCGIFDEBUG _IOSWR('I', 68, struct ifreq) /* get if debug level */
360
#define SIOCSIFTYPE _IOSW('I', 69, struct ifreq) /* set if MIB type */
361
#define SIOCGIFTYPE _IOSWR('I', 70, struct ifreq) /* get if MIB type */
363
#define SIOCGIFNUM _IOSR('I', 71, int) /* get number of ifs */
365
* This returns the number of ifreqs that SIOCGIFCONF would return, including
366
* aliases. This is the preferred way of sizing a buffer big enough to hold
369
#define SIOCGIFANUM _IOSR('I', 72, int) /* get number of ifreqs */
371
* Interface specific performance tuning
373
#define SIOCGIFPERF _IOSR('I', 73, struct ifreq) /* get perf info */
374
#define SIOCSIFPERF _IOSR('I', 74, struct ifreq) /* get perf info */
377
* This structure is used to encode pseudo system calls
380
/* When porting, make this the widest thing it can be */
385
* This structure is used for adding new protocols to the list supported by
388
struct socknewproto {
389
int family; /* address family (AF_INET, etc.) */
390
int type; /* protocol type (SOCK_STREAM, etc.) */
391
int proto; /* per family proto number */
392
dev_t dev; /* major/minor to use (must be a clone) */
393
int flags; /* protosw flags */
397
* utility definitions.
403
#define MIN(x,y) ((x) < (y) ? (x) : (y))
405
#define MAX(x,y) ((x) > (y) ? (x) : (y))
408
#define MAXHOSTNAMELEN 256
410
#define NBBY 8 /* number of bits in a byte */
413
/* defines for user/kernel interface */
415
#define MAX_MINOR (makedev(1,0) - 1) /* could be non-portable */
417
#define SOCKETSYS 140 /* SCO 3.2v5 */
422
#define SO_GETPEERNAME 4
423
#define SO_GETSOCKNAME 5
424
#define SO_GETSOCKOPT 6
427
#define SO_RECVFROM 9
430
#define SO_SETSOCKOPT 12
431
#define SO_SHUTDOWN 13
434
#define SO_GETIPDOMAIN 16
435
#define SO_SETIPDOMAIN 17
436
#define SO_ADJTIME 18
437
#define SO_SETREUID 19
438
#define SO_SETREGID 20
439
#define SO_GETTIME 21
440
#define SO_SETTIME 22
441
#define SO_GETITIMER 23
442
#define SO_SETITIMER 24
443
#define SO_RECVMSG 25
444
#define SO_SENDMSG 26
445
#define SO_SOCKPAIR 27
450
#define M_BCAST 0x80000000
452
/* Definitions and structures used for extracting */
453
/* the size and/or the contents of kernel tables */
455
/* Copyin/out values */
465
#if !defined(_KERNEL) && !defined(INKERNEL) && !defined(_INKERNEL)
467
#include <sys/cdefs.h>
470
int accept __P_((int, struct sockaddr *, int *));
471
int bind __P_((int, const struct sockaddr *, int));
472
int connect __P_((int, const struct sockaddr *, int));
473
int getpeername __P_((int, struct sockaddr *, int *));
474
int getsockname __P_((int, struct sockaddr *, int *));
475
int getsockopt __P_((int, int, int, void *, int *));
476
int setsockopt __P_((int, int, int, const void *, int));
477
int listen __P_((int, int));
478
ssize_t recv __P_((int, void *, size_t, int));
479
ssize_t recvfrom __P_((int, void *, size_t, int, struct sockaddr *, int *));
480
int recvmsg __P_((int, struct msghdr *, int));
481
ssize_t send __P_((int, const void *, size_t, int));
482
int sendmsg __P_((int, const struct msghdr *, int));
483
ssize_t sendto __P_((int, const void *, size_t, int, const struct sockaddr *, int));
484
int shutdown __P_((int, int));
485
int socket __P_((int, int, int));
486
int socketpair __P_((int, int, int, int[2]));
489
#endif /* !INKERNEL */
490
#endif /* __sys_socket_h */