xref: /haiku/headers/posix/sys/socket.h (revision baa326e0ecbb94b6c340f853c9b5055aa9f47da2)
1 /* sys/socket.h */
2 
3 
4 #ifndef _SYS_SOCKET_H
5 #define _SYS_SOCKET_H
6 
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <sys/ioctl.h>
10 
11 typedef uint32 socklen_t;
12 
13 /* These are the address/protocol families we'll be using... */
14 /* NB these should be added to as required... */
15 
16 /* If we want to have Binary compatability we may need to alter these
17  * to agree with the Be versions...
18  */
19 #define	AF_UNSPEC       0
20 #define AF_LOCAL        1
21 #define AF_UNIX         AF_LOCAL /* for compatability */
22 #define AF_INET         2
23 #define AF_ROUTE        3
24 #define AF_IMPLINK      4
25 #define AF_LINK         18
26 #define AF_IPX          23
27 #define AF_INET6        24
28 
29 #define AF_MAX          24
30 
31 #define PF_UNSPEC		AF_UNSPEC
32 #define PF_INET			AF_INET
33 #define PF_ROUTE		AF_ROUTE
34 #define PF_LINK			AF_LINK
35 #define PF_INET6		AF_INET6
36 #define PF_IPX			AF_IPX
37 #define PF_IMPLINK      AF_IMPLINK
38 
39 /* Types of socket we can create (eventually) */
40 #define SOCK_DGRAM     10
41 #define SOCK_STREAM    11
42 #define SOCK_RAW       12
43 #define SOCK_MISC     255
44 
45 /*
46  * Option flags per-socket.
47  */
48 #define SO_DEBUG        0x0001          /* turn on debugging info recording */
49 #define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
50 #define SO_REUSEADDR    0x0004          /* allow local address reuse */
51 #define SO_KEEPALIVE    0x0008          /* keep connections alive */
52 #define SO_DONTROUTE    0x0010          /* just use interface addresses */
53 #define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
54 #define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
55 #define SO_LINGER       0x0080          /* linger on close if data present */
56 #define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
57 #define SO_REUSEPORT    0x0200          /* allow local address & port reuse */
58 
59 #define SOL_SOCKET      0xffff
60 
61 /*
62  * Additional options, not kept in so_options.
63  */
64 #define SO_SNDBUF       0x1001          /* send buffer size */
65 #define SO_RCVBUF       0x1002          /* receive buffer size */
66 #define SO_SNDLOWAT     0x1003          /* send low-water mark */
67 #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
68 #define SO_SNDTIMEO     0x1005          /* send timeout */
69 #define SO_RCVTIMEO     0x1006          /* receive timeout */
70 #define SO_ERROR        0x1007          /* get error status and clear */
71 #define SO_TYPE         0x1008          /* get socket type */
72 #define SO_NETPROC      0x1020          /* multiplex; network processing */
73 
74 /*
75  * These are the valid values for the "how" field used by shutdown(2).
76  */
77 #define SHUT_RD         1
78 #define SHUT_WR         2
79 #define SHUT_RDWR       3
80 
81 struct linger {
82 	int l_onoff;
83 	int l_linger;
84 };
85 
86 struct sockaddr {
87 	uint8	sa_len;
88 	uint8	sa_family;
89 	uint8	sa_data[30];
90 };
91 
92 /* this can hold ANY sockaddr we care to throw at it! */
93 struct sockaddr_storage {
94 	uint8       ss_len;         /* total length */
95 	uint8       ss_family;      /* address family */
96 	uint8       __ss_pad1[6];   /* align to quad */
97 	uint64      __ss_pad2;      /* force alignment for stupid compilers */
98 	uint8       __ss_pad3[240]; /* pad to a total of 256 bytes */
99 };
100 
101 struct sockproto {
102 	uint16 sp_family;
103 	uint16 sp_protocol;
104 };
105 
106 #define CTL_NET         4
107 
108 #define CTL_NET_NAMES { \
109         { 0, 0 }, \
110         { "unix", CTLTYPE_NODE }, \
111         { "inet", CTLTYPE_NODE }, \
112         { "implink", CTLTYPE_NODE }, \
113         { "pup", CTLTYPE_NODE }, \
114         { "chaos", CTLTYPE_NODE }, \
115         { "xerox_ns", CTLTYPE_NODE }, \
116         { "iso", CTLTYPE_NODE }, \
117         { "emca", CTLTYPE_NODE }, \
118         { "datakit", CTLTYPE_NODE }, \
119         { "ccitt", CTLTYPE_NODE }, \
120         { "ibm_sna", CTLTYPE_NODE }, \
121         { "decnet", CTLTYPE_NODE }, \
122         { "dec_dli", CTLTYPE_NODE }, \
123         { "lat", CTLTYPE_NODE }, \
124         { "hylink", CTLTYPE_NODE }, \
125         { "appletalk", CTLTYPE_NODE }, \
126         { "route", CTLTYPE_NODE }, \
127         { "link_layer", CTLTYPE_NODE }, \
128         { "xtp", CTLTYPE_NODE }, \
129         { "coip", CTLTYPE_NODE }, \
130         { "cnt", CTLTYPE_NODE }, \
131         { "rtip", CTLTYPE_NODE }, \
132         { "ipx", CTLTYPE_NODE }, \
133         { "inet6", CTLTYPE_NODE }, \
134         { "pip", CTLTYPE_NODE }, \
135         { "isdn", CTLTYPE_NODE }, \
136         { "natm", CTLTYPE_NODE }, \
137         { "encap", CTLTYPE_NODE }, \
138         { "sip", CTLTYPE_NODE }, \
139         { "key", CTLTYPE_NODE }, \
140 }
141 
142 /*
143  * PF_ROUTE - Routing table
144  *
145  * Three additional levels are defined:
146  *      Fourth: address family, 0 is wildcard
147  *      Fifth: type of info, defined below
148  *      Sixth: flag(s) to mask with for NET_RT_FLAGS
149  */
150 #define NET_RT_DUMP     1               /* dump; may limit to a.f. */
151 #define NET_RT_FLAGS    2               /* by flags, e.g. RESOLVING */
152 #define NET_RT_IFLIST   3               /* survey interface list */
153 #define NET_RT_MAXID    4
154 
155 #define CTL_NET_RT_NAMES { \
156         { 0, 0 }, \
157         { "dump", CTLTYPE_STRUCT }, \
158         { "flags", CTLTYPE_STRUCT }, \
159         { "iflist", CTLTYPE_STRUCT }, \
160 }
161 
162                         /* Max listen queue for a socket */
163 #define SOMAXCONN	5	/* defined as 128 in OpenBSD */
164 
165 struct msghdr {
166 	char *	msg_name;         /* address we're using (optional) */
167 	uint msg_namelen;         /* length of address */
168 	struct iovec *msg_iov;    /* scatter/gather array we'll use */
169 	uint msg_iovlen;          /* # elements in msg_iov */
170 	char * msg_control;       /* extra data */
171 	uint msg_controllen;      /* length of extra data */
172 	int msg_flags;            /* flags */
173 };
174 
175 /* Defines used in msghdr structure. */
176 #define MSG_OOB         0x1             /* process out-of-band data */
177 #define MSG_PEEK        0x2             /* peek at incoming message */
178 #define MSG_DONTROUTE   0x4             /* send without using routing tables */
179 #define MSG_EOR         0x8             /* data completes record */
180 #define MSG_TRUNC       0x10            /* data discarded before delivery */
181 #define MSG_CTRUNC      0x20            /* control data lost before delivery */
182 #define MSG_WAITALL     0x40            /* wait for full request or error */
183 #define MSG_DONTWAIT    0x80            /* this message should be nonblocking */
184 #define MSG_BCAST       0x100           /* this message rec'd as broadcast */
185 #define MSG_MCAST       0x200           /* this message rec'd as multicast */
186 
187 struct cmsghdr {
188 	uint	cmsg_len;
189 	int	cmsg_level;
190 	int	cmsg_type;
191 	/* there now follows uchar[] cmsg_data */
192 };
193 
194 #if 0
195 #define SIOCSHIWAT      _IOW('s',  0, int)              /* set high watermark */
196 #define SIOCGHIWAT      _IOR('s',  1, int)              /* get high watermark */
197 #define SIOCSLOWAT      _IOW('s',  2, int)              /* set low watermark */
198 #define SIOCGLOWAT      _IOR('s',  3, int)              /* get low watermark */
199 #define SIOCATMARK      _IOR('s',  7, int)              /* at oob mark? */
200 
201 #define SIOCADDRT       _IOW('r', 10, struct ortentry)  /* add route */
202 #define SIOCDELRT       _IOW('r', 11, struct ortentry)  /* delete route */
203 
204 #define SIOCSIFADDR     _IOW('i', 12, struct ifreq)     /* set ifnet address */
205 #define OSIOCGIFADDR    _IOWR('i', 13, struct ifreq)    /* get ifnet address */
206 #define SIOCGIFADDR     _IOWR('i', 33, struct ifreq)    /* get ifnet address */
207 #define SIOCSIFDSTADDR  _IOW('i', 14, struct ifreq)     /* set p-p address */
208 #define OSIOCGIFDSTADDR _IOWR('i', 15, struct ifreq)    /* get p-p address */
209 #define SIOCGIFDSTADDR  _IOWR('i', 34, struct ifreq)    /* get p-p address */
210 #define SIOCSIFFLAGS    _IOW('i', 16, struct ifreq)     /* set ifnet flags */
211 #define SIOCGIFFLAGS    _IOWR('i', 17, struct ifreq)    /* get ifnet flags */
212 #define OSIOCGIFBRDADDR _IOWR('i', 18, struct ifreq)    /* get broadcast addr */
213 #define SIOCGIFBRDADDR  _IOWR('i', 35, struct ifreq)    /* get broadcast addr */
214 #define SIOCSIFBRDADDR  _IOW('i', 19, struct ifreq)     /* set broadcast addr */
215 #define OSIOCGIFCONF    _IOWR('i', 20, struct ifconf)   /* get ifnet list */
216 #define SIOCGIFCONF     _IOWR('i', 36, struct ifconf)   /* get ifnet list */
217 #define OSIOCGIFNETMASK _IOWR('i', 21, struct ifreq)    /* get net addr mask */
218 #define SIOCGIFNETMASK  _IOWR('i', 37, struct ifreq)    /* get net addr mask */
219 #define SIOCSIFNETMASK  _IOW('i', 22, struct ifreq)     /* set net addr mask */
220 #define SIOCGIFMETRIC   _IOWR('i', 23, struct ifreq)    /* get IF metric */
221 #define SIOCSIFMETRIC   _IOW('i', 24, struct ifreq)     /* set IF metric */
222 #define SIOCDIFADDR     _IOW('i', 25, struct ifreq)     /* delete IF addr */
223 #define SIOCAIFADDR     _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */
224 #define SIOCGIFDATA     _IOWR('i', 27, struct ifreq)    /* get if_data */
225 
226 #define SIOCGIFMTU      _IOWR('i', 126, struct ifreq)   /* get ifnet MTU */
227 #define SIOCSIFMTU      _IOW('i', 127, struct ifreq)    /* set ifnet MTU */
228 
229 #define SIOCADDMULTI    _IOW('i', 49, struct ifreq)     /* add m'cast addr */
230 #define SIOCDELMULTI    _IOW('i', 50, struct ifreq)     /* del m'cast addr */
231 #endif
232 
233 
234 #ifndef _KERNEL_MODE
235 /* Function declarations */
236 int     socket (int, int, int);
237 int     bind(int, const struct sockaddr *, int);
238 int     connect(int, const struct sockaddr *, int);
239 int 	listen(int, int);
240 int 	accept(int, struct sockaddr *, int *);
241 int     closesocket(int);
242 int     shutdown(int sock, int how);
243 
244 ssize_t send(int, const void *, size_t, int);
245 ssize_t recv(int, void *, size_t, int);
246 ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, size_t);
247 ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, size_t *);
248 
249 int     setsockopt(int, int, int, const void *, size_t);
250 int     getsockopt(int, int, int, void *, size_t *);
251 int     getpeername(int, struct sockaddr *, int *);
252 int     getsockname(int, struct sockaddr *, int *);
253 #endif /* _KERNEL_MODE */
254 
255 #endif /* _SYS_SOCKET_H */
256 
257