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