sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
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
77#ifndef _SYS_SOCKET_H_
78#define _SYS_SOCKET_H_
79
80#if 1
81#include <stdint.h>
82#include <stddef.h>
83#include <sys/types.h>
84#include <sys/cdefs.h>
85#include <unistd.h>
86#include <sys/uio.h>
87#include <tamtypes.h>
88
89/* Used to be a blanket #include <tcpip.h> - that header is ps2sdk's
90 * own pre-lwip-migration "Common definitions file for the LWIP v2.0.0
91 * port" (see common/include/tcpip.h's own file comment), a whole
92 * parallel, now-superseded copy of lwip's own types/macros. It
93 * conflicts outright with the real lwip headers ps2ip actually builds
94 * against today (confirmed for real: PBUF_TRANSPORT/PBUF_IP/
95 * pbuf_layer/etc redeclaration errors) - and its own socklen_t is
96 * `int`, while real lwip's is `u32_t`, a real ABI mismatch that broke
97 * ps2ip_ps2sdk.c's fdman callback wiring the moment ps2ip's own
98 * headers ever got fixed enough to expose the real lwip chain (see
99 * ps2ip.h's own commit history). Replaced with real, minimal
100 * equivalents for exactly what this file itself uses below - not
101 * everything tcpip.h ever offered, only what's load-bearing here.
102 *
103 * socklen_t: matches real lwip's own `u32_t socklen_t` exactly (u32 on
104 * this platform IS the same real type lwip's u32_t resolves to), using
105 * lwip's own SOCKLEN_T_DEFINED convention so a TU that also reaches
106 * lwip/sockets.h later doesn't get a conflicting second typedef. */
107#ifndef SOCKLEN_T_DEFINED
108#define SOCKLEN_T_DEFINED
109typedef u32 socklen_t;
110#endif
111
112/* struct in_addr: real, full definition (t_ip_info below embeds it by
113 * value, so a forward declaration isn't enough here) - guarded on
114 * lwip/inet.h's own real include guard (LWIP_HDR_INET_H) so a TU that
115 * also reaches that header later doesn't get a real redefinition
116 * error; lwip's own struct in_addr has no guard of its own to reuse
117 * the other direction. */
118#ifndef LWIP_HDR_INET_H
119struct in_addr {
120 u32 s_addr;
121};
122#endif
123
124/* ip4_addr_t/ip_addr_t: forward-declared only (every real use below is
125 * a pointer, never dereferenced here) - safe because lwip's own real
126 * `struct ip4_addr { ... }; typedef struct ip4_addr ip4_addr_t;`
127 * (lwip/ip4_addr.h) uses that same real tag name, so this and lwip's
128 * own full definition are compatible re-declarations of the same
129 * struct if both appear in one TU, not two conflicting types. ip_addr_t
130 * itself is a plain alias for ip4_addr_t in lwip's real build config
131 * here (LWIP_IPV6 off, this project's actual default - see
132 * ps2ip/include/lwipopts.h) - true only because IPv6 is off; if that
133 * ever changes, ip_addr_t becomes its own real struct/union upstream
134 * and this alias would need revisiting. */
135#ifndef LWIP_HDR_IP4_ADDR_H
136struct ip4_addr;
137typedef struct ip4_addr ip4_addr_t;
138typedef struct ip4_addr ip_addr_t;
139#endif
140
141/* t_ip_info: real struct, real layout, matches (superseded) tcpip.h's
142 * own definition exactly. Real, direct consumers of THIS header
143 * (core/ps2ips/src/ps2ipc.c, via ps2ips.h) need it from here - they
144 * don't include ps2sdkapi.h at all. ps2sdkapi.h needs it too, and
145 * provides its own independent copy (for TUs where <sys/socket.h>
146 * resolves to lwip's own real sockets.h instead of this file - see
147 * ps2sdkapi.h's own comment) - shared guard so whichever of the two
148 * is reached first in a given TU wins and the other is skipped. */
149#ifndef T_IP_INFO_DEFINED
150#define T_IP_INFO_DEFINED
151typedef struct
152{
153 char netif_name[4];
154 struct in_addr ipaddr;
155 struct in_addr netmask;
156 struct in_addr gw;
157 u32 dhcp_enabled;
158 u32 dhcp_status;
159 u8 hw_addr[8];
160} t_ip_info;
161#endif
162
163/* ioctlsocket()/fcntl() command constants: real, wire-protocol-exact
164 * values (ps2ipc_ioctl's `cmd` argument gets RPC'd to the IOP verbatim
165 * and interpreted there by lwip's own real lwip_ioctl(), which only
166 * understands FIONREAD/FIONBIO) - byte-identical to both (superseded)
167 * tcpip.h's own copy and lwip/sockets.h's own real definitions
168 * (core/ps2ip/include/lwip_include/lwip/sockets.h), guarded the same
169 * way lwip guards them so whichever is reached first in a given TU
170 * wins and neither redefines the other. */
171#if !defined(FIONREAD) || !defined(FIONBIO)
172#ifndef IOCPARM_MASK
173#define IOCPARM_MASK 0x7fUL
174#define IOC_VOID 0x20000000UL
175#define IOC_OUT 0x40000000UL
176#define IOC_IN 0x80000000UL
177#define IOC_INOUT (IOC_IN | IOC_OUT)
178#define _IO(x, y) ((long)(IOC_VOID | ((x) << 8) | (y)))
179#define _IOR(x, y, t) ((long)(IOC_OUT | ((sizeof(t) & IOCPARM_MASK) << 16) | ((x) << 8) | (y)))
180#define _IOW(x, y, t) ((long)(IOC_IN | ((sizeof(t) & IOCPARM_MASK) << 16) | ((x) << 8) | (y)))
181#endif
182#endif
183#ifndef FIONREAD
184#define FIONREAD _IOR('f', 127, unsigned long)
185#endif
186#ifndef FIONBIO
187#define FIONBIO _IOW('f', 126, unsigned long)
188#endif
189
190#ifndef F_GETFL
191#define F_GETFL 3
192#endif
193#ifndef F_SETFL
194#define F_SETFL 4
195#endif
196
197#ifndef O_NONBLOCK
198#define O_NONBLOCK 1
199#endif
200#ifndef O_NDELAY
201#define O_NDELAY O_NONBLOCK
202#endif
203
204/* sa_family_t/struct sockaddr: real, active definitions - the
205 * disabled `#if 0` block further down (originally real NetBSD source,
206 * gated behind #include <sys/ansi.h>/<sys/featuretest.h>, neither of
207 * which exist in this tree) used to be dead code even before the
208 * (superseded) blanket `#include <tcpip.h>` removal - tcpip.h's own
209 * hand-copied sa_family_t/struct sockaddr (byte-identical to the
210 * disabled block below and to real lwip/sockets.h's SA_FAMILY_T_DEFINED
211 * convention) was the only ACTIVE source for these before. Real
212 * consumers embedding `struct sockaddr` by value (not just by pointer)
213 * need the complete type, not just the forward reference further down
214 * in this file - e.g. common/include/ps2ip_rpc.h's RPC packet structs. */
215#ifndef SA_FAMILY_T_DEFINED
216#define SA_FAMILY_T_DEFINED
217typedef u8 sa_family_t;
218#endif
219
220#ifndef _SOCKADDR_STRUCT_DEFINED
221#define _SOCKADDR_STRUCT_DEFINED
222struct sockaddr {
223 u8 sa_len; /* total length */
224 sa_family_t sa_family; /* address family */
225 char sa_data[14]; /* actually longer; address value */
226};
227#endif
228
229/* Socket types, common address families, and SOL_SOCKET/common SO_*
230 * option constants: same real, disabled-`#if 0`-block story as
231 * sa_family_t/struct sockaddr above - real, byte-identical values,
232 * just never given an active home. A deliberately trimmed subset (not
233 * the whole exotic BSD AF_* list - AF_APPLETALK/AF_ISDN/AF_BLUETOOTH
234 * and friends have no real use on this platform) rather than fully
235 * reviving the disabled block, which itself depends on real, missing
236 * headers (<sys/featuretest.h>, <sys/ansi.h>, <machine/ansi.h>) and
237 * would cascade into more errors than it fixes. Found for real
238 * building ps2_drivers's select_test_ee sample ("AF_INET undeclared"). */
239#ifndef SOCK_STREAM
240#define SOCK_STREAM 1
241#define SOCK_DGRAM 2
242#define SOCK_RAW 3
243#define SOCK_RDM 4
244#define SOCK_SEQPACKET 5
245#endif
246
247#ifndef AF_UNSPEC
248#define AF_UNSPEC 0
249#define AF_LOCAL 1
250#define AF_UNIX AF_LOCAL
251#define AF_INET 2
252#define AF_INET6 24
253#define AF_ROUTE 34
254#define AF_MAX 37
255#endif
256#ifndef PF_UNSPEC
257#define PF_UNSPEC AF_UNSPEC
258#define PF_LOCAL AF_LOCAL
259#define PF_UNIX PF_LOCAL
260#define PF_INET AF_INET
261#define PF_INET6 AF_INET6
262#define PF_ROUTE AF_ROUTE
263#define PF_MAX AF_MAX
264#endif
265
266#ifndef SOL_SOCKET
267#define SOL_SOCKET 0xffff
268#endif
269#ifndef SO_DEBUG
270#define SO_DEBUG 0x0001
271#define SO_ACCEPTCONN 0x0002
272#define SO_REUSEADDR 0x0004
273#define SO_KEEPALIVE 0x0008
274#define SO_DONTROUTE 0x0010
275#define SO_BROADCAST 0x0020
276#define SO_USELOOPBACK 0x0040
277#define SO_LINGER 0x0080
278#define SO_OOBINLINE 0x0100
279#define SO_REUSEPORT 0x0200
280#endif
281#ifndef SO_SNDBUF
282#define SO_SNDBUF 0x1001
283#define SO_RCVBUF 0x1002
284#define SO_SNDLOWAT 0x1003
285#define SO_RCVLOWAT 0x1004
286#define SO_ERROR 0x1007
287#define SO_TYPE 0x1008
288#define SO_SNDTIMEO 0x100b
289#define SO_RCVTIMEO 0x100c
290#endif
291
292#ifndef _LINGER_STRUCT_DEFINED
293#define _LINGER_STRUCT_DEFINED
294struct linger {
295 int l_onoff; /* option on/off */
296 int l_linger; /* linger time in seconds */
297};
298#endif
299#endif
300
301/*
302 * Maximum queue length specifiable by listen(2).
303 */
304#ifndef SOMAXCONN
305#define SOMAXCONN 128
306#endif
307
308/*
309 * Message header for recvmsg and sendmsg calls.
310 * Used value-result for recvmsg, value only for sendmsg.
311 */
312struct msghdr {
313 void *msg_name; /* optional address */
314 socklen_t msg_namelen; /* size of address */
315 struct iovec *msg_iov; /* scatter/gather array */
316 int msg_iovlen; /* # elements in msg_iov */
317 void *msg_control; /* ancillary data, see below */
318 socklen_t msg_controllen; /* ancillary data buffer len */
319 int msg_flags; /* flags on received message */
320};
321
322// TODO: Not available in LWIP
323#define MSG_TRUNC 0x0000 /* data discarded before delivery */
324
325#if 0
326#include <sys/featuretest.h>
327
328/*
329 * Definitions related to sockets: types, address families, options.
330 */
331
332/*
333 * Data types.
334 */
335#include <sys/ansi.h>
336
337#ifndef sa_family_t
338typedef __sa_family_t sa_family_t;
339#define sa_family_t __sa_family_t
340#endif
341
342#ifndef socklen_t
343typedef __socklen_t socklen_t;
344#define socklen_t __socklen_t
345#endif
346
347#include <machine/ansi.h>
348
349#ifdef _BSD_SIZE_T_
350typedef _BSD_SIZE_T_ size_t;
351#undef _BSD_SIZE_T_
352#endif
353
354#ifdef _BSD_SSIZE_T_
355typedef _BSD_SSIZE_T_ ssize_t;
356#undef _BSD_SSIZE_T_
357#endif
358
359#include <sys/uio.h>
360#include <sys/sigtypes.h>
361
362/*
363 * Socket types.
364 */
365#define SOCK_STREAM 1 /* stream socket */
366#define SOCK_DGRAM 2 /* datagram socket */
367#define SOCK_RAW 3 /* raw-protocol interface */
368#define SOCK_RDM 4 /* reliably-delivered message */
369#define SOCK_SEQPACKET 5 /* sequenced packet stream */
370#define SOCK_CONN_DGRAM 6 /* connection-orientated datagram */
371#define SOCK_DCCP SOCK_CONN_DGRAM
372
373#define SOCK_CLOEXEC 0x10000000 /* set close on exec on socket */
374#define SOCK_NONBLOCK 0x20000000 /* set non blocking i/o socket */
375#define SOCK_NOSIGPIPE 0x40000000 /* don't send sigpipe */
376#define SOCK_FLAGS_MASK 0xf0000000 /* flags mask */
377
378/*
379 * Option flags per-socket.
380 */
381#define SO_DEBUG 0x0001 /* turn on debugging info recording */
382#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
383#define SO_REUSEADDR 0x0004 /* allow local address reuse */
384#define SO_KEEPALIVE 0x0008 /* keep connections alive */
385#define SO_DONTROUTE 0x0010 /* just use interface addresses */
386#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
387#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
388#define SO_LINGER 0x0080 /* linger on close if data present */
389#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
390#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
391/* SO_OTIMESTAMP 0x0400 */
392#define SO_NOSIGPIPE 0x0800 /* no SIGPIPE from EPIPE */
393#define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
394#define SO_TIMESTAMP 0x2000 /* timestamp received dgram traffic */
395#define SO_RERROR 0x4000 /* Keep track of receive errors */
396
397/* Allowed default option flags */
398#define SO_DEFOPTS (SO_DEBUG|SO_REUSEADDR|SO_KEEPALIVE|SO_DONTROUTE| \
399 SO_BROADCAST|SO_USELOOPBACK|SO_LINGER|SO_OOBINLINE|SO_REUSEPORT| \
400 SO_NOSIGPIPE|SO_TIMESTAMP|SO_RERROR)
401
402#define __SO_OPTION_BITS \
403 "\20" \
404 "\1SO_DEBUG" \
405 "\2SO_ACCEPTCONN" \
406 "\3SO_REUSEADDR" \
407 "\4SO_KEEPALIVE" \
408 "\5SO_DONTROUTE" \
409 "\6SO_BROADCAST" \
410 "\7SO_USELOOPBACK" \
411 "\10SO_LINGER" \
412 "\11SO_OOBINLINE" \
413 "\12SO_REUSEPORT" \
414 "\13SO_OTIMESTAMP" \
415 "\14SO_NOSIGPIPE" \
416 "\15SO_ACCEPTFILTER" \
417 "\16SO_TIMESTAMP" \
418 "\17SO_RERROR"
419
420/*
421 * Additional options, not kept in so_options.
422 */
423#define SO_SNDBUF 0x1001 /* send buffer size */
424#define SO_RCVBUF 0x1002 /* receive buffer size */
425#define SO_SNDLOWAT 0x1003 /* send low-water mark */
426#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
427/* SO_OSNDTIMEO 0x1005 */
428/* SO_ORCVTIMEO 0x1006 */
429#define SO_ERROR 0x1007 /* get error status and clear */
430#define SO_TYPE 0x1008 /* get socket type */
431#define SO_OVERFLOWED 0x1009 /* datagrams: return packets dropped */
432
433#define SO_NOHEADER 0x100a /* user supplies no header to kernel;
434 * kernel removes header and supplies
435 * payload
436 */
437#define SO_SNDTIMEO 0x100b /* send timeout */
438#define SO_RCVTIMEO 0x100c /* receive timeout */
439/*
440 * Structure used for manipulating linger option.
441 */
442struct linger {
443 int l_onoff; /* option on/off */
444 int l_linger; /* linger time in seconds */
445};
446
447struct accept_filter_arg {
448 char af_name[16];
449 char af_arg[256-16];
450};
451
452/*
453 * Level number for (get/set)sockopt() to apply to socket itself.
454 */
455#define SOL_SOCKET 0xffff /* options for socket level */
456
457/*
458 * Address families.
459 */
460#define AF_UNSPEC 0 /* unspecified */
461#define AF_LOCAL 1 /* local to host */
462#define AF_UNIX AF_LOCAL /* backward compatibility */
463#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
464#define AF_IMPLINK 3 /* arpanet imp addresses */
465#define AF_PUP 4 /* pup protocols: e.g. BSP */
466#define AF_CHAOS 5 /* mit CHAOS protocols */
467#define AF_NS 6 /* XEROX NS protocols */
468#define AF_ISO 7 /* ISO protocols */
469#define AF_OSI AF_ISO
470#define AF_ECMA 8 /* european computer manufacturers */
471#define AF_DATAKIT 9 /* datakit protocols */
472#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
473#define AF_SNA 11 /* IBM SNA */
474#define AF_DECnet 12 /* DECnet */
475#define AF_DLI 13 /* DEC Direct data link interface */
476#define AF_LAT 14 /* LAT */
477#define AF_HYLINK 15 /* NSC Hyperchannel */
478#define AF_APPLETALK 16 /* Apple Talk */
479#define AF_OROUTE 17 /* Internal Routing Protocol */
480#define AF_LINK 18 /* Link layer interface */
481#if defined(_NETBSD_SOURCE)
482#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
483#endif
484#define AF_COIP 20 /* connection-oriented IP, aka ST II */
485#define AF_CNT 21 /* Computer Network Technology */
486#if defined(_NETBSD_SOURCE)
487#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
488#endif
489#define AF_IPX 23 /* Novell Internet Protocol */
490#define AF_INET6 24 /* IP version 6 */
491#if defined(_NETBSD_SOURCE)
492#define pseudo_AF_PIP 25 /* Help Identify PIP packets */
493#endif
494#define AF_ISDN 26 /* Integrated Services Digital Network*/
495#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
496#define AF_NATM 27 /* native ATM access */
497#define AF_ARP 28 /* (rev.) addr. res. prot. (RFC 826) */
498#if defined(_NETBSD_SOURCE)
499#define pseudo_AF_KEY 29 /* Internal key management protocol */
500#define pseudo_AF_HDRCMPLT 30 /* Used by BPF to not rewrite hdrs
501 in interface output routine */
502#endif
503#define AF_BLUETOOTH 31 /* Bluetooth: HCI, SCO, L2CAP, RFCOMM */
504#define AF_IEEE80211 32 /* IEEE80211 */
505#define AF_MPLS 33 /* MultiProtocol Label Switching */
506#define AF_ROUTE 34 /* Internal Routing Protocol */
507#define AF_CAN 35
508#define AF_ETHER 36
509#define AF_MAX 37
510
511/*
512 * Structure used by kernel to store most
513 * addresses.
514 */
515struct sockaddr {
516 __uint8_t sa_len; /* total length */
517 sa_family_t sa_family; /* address family */
518 char sa_data[14]; /* actually longer; address value */
519};
520
521#if defined(_KERNEL)
522/*
523 * Structure used by kernel to pass protocol
524 * information in raw sockets.
525 */
526struct sockproto {
527 u_short sp_family; /* address family */
528 u_short sp_protocol; /* protocol */
529};
530
531/*
532 * we make the entire struct at least UCHAR_MAX + 1 in size since existing
533 * use of sockaddr_un permits a path up to 253 bytes + '\0'.
534 * sizeof(sb_len) + sizeof(sb_family) + 253 + '\0'
535 */
536#define _SB_DATASIZE 254
537struct sockaddr_big {
538 union {
539 struct {
540 __uint8_t sb_len;
541 sa_family_t sb_family;
542 char sb_data[_SB_DATASIZE];
543 };
544 uint64_t dummy; /* solicit natural alignment */
545 };
546};
547
548#endif /* _KERNEL */
549
550/*
551 * RFC 2553: protocol-independent placeholder for socket addresses
552 */
553#define _SS_MAXSIZE 128
554#define _SS_ALIGNSIZE (sizeof(__int64_t))
555#define _SS_PAD1SIZE (_SS_ALIGNSIZE - 2)
556#define _SS_PAD2SIZE (_SS_MAXSIZE - 2 - _SS_PAD1SIZE - _SS_ALIGNSIZE)
557
558struct sockaddr_storage {
559 __uint8_t ss_len; /* address length */
560 sa_family_t ss_family; /* address family */
561 char __ss_pad1[_SS_PAD1SIZE];
562 __int64_t __ss_align;/* force desired structure storage alignment */
563 char __ss_pad2[_SS_PAD2SIZE];
564};
565
566#if defined(_NETBSD_SOURCE)
567#define sstosa(__ss) ((struct sockaddr *)(__ss))
568#define sstocsa(__ss) ((const struct sockaddr *)(__ss))
569#endif /* _NETBSD_SOURCE */
570
571/*
572 * Protocol families, same as address families for now.
573 */
574#define PF_UNSPEC AF_UNSPEC
575#define PF_LOCAL AF_LOCAL
576#define PF_UNIX PF_LOCAL /* backward compatibility */
577#define PF_INET AF_INET
578#define PF_IMPLINK AF_IMPLINK
579#define PF_PUP AF_PUP
580#define PF_CHAOS AF_CHAOS
581#define PF_NS AF_NS
582#define PF_ISO AF_ISO
583#define PF_OSI AF_ISO
584#define PF_ECMA AF_ECMA
585#define PF_DATAKIT AF_DATAKIT
586#define PF_CCITT AF_CCITT
587#define PF_SNA AF_SNA
588#define PF_DECnet AF_DECnet
589#define PF_DLI AF_DLI
590#define PF_LAT AF_LAT
591#define PF_HYLINK AF_HYLINK
592#define PF_APPLETALK AF_APPLETALK
593#define PF_OROUTE AF_OROUTE
594#define PF_LINK AF_LINK
595#if defined(_NETBSD_SOURCE)
596#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
597#endif
598#define PF_COIP AF_COIP
599#define PF_CNT AF_CNT
600#define PF_INET6 AF_INET6
601#define PF_IPX AF_IPX /* same format as AF_NS */
602#if defined(_NETBSD_SOURCE)
603#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
604#define PF_PIP pseudo_AF_PIP
605#endif
606#define PF_ISDN AF_ISDN /* same as E164 */
607#define PF_E164 AF_E164
608#define PF_NATM AF_NATM
609#define PF_ARP AF_ARP
610#if defined(_NETBSD_SOURCE)
611#define PF_KEY pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */
612#endif
613#define PF_BLUETOOTH AF_BLUETOOTH
614#define PF_MPLS AF_MPLS
615#define PF_ROUTE AF_ROUTE
616#define PF_CAN AF_CAN
617#define PF_ETHER AF_ETHER
618
619#define PF_MAX AF_MAX
620
621#if defined(_NETBSD_SOURCE)
622
623#ifndef pid_t
624typedef __pid_t pid_t; /* process id */
625#define pid_t __pid_t
626#endif
627
628#ifndef gid_t
629typedef __gid_t gid_t; /* group id */
630#define gid_t __gid_t
631#endif
632
633#ifndef uid_t
634typedef __uid_t uid_t; /* user id */
635#define uid_t __uid_t
636#endif
637
638/*
639 * Socket credentials.
640 */
641struct sockcred {
642 pid_t sc_pid; /* process id */
643 uid_t sc_uid; /* real user id */
644 uid_t sc_euid; /* effective user id */
645 gid_t sc_gid; /* real group id */
646 gid_t sc_egid; /* effective group id */
647 int sc_ngroups; /* number of supplemental groups */
648 gid_t sc_groups[1]; /* variable length */
649};
650
651/*
652 * Compute size of a sockcred structure with groups.
653 *
654 * The (ngrps - 1) is to account for struct sockcred being defined with
655 * already one group member. This code works correctly when ngroups == 0
656 * because of unsigned arithmetic wrap-around.
657 */
658#define SOCKCREDSIZE(ngrps) \
659 (/*LINTED*/sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
660#endif /* _NETBSD_SOURCE */
661
662
663#if defined(_NETBSD_SOURCE)
664/* Definition for CTL_NET PCB fetching sysctls */
665struct kinfo_pcb {
666 __uint64_t ki_pcbaddr; /* PTR: pcb addr */
667 __uint64_t ki_ppcbaddr; /* PTR: ppcb addr */
668 __uint64_t ki_sockaddr; /* PTR: socket addr */
669
670 __uint32_t ki_family; /* INT: protocol family */
671 __uint32_t ki_type; /* INT: socket type */
672 __uint32_t ki_protocol; /* INT: protocol */
673 __uint32_t ki_pflags; /* INT: generic protocol flags */
674
675 __uint32_t ki_sostate; /* INT: socket state */
676 __uint32_t ki_prstate; /* INT: protocol state */
677 __int32_t ki_tstate; /* INT: tcp state */
678 __uint32_t ki_tflags; /* INT: tcp flags */
679
680 __uint64_t ki_rcvq; /* U_LONG: receive queue len */
681 __uint64_t ki_sndq; /* U_LONG: send queue len */
682
683 union {
684 struct sockaddr _kis_src; /* STRUCT: local address */
685 char _kis_pad[256 + 8]; /* pad to max addr length */
686 } ki_s;
687 union {
688 struct sockaddr _kid_dst; /* STRUCT: remote address */
689 char _kid_pad[256 + 8]; /* pad to max addr length */
690 } ki_d;
691
692 __uint64_t ki_inode; /* INO_T: fake inode number */
693 __uint64_t ki_vnode; /* PTR: if associated with file */
694 __uint64_t ki_conn; /* PTR: control block of peer */
695 __uint64_t ki_refs; /* PTR: referencing socket */
696 __uint64_t ki_nextref; /* PTR: link in refs list */
697};
698
699#define ki_src ki_s._kis_src
700#define ki_dst ki_d._kid_dst
701#define ki_spad ki_s._kis_pad
702#define ki_dpad ki_d._kid_pad
703
704#define PCB_SLOP 20
705#define PCB_ALL 0
706
707#endif /* _NETBSD_SOURCE */
708
709#if defined(_NETBSD_SOURCE)
710/*
711 * PF_ROUTE - Routing table
712 *
713 * Three additional levels are defined:
714 * Fourth: address family, 0 is wildcard
715 * Fifth: type of info, defined below
716 * Sixth: flag(s) to mask with for NET_RT_FLAGS
717 */
718#define NET_RT_DUMP 1 /* dump; may limit to a.f. */
719#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
720#define NET_RT_OOOIFLIST 3 /* old NET_RT_IFLIST (pre 1.5) */
721#define NET_RT_OOIFLIST 4 /* old NET_RT_IFLIST (pre-64bit time) */
722#define NET_RT_OIFLIST 5 /* old NET_RT_IFLIST (pre 8.0) */
723#define NET_RT_IFLIST 6 /* survey interface list */
724
725#endif /* _NETBSD_SOURCE */
726
727/*
728 * Maximum queue length specifiable by listen(2).
729 */
730#ifndef SOMAXCONN
731#define SOMAXCONN 128
732#endif
733
734#include <sys/cdefs.h>
735
736/*
737 * Message header for recvmsg and sendmsg calls.
738 * Used value-result for recvmsg, value only for sendmsg.
739 */
740struct msghdr {
741 void *msg_name; /* optional address */
742 socklen_t msg_namelen; /* size of address */
743 struct iovec *msg_iov; /* scatter/gather array */
744 int msg_iovlen; /* # elements in msg_iov */
745 void *msg_control; /* ancillary data, see below */
746 socklen_t msg_controllen; /* ancillary data buffer len */
747 int msg_flags; /* flags on received message */
748};
749
750#define MSG_OOB 0x0001 /* process out-of-band data */
751#define MSG_PEEK 0x0002 /* peek at incoming message */
752#define MSG_DONTROUTE 0x0004 /* send without using routing tables */
753#define MSG_EOR 0x0008 /* data completes record */
754#define MSG_TRUNC 0x0010 /* data discarded before delivery */
755#define MSG_CTRUNC 0x0020 /* control data lost before delivery */
756#define MSG_WAITALL 0x0040 /* wait for full request or error */
757#define MSG_DONTWAIT 0x0080 /* this message should be nonblocking */
758#define MSG_BCAST 0x0100 /* this message was rcvd using link-level brdcst */
759#define MSG_MCAST 0x0200 /* this message was rcvd using link-level mcast */
760#define MSG_NOSIGNAL 0x0400 /* do not generate SIGPIPE on EOF */
761#if defined(_NETBSD_SOURCE)
762#define MSG_CMSG_CLOEXEC 0x0800 /* close on exec receiving fd */
763#define MSG_NBIO 0x1000 /* use non-blocking I/O */
764#define MSG_WAITFORONE 0x2000 /* recvmmsg() wait for one message */
765#define MSG_NOTIFICATION 0x4000 /* SCTP notification */
766
767struct mmsghdr {
768 struct msghdr msg_hdr;
769 unsigned int msg_len;
770};
771#endif
772
773/* Extra flags used internally only */
774#define MSG_USERFLAGS 0x0ffffff
775#define MSG_NAMEMBUF 0x1000000 /* msg_name is an mbuf */
776#define MSG_CONTROLMBUF 0x2000000 /* msg_control is an mbuf */
777#define MSG_IOVUSRSPACE 0x4000000 /* msg_iov is in user space */
778#define MSG_LENUSRSPACE 0x8000000 /* address length is in user space */
779
780/*
781 * Header for ancillary data objects in msg_control buffer.
782 * Used for additional information with/about a datagram
783 * not expressible by flags. The format is a sequence
784 * of message elements headed by cmsghdr structures.
785 */
786struct cmsghdr {
787 socklen_t cmsg_len; /* data byte count, including hdr */
788 int cmsg_level; /* originating protocol */
789 int cmsg_type; /* protocol-specific type */
790/* followed by u_char cmsg_data[]; */
791};
792
793/*
794 * Alignment requirement for CMSG struct manipulation.
795 * This basically behaves the same as ALIGN() ARCH/include/param.h.
796 * We declare it separately for two reasons:
797 * (1) avoid dependency between machine/param.h, and (2) to sync with kernel's
798 * idea of ALIGNBYTES at runtime.
799 * without (2), we can't guarantee binary compatibility in case of future
800 * changes in ALIGNBYTES.
801 */
802#define __CMSG_ALIGN(n) (((n) + __ALIGNBYTES) & ~__ALIGNBYTES)
803
804#ifdef _KERNEL
805#define CMSG_ALIGN(n) __CMSG_ALIGN(n)
806#endif
807
808#define __CMSG_ASIZE __CMSG_ALIGN(sizeof(struct cmsghdr))
809#define __CMSG_MSGNEXT(cmsg) \
810 (__CASTV(char *, cmsg) + __CMSG_ALIGN((cmsg)->cmsg_len))
811#define __CMSG_MSGEND(mhdr) \
812 (__CASTV(char *, (mhdr)->msg_control) + (mhdr)->msg_controllen)
813
814/* given pointer to struct cmsghdr, return pointer to data */
815#define CMSG_DATA(cmsg) (__CASTV(u_char *, cmsg) + __CMSG_ASIZE)
816#define CCMSG_DATA(cmsg) (__CASTCV(const u_char *, cmsg) + __CMSG_ASIZE)
817
818/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
819#define CMSG_NXTHDR(mhdr, cmsg) \
820 __CASTV(struct cmsghdr *, \
821 __CMSG_MSGNEXT(cmsg) + __CMSG_ASIZE > __CMSG_MSGEND(mhdr) ? 0 : \
822 __CMSG_MSGNEXT(cmsg))
823
824/*
825 * RFC 2292 requires to check msg_controllen, in case that the kernel returns
826 * an empty list for some reasons.
827 */
828#define CMSG_FIRSTHDR(mhdr) \
829 __CASTV(struct cmsghdr *, \
830 (mhdr)->msg_controllen < sizeof(struct cmsghdr) ? 0 : \
831 (mhdr)->msg_control)
832
833#define CMSG_SPACE(l) (__CMSG_ASIZE + __CMSG_ALIGN(l))
834#define CMSG_LEN(l) (__CMSG_ASIZE + (l))
835
836/* "Socket"-level control message types: */
837#define SCM_RIGHTS 0x01 /* access rights (array of int) */
838#if defined(_NETBSD_SOURCE)
839/* 0x02 timestamp (struct timeval50) */
840/* 0x04 credentials (struct sockcred70) */
841#define SCM_TIMESTAMP 0x08 /* timestamp (struct timeval) */
842#define SCM_CREDS 0x10 /* credentials (struct sockcred) */
843#endif
844
845/*
846 * Types of socket shutdown(2).
847 */
848#define SHUT_RD 0 /* Disallow further receives. */
849#define SHUT_WR 1 /* Disallow further sends. */
850#define SHUT_RDWR 2 /* Disallow further sends/receives. */
851
852#ifdef _KERNEL
853static __inline socklen_t
854sockaddr_getlen(const struct sockaddr *sa)
855{
856 return sa->sa_len;
857}
858
859__BEGIN_DECLS
860socklen_t sockaddr_getsize_by_family(sa_family_t);
861struct sockaddr *sockaddr_copy(struct sockaddr *, socklen_t,
862 const struct sockaddr *);
863struct sockaddr *sockaddr_externalize(struct sockaddr *, socklen_t,
864 const struct sockaddr *);
865struct sockaddr *sockaddr_alloc(sa_family_t, socklen_t, int);
866const void *sockaddr_const_addr(const struct sockaddr *, socklen_t *);
867void *sockaddr_addr(struct sockaddr *, socklen_t *);
868const struct sockaddr *sockaddr_any(const struct sockaddr *);
869const struct sockaddr *sockaddr_any_by_family(sa_family_t);
870const void *sockaddr_anyaddr(const struct sockaddr *, socklen_t *);
871int sockaddr_cmp(const struct sockaddr *, const struct sockaddr *);
872struct sockaddr *sockaddr_dup(const struct sockaddr *, int);
873int sockaddr_format(const struct sockaddr *, char *, size_t);
874void sockaddr_free(struct sockaddr *);
875__END_DECLS
876#endif /* _KERNEL */
877#endif
878
879#ifndef _KERNEL
880
881__BEGIN_DECLS
882extern int accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
883#if 0
884extern int accept4(int, struct sockaddr * __restrict, socklen_t * __restrict, int);
885#endif
886extern int bind(int, const struct sockaddr *, socklen_t);
887extern int connect(int, const struct sockaddr *, socklen_t);
888extern int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
889extern int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
890extern int getsockopt(int, int, int, void *__restrict, socklen_t * __restrict);
891#if 0
892extern int getsockopt2(int, int, int, void *__restrict, socklen_t * __restrict);
893#endif
894extern int listen(int, int);
895#if 0
896extern int paccept(int, struct sockaddr * __restrict, socklen_t * __restrict,
897 const sigset_t * __restrict, int);
898#endif
899extern ssize_t recv(int, void *, size_t, int);
900extern ssize_t recvfrom(int, void *__restrict, size_t, int,
901 struct sockaddr * __restrict, socklen_t * __restrict);
902extern ssize_t recvmsg(int, struct msghdr *, int);
903extern ssize_t send(int, const void *, size_t, int);
904extern ssize_t sendto(int, const void *,
905 size_t, int, const struct sockaddr *, socklen_t);
906extern ssize_t sendmsg(int, const struct msghdr *, int);
907extern int setsockopt(int, int, int, const void *, socklen_t);
908extern int shutdown(int, int);
909#if 0
910extern int sockatmark(int);
911#endif
912extern int socket(int, int, int)
913#if 0
914#if !defined(__LIBC12_SOURCE__) && !defined(_STANDALONE)
915__RENAME(__socket30)
916#endif
917#endif
918 ;
919#if 0
920extern int socketpair(int, int, int, int *);
921#endif
922
923#if 0
924#if defined(_NETBSD_SOURCE)
925extern int sendmmsg(int, struct mmsghdr *, unsigned int, unsigned int);
926struct timespec;
927extern int recvmmsg(int, struct mmsghdr *, unsigned int, unsigned int,
928 struct timespec *);
929#endif
930#endif
931#if 1
932/* setconfig/dns_setserver take const - matches both real backend
933 * implementations exactly (core/ps2ip's own ps2ip_setconfig/
934 * dns_setserver and core/ps2ips's own ps2ipc_ps2ip_setconfig/
935 * ps2ipc_dns_setserver, and lwip's own real dns_setserver prototype).
936 * Real, previously-latent bug found for real porting Open-PS2-Loader:
937 * this was declared non-const, silently fine only because nothing had
938 * ever included both this header and a real backend's own declaration
939 * (ps2ipee.h, ps2ipc.h) in the same TU until now. */
940extern int libcglue_ps2ip_setconfig(const t_ip_info *ip_info);
941extern int libcglue_ps2ip_getconfig(char *netif_name, t_ip_info *ip_info);
942extern void libcglue_dns_setserver(u8 numdns, const ip_addr_t *dnsserver);
943extern const ip_addr_t *libcglue_dns_getserver(u8 numdns);
944#endif
945__END_DECLS
946
947#ifndef LIBCGLUE_SYS_SOCKET_ALIASES
948#define LIBCGLUE_SYS_SOCKET_ALIASES 0
949#endif
950
951#if LIBCGLUE_SYS_SOCKET_ALIASES
952#define closesocket(...) close(__VA_ARGS__)
953#define readsocket(...) read(__VA_ARGS__)
954#define writesocket(...) write(__VA_ARGS__)
955#define ioctlsocket(...) ioctl(__VA_ARGS__)
956#define fcntlsocket(...) fcntl(__VA_ARGS__)
957#define lwip_accept(...) accept(__VA_ARGS__)
958#define lwip_bind(...) bind(__VA_ARGS__)
959#define lwip_shutdown(...) shutdown(__VA_ARGS__)
960#define lwip_getpeername(...) getpeername(__VA_ARGS__)
961#define lwip_getsockname(...) getsockname(__VA_ARGS__)
962#define lwip_getsockopt(...) getsockopt(__VA_ARGS__)
963#define lwip_setsockopt(...) setsockopt(__VA_ARGS__)
964#define lwip_close(...) close(__VA_ARGS__)
965#define lwip_connect(...) connect(__VA_ARGS__)
966#define lwip_listen(...) listen(__VA_ARGS__)
967#define lwip_recv(...) recv(__VA_ARGS__)
968#define lwip_read(...) read(__VA_ARGS__)
969#define lwip_recvfrom(...) recvfrom(__VA_ARGS__)
970#define lwip_send(...) send(__VA_ARGS__)
971#define lwip_sendto(...) sendto(__VA_ARGS__)
972#define lwip_socket(...) socket(__VA_ARGS__)
973#define lwip_write(...) write(__VA_ARGS__)
974#define lwip_select(...) select(__VA_ARGS__)
975#define lwip_ioctl(...) ioctl(__VA_ARGS__)
976#define lwip_fcntl(...) fcntl(__VA_ARGS__)
977#define disconnect(...) close(__VA_ARGS__)
978#define ps2ip_setconfig(...) libcglue_ps2ip_setconfig(__VA_ARGS__)
979#define ps2ip_getconfig(...) libcglue_ps2ip_getconfig(__VA_ARGS__)
980#define dns_setserver(...) libcglue_dns_setserver(__VA_ARGS__)
981#define dns_getserver(...) libcglue_dns_getserver(__VA_ARGS__)
982#endif
983
984#endif /* !_KERNEL */
985
986#endif /* !_SYS_SOCKET_H_ */
struct ip4_addr ip4_addr_t
Definition ps2ip_rpc.h:41
Definition uio.h:28