PS2SDK
PS2 Homebrew Libraries
socket.h
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
11 /* $NetBSD: socket.h,v 1.131 2021/11/02 20:35:51 christos Exp $ */
12 
13 /*
14  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  * 1. Redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer.
22  * 2. Redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution.
25  * 3. Neither the name of the project nor the names of its contributors
26  * may be used to endorse or promote products derived from this software
27  * without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39  * SUCH DAMAGE.
40  */
41 
42 /*
43  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
44  * The Regents of the University of California. All rights reserved.
45  *
46  * Redistribution and use in source and binary forms, with or without
47  * modification, are permitted provided that the following conditions
48  * are met:
49  * 1. Redistributions of source code must retain the above copyright
50  * notice, this list of conditions and the following disclaimer.
51  * 2. Redistributions in binary form must reproduce the above copyright
52  * notice, this list of conditions and the following disclaimer in the
53  * documentation and/or other materials provided with the distribution.
54  * 3. Neither the name of the University nor the names of its contributors
55  * may be used to endorse or promote products derived from this software
56  * without specific prior written permission.
57  *
58  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68  * SUCH DAMAGE.
69  *
70  * @(#)socket.h 8.6 (Berkeley) 5/3/95
71  */
72 
73 #ifndef _SYS_SOCKET_H_
74 #define _SYS_SOCKET_H_
75 
76 #if 1
77 #include <stdint.h>
78 #include <stddef.h>
79 #include <sys/types.h>
80 #include <sys/cdefs.h>
81 #include <unistd.h>
82 #include <tcpip.h>
83 #endif
84 
85 /*
86  * Maximum queue length specifiable by listen(2).
87  */
88 #ifndef SOMAXCONN
89 #define SOMAXCONN 128
90 #endif
91 
92 /*
93  * Message header for recvmsg and sendmsg calls.
94  * Used value-result for recvmsg, value only for sendmsg.
95  */
96 struct msghdr {
97  void *msg_name; /* optional address */
98  socklen_t msg_namelen; /* size of address */
99  struct iovec *msg_iov; /* scatter/gather array */
100  int msg_iovlen; /* # elements in msg_iov */
101  void *msg_control; /* ancillary data, see below */
102  socklen_t msg_controllen; /* ancillary data buffer len */
103  int msg_flags; /* flags on received message */
104 };
105 
106 // TODO: Not available in LWIP
107 #define MSG_TRUNC 0x0000 /* data discarded before delivery */
108 
109 #if 0
110 #include <sys/featuretest.h>
111 
112 /*
113  * Definitions related to sockets: types, address families, options.
114  */
115 
116 /*
117  * Data types.
118  */
119 #include <sys/ansi.h>
120 
121 #ifndef sa_family_t
122 typedef __sa_family_t sa_family_t;
123 #define sa_family_t __sa_family_t
124 #endif
125 
126 #ifndef socklen_t
127 typedef __socklen_t socklen_t;
128 #define socklen_t __socklen_t
129 #endif
130 
131 #include <machine/ansi.h>
132 
133 #ifdef _BSD_SIZE_T_
134 typedef _BSD_SIZE_T_ size_t;
135 #undef _BSD_SIZE_T_
136 #endif
137 
138 #ifdef _BSD_SSIZE_T_
139 typedef _BSD_SSIZE_T_ ssize_t;
140 #undef _BSD_SSIZE_T_
141 #endif
142 
143 #include <sys/uio.h>
144 #include <sys/sigtypes.h>
145 
146 /*
147  * Socket types.
148  */
149 #define SOCK_STREAM 1 /* stream socket */
150 #define SOCK_DGRAM 2 /* datagram socket */
151 #define SOCK_RAW 3 /* raw-protocol interface */
152 #define SOCK_RDM 4 /* reliably-delivered message */
153 #define SOCK_SEQPACKET 5 /* sequenced packet stream */
154 #define SOCK_CONN_DGRAM 6 /* connection-orientated datagram */
155 #define SOCK_DCCP SOCK_CONN_DGRAM
156 
157 #define SOCK_CLOEXEC 0x10000000 /* set close on exec on socket */
158 #define SOCK_NONBLOCK 0x20000000 /* set non blocking i/o socket */
159 #define SOCK_NOSIGPIPE 0x40000000 /* don't send sigpipe */
160 #define SOCK_FLAGS_MASK 0xf0000000 /* flags mask */
161 
162 /*
163  * Option flags per-socket.
164  */
165 #define SO_DEBUG 0x0001 /* turn on debugging info recording */
166 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
167 #define SO_REUSEADDR 0x0004 /* allow local address reuse */
168 #define SO_KEEPALIVE 0x0008 /* keep connections alive */
169 #define SO_DONTROUTE 0x0010 /* just use interface addresses */
170 #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
171 #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
172 #define SO_LINGER 0x0080 /* linger on close if data present */
173 #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
174 #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
175 /* SO_OTIMESTAMP 0x0400 */
176 #define SO_NOSIGPIPE 0x0800 /* no SIGPIPE from EPIPE */
177 #define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
178 #define SO_TIMESTAMP 0x2000 /* timestamp received dgram traffic */
179 #define SO_RERROR 0x4000 /* Keep track of receive errors */
180 
181 /* Allowed default option flags */
182 #define SO_DEFOPTS (SO_DEBUG|SO_REUSEADDR|SO_KEEPALIVE|SO_DONTROUTE| \
183  SO_BROADCAST|SO_USELOOPBACK|SO_LINGER|SO_OOBINLINE|SO_REUSEPORT| \
184  SO_NOSIGPIPE|SO_TIMESTAMP|SO_RERROR)
185 
186 #define __SO_OPTION_BITS \
187  "\20" \
188  "\1SO_DEBUG" \
189  "\2SO_ACCEPTCONN" \
190  "\3SO_REUSEADDR" \
191  "\4SO_KEEPALIVE" \
192  "\5SO_DONTROUTE" \
193  "\6SO_BROADCAST" \
194  "\7SO_USELOOPBACK" \
195  "\10SO_LINGER" \
196  "\11SO_OOBINLINE" \
197  "\12SO_REUSEPORT" \
198  "\13SO_OTIMESTAMP" \
199  "\14SO_NOSIGPIPE" \
200  "\15SO_ACCEPTFILTER" \
201  "\16SO_TIMESTAMP" \
202  "\17SO_RERROR"
203 
204 /*
205  * Additional options, not kept in so_options.
206  */
207 #define SO_SNDBUF 0x1001 /* send buffer size */
208 #define SO_RCVBUF 0x1002 /* receive buffer size */
209 #define SO_SNDLOWAT 0x1003 /* send low-water mark */
210 #define SO_RCVLOWAT 0x1004 /* receive low-water mark */
211 /* SO_OSNDTIMEO 0x1005 */
212 /* SO_ORCVTIMEO 0x1006 */
213 #define SO_ERROR 0x1007 /* get error status and clear */
214 #define SO_TYPE 0x1008 /* get socket type */
215 #define SO_OVERFLOWED 0x1009 /* datagrams: return packets dropped */
216 
217 #define SO_NOHEADER 0x100a /* user supplies no header to kernel;
218  * kernel removes header and supplies
219  * payload
220  */
221 #define SO_SNDTIMEO 0x100b /* send timeout */
222 #define SO_RCVTIMEO 0x100c /* receive timeout */
223 /*
224  * Structure used for manipulating linger option.
225  */
226 struct linger {
227  int l_onoff; /* option on/off */
228  int l_linger; /* linger time in seconds */
229 };
230 
231 struct accept_filter_arg {
232  char af_name[16];
233  char af_arg[256-16];
234 };
235 
236 /*
237  * Level number for (get/set)sockopt() to apply to socket itself.
238  */
239 #define SOL_SOCKET 0xffff /* options for socket level */
240 
241 /*
242  * Address families.
243  */
244 #define AF_UNSPEC 0 /* unspecified */
245 #define AF_LOCAL 1 /* local to host */
246 #define AF_UNIX AF_LOCAL /* backward compatibility */
247 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
248 #define AF_IMPLINK 3 /* arpanet imp addresses */
249 #define AF_PUP 4 /* pup protocols: e.g. BSP */
250 #define AF_CHAOS 5 /* mit CHAOS protocols */
251 #define AF_NS 6 /* XEROX NS protocols */
252 #define AF_ISO 7 /* ISO protocols */
253 #define AF_OSI AF_ISO
254 #define AF_ECMA 8 /* european computer manufacturers */
255 #define AF_DATAKIT 9 /* datakit protocols */
256 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
257 #define AF_SNA 11 /* IBM SNA */
258 #define AF_DECnet 12 /* DECnet */
259 #define AF_DLI 13 /* DEC Direct data link interface */
260 #define AF_LAT 14 /* LAT */
261 #define AF_HYLINK 15 /* NSC Hyperchannel */
262 #define AF_APPLETALK 16 /* Apple Talk */
263 #define AF_OROUTE 17 /* Internal Routing Protocol */
264 #define AF_LINK 18 /* Link layer interface */
265 #if defined(_NETBSD_SOURCE)
266 #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
267 #endif
268 #define AF_COIP 20 /* connection-oriented IP, aka ST II */
269 #define AF_CNT 21 /* Computer Network Technology */
270 #if defined(_NETBSD_SOURCE)
271 #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
272 #endif
273 #define AF_IPX 23 /* Novell Internet Protocol */
274 #define AF_INET6 24 /* IP version 6 */
275 #if defined(_NETBSD_SOURCE)
276 #define pseudo_AF_PIP 25 /* Help Identify PIP packets */
277 #endif
278 #define AF_ISDN 26 /* Integrated Services Digital Network*/
279 #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
280 #define AF_NATM 27 /* native ATM access */
281 #define AF_ARP 28 /* (rev.) addr. res. prot. (RFC 826) */
282 #if defined(_NETBSD_SOURCE)
283 #define pseudo_AF_KEY 29 /* Internal key management protocol */
284 #define pseudo_AF_HDRCMPLT 30 /* Used by BPF to not rewrite hdrs
285  in interface output routine */
286 #endif
287 #define AF_BLUETOOTH 31 /* Bluetooth: HCI, SCO, L2CAP, RFCOMM */
288 #define AF_IEEE80211 32 /* IEEE80211 */
289 #define AF_MPLS 33 /* MultiProtocol Label Switching */
290 #define AF_ROUTE 34 /* Internal Routing Protocol */
291 #define AF_CAN 35
292 #define AF_ETHER 36
293 #define AF_MAX 37
294 
295 /*
296  * Structure used by kernel to store most
297  * addresses.
298  */
299 struct sockaddr {
300  __uint8_t sa_len; /* total length */
301  sa_family_t sa_family; /* address family */
302  char sa_data[14]; /* actually longer; address value */
303 };
304 
305 #if defined(_KERNEL)
306 /*
307  * Structure used by kernel to pass protocol
308  * information in raw sockets.
309  */
310 struct sockproto {
311  u_short sp_family; /* address family */
312  u_short sp_protocol; /* protocol */
313 };
314 
315 /*
316  * we make the entire struct at least UCHAR_MAX + 1 in size since existing
317  * use of sockaddr_un permits a path up to 253 bytes + '\0'.
318  * sizeof(sb_len) + sizeof(sb_family) + 253 + '\0'
319  */
320 #define _SB_DATASIZE 254
321 struct sockaddr_big {
322  union {
323  struct {
324  __uint8_t sb_len;
325  sa_family_t sb_family;
326  char sb_data[_SB_DATASIZE];
327  };
328  uint64_t dummy; /* solicit natural alignment */
329  };
330 };
331 
332 #endif /* _KERNEL */
333 
334 /*
335  * RFC 2553: protocol-independent placeholder for socket addresses
336  */
337 #define _SS_MAXSIZE 128
338 #define _SS_ALIGNSIZE (sizeof(__int64_t))
339 #define _SS_PAD1SIZE (_SS_ALIGNSIZE - 2)
340 #define _SS_PAD2SIZE (_SS_MAXSIZE - 2 - _SS_PAD1SIZE - _SS_ALIGNSIZE)
341 
342 struct sockaddr_storage {
343  __uint8_t ss_len; /* address length */
344  sa_family_t ss_family; /* address family */
345  char __ss_pad1[_SS_PAD1SIZE];
346  __int64_t __ss_align;/* force desired structure storage alignment */
347  char __ss_pad2[_SS_PAD2SIZE];
348 };
349 
350 #if defined(_NETBSD_SOURCE)
351 #define sstosa(__ss) ((struct sockaddr *)(__ss))
352 #define sstocsa(__ss) ((const struct sockaddr *)(__ss))
353 #endif /* _NETBSD_SOURCE */
354 
355 /*
356  * Protocol families, same as address families for now.
357  */
358 #define PF_UNSPEC AF_UNSPEC
359 #define PF_LOCAL AF_LOCAL
360 #define PF_UNIX PF_LOCAL /* backward compatibility */
361 #define PF_INET AF_INET
362 #define PF_IMPLINK AF_IMPLINK
363 #define PF_PUP AF_PUP
364 #define PF_CHAOS AF_CHAOS
365 #define PF_NS AF_NS
366 #define PF_ISO AF_ISO
367 #define PF_OSI AF_ISO
368 #define PF_ECMA AF_ECMA
369 #define PF_DATAKIT AF_DATAKIT
370 #define PF_CCITT AF_CCITT
371 #define PF_SNA AF_SNA
372 #define PF_DECnet AF_DECnet
373 #define PF_DLI AF_DLI
374 #define PF_LAT AF_LAT
375 #define PF_HYLINK AF_HYLINK
376 #define PF_APPLETALK AF_APPLETALK
377 #define PF_OROUTE AF_OROUTE
378 #define PF_LINK AF_LINK
379 #if defined(_NETBSD_SOURCE)
380 #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
381 #endif
382 #define PF_COIP AF_COIP
383 #define PF_CNT AF_CNT
384 #define PF_INET6 AF_INET6
385 #define PF_IPX AF_IPX /* same format as AF_NS */
386 #if defined(_NETBSD_SOURCE)
387 #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
388 #define PF_PIP pseudo_AF_PIP
389 #endif
390 #define PF_ISDN AF_ISDN /* same as E164 */
391 #define PF_E164 AF_E164
392 #define PF_NATM AF_NATM
393 #define PF_ARP AF_ARP
394 #if defined(_NETBSD_SOURCE)
395 #define PF_KEY pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */
396 #endif
397 #define PF_BLUETOOTH AF_BLUETOOTH
398 #define PF_MPLS AF_MPLS
399 #define PF_ROUTE AF_ROUTE
400 #define PF_CAN AF_CAN
401 #define PF_ETHER AF_ETHER
402 
403 #define PF_MAX AF_MAX
404 
405 #if defined(_NETBSD_SOURCE)
406 
407 #ifndef pid_t
408 typedef __pid_t pid_t; /* process id */
409 #define pid_t __pid_t
410 #endif
411 
412 #ifndef gid_t
413 typedef __gid_t gid_t; /* group id */
414 #define gid_t __gid_t
415 #endif
416 
417 #ifndef uid_t
418 typedef __uid_t uid_t; /* user id */
419 #define uid_t __uid_t
420 #endif
421 
422 /*
423  * Socket credentials.
424  */
425 struct sockcred {
426  pid_t sc_pid; /* process id */
427  uid_t sc_uid; /* real user id */
428  uid_t sc_euid; /* effective user id */
429  gid_t sc_gid; /* real group id */
430  gid_t sc_egid; /* effective group id */
431  int sc_ngroups; /* number of supplemental groups */
432  gid_t sc_groups[1]; /* variable length */
433 };
434 
435 /*
436  * Compute size of a sockcred structure with groups.
437  *
438  * The (ngrps - 1) is to account for struct sockcred being defined with
439  * already one group member. This code works correctly when ngroups == 0
440  * because of unsigned arithmetic wrap-around.
441  */
442 #define SOCKCREDSIZE(ngrps) \
443  (/*LINTED*/sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
444 #endif /* _NETBSD_SOURCE */
445 
446 
447 #if defined(_NETBSD_SOURCE)
448 /* Definition for CTL_NET PCB fetching sysctls */
449 struct kinfo_pcb {
450  __uint64_t ki_pcbaddr; /* PTR: pcb addr */
451  __uint64_t ki_ppcbaddr; /* PTR: ppcb addr */
452  __uint64_t ki_sockaddr; /* PTR: socket addr */
453 
454  __uint32_t ki_family; /* INT: protocol family */
455  __uint32_t ki_type; /* INT: socket type */
456  __uint32_t ki_protocol; /* INT: protocol */
457  __uint32_t ki_pflags; /* INT: generic protocol flags */
458 
459  __uint32_t ki_sostate; /* INT: socket state */
460  __uint32_t ki_prstate; /* INT: protocol state */
461  __int32_t ki_tstate; /* INT: tcp state */
462  __uint32_t ki_tflags; /* INT: tcp flags */
463 
464  __uint64_t ki_rcvq; /* U_LONG: receive queue len */
465  __uint64_t ki_sndq; /* U_LONG: send queue len */
466 
467  union {
468  struct sockaddr _kis_src; /* STRUCT: local address */
469  char _kis_pad[256 + 8]; /* pad to max addr length */
470  } ki_s;
471  union {
472  struct sockaddr _kid_dst; /* STRUCT: remote address */
473  char _kid_pad[256 + 8]; /* pad to max addr length */
474  } ki_d;
475 
476  __uint64_t ki_inode; /* INO_T: fake inode number */
477  __uint64_t ki_vnode; /* PTR: if associated with file */
478  __uint64_t ki_conn; /* PTR: control block of peer */
479  __uint64_t ki_refs; /* PTR: referencing socket */
480  __uint64_t ki_nextref; /* PTR: link in refs list */
481 };
482 
483 #define ki_src ki_s._kis_src
484 #define ki_dst ki_d._kid_dst
485 #define ki_spad ki_s._kis_pad
486 #define ki_dpad ki_d._kid_pad
487 
488 #define PCB_SLOP 20
489 #define PCB_ALL 0
490 
491 #endif /* _NETBSD_SOURCE */
492 
493 #if defined(_NETBSD_SOURCE)
494 /*
495  * PF_ROUTE - Routing table
496  *
497  * Three additional levels are defined:
498  * Fourth: address family, 0 is wildcard
499  * Fifth: type of info, defined below
500  * Sixth: flag(s) to mask with for NET_RT_FLAGS
501  */
502 #define NET_RT_DUMP 1 /* dump; may limit to a.f. */
503 #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
504 #define NET_RT_OOOIFLIST 3 /* old NET_RT_IFLIST (pre 1.5) */
505 #define NET_RT_OOIFLIST 4 /* old NET_RT_IFLIST (pre-64bit time) */
506 #define NET_RT_OIFLIST 5 /* old NET_RT_IFLIST (pre 8.0) */
507 #define NET_RT_IFLIST 6 /* survey interface list */
508 
509 #endif /* _NETBSD_SOURCE */
510 
511 /*
512  * Maximum queue length specifiable by listen(2).
513  */
514 #ifndef SOMAXCONN
515 #define SOMAXCONN 128
516 #endif
517 
518 #include <sys/cdefs.h>
519 
520 /*
521  * Message header for recvmsg and sendmsg calls.
522  * Used value-result for recvmsg, value only for sendmsg.
523  */
524 struct msghdr {
525  void *msg_name; /* optional address */
526  socklen_t msg_namelen; /* size of address */
527  struct iovec *msg_iov; /* scatter/gather array */
528  int msg_iovlen; /* # elements in msg_iov */
529  void *msg_control; /* ancillary data, see below */
530  socklen_t msg_controllen; /* ancillary data buffer len */
531  int msg_flags; /* flags on received message */
532 };
533 
534 #define MSG_OOB 0x0001 /* process out-of-band data */
535 #define MSG_PEEK 0x0002 /* peek at incoming message */
536 #define MSG_DONTROUTE 0x0004 /* send without using routing tables */
537 #define MSG_EOR 0x0008 /* data completes record */
538 #define MSG_TRUNC 0x0010 /* data discarded before delivery */
539 #define MSG_CTRUNC 0x0020 /* control data lost before delivery */
540 #define MSG_WAITALL 0x0040 /* wait for full request or error */
541 #define MSG_DONTWAIT 0x0080 /* this message should be nonblocking */
542 #define MSG_BCAST 0x0100 /* this message was rcvd using link-level brdcst */
543 #define MSG_MCAST 0x0200 /* this message was rcvd using link-level mcast */
544 #define MSG_NOSIGNAL 0x0400 /* do not generate SIGPIPE on EOF */
545 #if defined(_NETBSD_SOURCE)
546 #define MSG_CMSG_CLOEXEC 0x0800 /* close on exec receiving fd */
547 #define MSG_NBIO 0x1000 /* use non-blocking I/O */
548 #define MSG_WAITFORONE 0x2000 /* recvmmsg() wait for one message */
549 #define MSG_NOTIFICATION 0x4000 /* SCTP notification */
550 
551 struct mmsghdr {
552  struct msghdr msg_hdr;
553  unsigned int msg_len;
554 };
555 #endif
556 
557 /* Extra flags used internally only */
558 #define MSG_USERFLAGS 0x0ffffff
559 #define MSG_NAMEMBUF 0x1000000 /* msg_name is an mbuf */
560 #define MSG_CONTROLMBUF 0x2000000 /* msg_control is an mbuf */
561 #define MSG_IOVUSRSPACE 0x4000000 /* msg_iov is in user space */
562 #define MSG_LENUSRSPACE 0x8000000 /* address length is in user space */
563 
564 /*
565  * Header for ancillary data objects in msg_control buffer.
566  * Used for additional information with/about a datagram
567  * not expressible by flags. The format is a sequence
568  * of message elements headed by cmsghdr structures.
569  */
570 struct cmsghdr {
571  socklen_t cmsg_len; /* data byte count, including hdr */
572  int cmsg_level; /* originating protocol */
573  int cmsg_type; /* protocol-specific type */
574 /* followed by u_char cmsg_data[]; */
575 };
576 
577 /*
578  * Alignment requirement for CMSG struct manipulation.
579  * This basically behaves the same as ALIGN() ARCH/include/param.h.
580  * We declare it separately for two reasons:
581  * (1) avoid dependency between machine/param.h, and (2) to sync with kernel's
582  * idea of ALIGNBYTES at runtime.
583  * without (2), we can't guarantee binary compatibility in case of future
584  * changes in ALIGNBYTES.
585  */
586 #define __CMSG_ALIGN(n) (((n) + __ALIGNBYTES) & ~__ALIGNBYTES)
587 
588 #ifdef _KERNEL
589 #define CMSG_ALIGN(n) __CMSG_ALIGN(n)
590 #endif
591 
592 #define __CMSG_ASIZE __CMSG_ALIGN(sizeof(struct cmsghdr))
593 #define __CMSG_MSGNEXT(cmsg) \
594  (__CASTV(char *, cmsg) + __CMSG_ALIGN((cmsg)->cmsg_len))
595 #define __CMSG_MSGEND(mhdr) \
596  (__CASTV(char *, (mhdr)->msg_control) + (mhdr)->msg_controllen)
597 
598 /* given pointer to struct cmsghdr, return pointer to data */
599 #define CMSG_DATA(cmsg) (__CASTV(u_char *, cmsg) + __CMSG_ASIZE)
600 #define CCMSG_DATA(cmsg) (__CASTCV(const u_char *, cmsg) + __CMSG_ASIZE)
601 
602 /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
603 #define CMSG_NXTHDR(mhdr, cmsg) \
604  __CASTV(struct cmsghdr *, \
605  __CMSG_MSGNEXT(cmsg) + __CMSG_ASIZE > __CMSG_MSGEND(mhdr) ? 0 : \
606  __CMSG_MSGNEXT(cmsg))
607 
608 /*
609  * RFC 2292 requires to check msg_controllen, in case that the kernel returns
610  * an empty list for some reasons.
611  */
612 #define CMSG_FIRSTHDR(mhdr) \
613  __CASTV(struct cmsghdr *, \
614  (mhdr)->msg_controllen < sizeof(struct cmsghdr) ? 0 : \
615  (mhdr)->msg_control)
616 
617 #define CMSG_SPACE(l) (__CMSG_ASIZE + __CMSG_ALIGN(l))
618 #define CMSG_LEN(l) (__CMSG_ASIZE + (l))
619 
620 /* "Socket"-level control message types: */
621 #define SCM_RIGHTS 0x01 /* access rights (array of int) */
622 #if defined(_NETBSD_SOURCE)
623 /* 0x02 timestamp (struct timeval50) */
624 /* 0x04 credentials (struct sockcred70) */
625 #define SCM_TIMESTAMP 0x08 /* timestamp (struct timeval) */
626 #define SCM_CREDS 0x10 /* credentials (struct sockcred) */
627 #endif
628 
629 /*
630  * Types of socket shutdown(2).
631  */
632 #define SHUT_RD 0 /* Disallow further receives. */
633 #define SHUT_WR 1 /* Disallow further sends. */
634 #define SHUT_RDWR 2 /* Disallow further sends/receives. */
635 
636 #ifdef _KERNEL
637 static __inline socklen_t
638 sockaddr_getlen(const struct sockaddr *sa)
639 {
640  return sa->sa_len;
641 }
642 
643 __BEGIN_DECLS
644 socklen_t sockaddr_getsize_by_family(sa_family_t);
645 struct sockaddr *sockaddr_copy(struct sockaddr *, socklen_t,
646  const struct sockaddr *);
647 struct sockaddr *sockaddr_externalize(struct sockaddr *, socklen_t,
648  const struct sockaddr *);
649 struct sockaddr *sockaddr_alloc(sa_family_t, socklen_t, int);
650 const void *sockaddr_const_addr(const struct sockaddr *, socklen_t *);
651 void *sockaddr_addr(struct sockaddr *, socklen_t *);
652 const struct sockaddr *sockaddr_any(const struct sockaddr *);
653 const struct sockaddr *sockaddr_any_by_family(sa_family_t);
654 const void *sockaddr_anyaddr(const struct sockaddr *, socklen_t *);
655 int sockaddr_cmp(const struct sockaddr *, const struct sockaddr *);
656 struct sockaddr *sockaddr_dup(const struct sockaddr *, int);
657 int sockaddr_format(const struct sockaddr *, char *, size_t);
658 void sockaddr_free(struct sockaddr *);
659 __END_DECLS
660 #endif /* _KERNEL */
661 #endif
662 
663 #ifndef _KERNEL
664 
665 __BEGIN_DECLS
666 extern int accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
667 #if 0
668 extern int accept4(int, struct sockaddr * __restrict, socklen_t * __restrict, int);
669 #endif
670 extern int bind(int, const struct sockaddr *, socklen_t);
671 extern int connect(int, const struct sockaddr *, socklen_t);
672 extern int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
673 extern int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
674 extern int getsockopt(int, int, int, void *__restrict, socklen_t * __restrict);
675 #if 0
676 extern int getsockopt2(int, int, int, void *__restrict, socklen_t * __restrict);
677 #endif
678 extern int listen(int, int);
679 #if 0
680 extern int paccept(int, struct sockaddr * __restrict, socklen_t * __restrict,
681  const sigset_t * __restrict, int);
682 #endif
683 extern ssize_t recv(int, void *, size_t, int);
684 extern ssize_t recvfrom(int, void *__restrict, size_t, int,
685  struct sockaddr * __restrict, socklen_t * __restrict);
686 extern ssize_t recvmsg(int, struct msghdr *, int);
687 extern ssize_t send(int, const void *, size_t, int);
688 extern ssize_t sendto(int, const void *,
689  size_t, int, const struct sockaddr *, socklen_t);
690 extern ssize_t sendmsg(int, const struct msghdr *, int);
691 extern int setsockopt(int, int, int, const void *, socklen_t);
692 extern int shutdown(int, int);
693 #if 0
694 extern int sockatmark(int);
695 #endif
696 extern int socket(int, int, int)
697 #if 0
698 #if !defined(__LIBC12_SOURCE__) && !defined(_STANDALONE)
699 __RENAME(__socket30)
700 #endif
701 #endif
702  ;
703 #if 0
704 extern int socketpair(int, int, int, int *);
705 #endif
706 
707 #if 0
708 #if defined(_NETBSD_SOURCE)
709 extern int sendmmsg(int, struct mmsghdr *, unsigned int, unsigned int);
710 struct timespec;
711 extern int recvmmsg(int, struct mmsghdr *, unsigned int, unsigned int,
712  struct timespec *);
713 #endif
714 #endif
715 #if 1
716 extern int libcglue_ps2ip_setconfig(t_ip_info *ip_info);
717 extern int libcglue_ps2ip_getconfig(char *netif_name, t_ip_info *ip_info);
718 extern void libcglue_dns_setserver(u8 numdns, ip_addr_t *dnsserver);
719 extern const ip_addr_t *libcglue_dns_getserver(u8 numdns);
720 #endif
721 __END_DECLS
722 
723 #ifndef LIBCGLUE_SYS_SOCKET_ALIASES
724 #define LIBCGLUE_SYS_SOCKET_ALIASES 0
725 #endif
726 
727 #if LIBCGLUE_SYS_SOCKET_ALIASES
728 #define closesocket(...) close(__VA_ARGS__)
729 #define readsocket(...) read(__VA_ARGS__)
730 #define writesocket(...) write(__VA_ARGS__)
731 #define ioctlsocket(...) ioctl(__VA_ARGS__)
732 #define fcntlsocket(...) fcntl(__VA_ARGS__)
733 #define lwip_accept(...) accept(__VA_ARGS__)
734 #define lwip_bind(...) bind(__VA_ARGS__)
735 #define lwip_shutdown(...) shutdown(__VA_ARGS__)
736 #define lwip_getpeername(...) getpeername(__VA_ARGS__)
737 #define lwip_getsockname(...) getsockname(__VA_ARGS__)
738 #define lwip_getsockopt(...) getsockopt(__VA_ARGS__)
739 #define lwip_setsockopt(...) setsockopt(__VA_ARGS__)
740 #define lwip_close(...) close(__VA_ARGS__)
741 #define lwip_connect(...) connect(__VA_ARGS__)
742 #define lwip_listen(...) listen(__VA_ARGS__)
743 #define lwip_recv(...) recv(__VA_ARGS__)
744 #define lwip_read(...) read(__VA_ARGS__)
745 #define lwip_recvfrom(...) recvfrom(__VA_ARGS__)
746 #define lwip_send(...) send(__VA_ARGS__)
747 #define lwip_sendto(...) sendto(__VA_ARGS__)
748 #define lwip_socket(...) socket(__VA_ARGS__)
749 #define lwip_write(...) write(__VA_ARGS__)
750 #define lwip_select(...) select(__VA_ARGS__)
751 #define lwip_ioctl(...) ioctl(__VA_ARGS__)
752 #define lwip_fcntl(...) fcntl(__VA_ARGS__)
753 #define disconnect(...) close(__VA_ARGS__)
754 #define ps2ip_setconfig(...) libcglue_ps2ip_setconfig(__VA_ARGS__)
755 #define ps2ip_getconfig(...) libcglue_ps2ip_getconfig(__VA_ARGS__)
756 #define dns_setserver(...) libcglue_dns_setserver(__VA_ARGS__)
757 #define dns_getserver(...) libcglue_dns_getserver(__VA_ARGS__)
758 #endif
759 
760 #endif /* !_KERNEL */
761 
762 #endif /* !_SYS_SOCKET_H_ */
tcpip.h
sockaddr_storage
Definition: tcpip.h:1569
t_ip_info
Definition: tcpip.h:1990
msghdr
Definition: socket.h:96
ip4_addr
Definition: tcpip.h:266
iovec
Definition: uio.h:24
sockaddr
Definition: tcpip.h:1562