PSPSDK 2024-10-31
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1/* $NetBSD: socket.h,v 1.77 2005/11/29 03:12:16 christos Exp $ */
2
3/*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32/*
33 * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
34 * The Regents of the University of California. All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)socket.h 8.6 (Berkeley) 5/3/95
61 */
62
63#ifndef _SYS_SOCKET_H_
64#define _SYS_SOCKET_H_
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70#include <stdint.h>
71#include <stddef.h>
72#include <sys/types.h>
73
76
77/*
78 * Socket types.
79 */
80#define SOCK_STREAM 1 /* stream socket */
81#define SOCK_DGRAM 2 /* datagram socket */
82#define SOCK_RAW 3 /* raw-protocol interface */
83#define SOCK_RDM 4 /* reliably-delivered message */
84#define SOCK_SEQPACKET 5 /* sequenced packet stream */
85
86/*
87 * Option flags per-socket.
88 */
89#define SO_DEBUG 0x0001 /* turn on debugging info recording */
90#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
91#define SO_REUSEADDR 0x0004 /* allow local address reuse */
92#define SO_KEEPALIVE 0x0008 /* keep connections alive */
93#define SO_DONTROUTE 0x0010 /* just use interface addresses */
94#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
95#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
96#define SO_LINGER 0x0080 /* linger on close if data present */
97#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
98#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
99#define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */
100
101/*
102 * Additional options, not kept in so_options.
103 */
104#define SO_SNDBUF 0x1001 /* send buffer size */
105#define SO_RCVBUF 0x1002 /* receive buffer size */
106#define SO_SNDLOWAT 0x1003 /* send low-water mark */
107#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
108#define SO_SNDTIMEO 0x1005 /* send timeout */
109#define SO_RCVTIMEO 0x1006 /* receive timeout */
110#define SO_ERROR 0x1007 /* get error status and clear */
111#define SO_TYPE 0x1008 /* get socket type */
112#define SO_OVERFLOWED 0x1009 /* datagrams: return packets dropped */
113#define SO_NONBLOCK 0x1009 /* non-blocking I/O */
114
115/*
116 * Structure used for manipulating linger option.
117 */
118struct linger {
119 int l_onoff; /* option on/off */
120 int l_linger; /* linger time in seconds */
121};
122
123/*
124 * Level number for (get/set)sockopt() to apply to socket itself.
125 */
126#define SOL_SOCKET 0xffff /* options for socket level */
127
128/*
129 * Address families.
130 */
131#define AF_UNSPEC 0 /* unspecified */
132#define AF_LOCAL 1 /* local to host (pipes, portals) */
133#define AF_UNIX AF_LOCAL /* backward compatibility */
134#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
135#define AF_IMPLINK 3 /* arpanet imp addresses */
136#define AF_PUP 4 /* pup protocols: e.g. BSP */
137#define AF_CHAOS 5 /* mit CHAOS protocols */
138#define AF_NS 6 /* XEROX NS protocols */
139#define AF_ISO 7 /* ISO protocols */
140#define AF_OSI AF_ISO
141#define AF_ECMA 8 /* european computer manufacturers */
142#define AF_DATAKIT 9 /* datakit protocols */
143#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
144#define AF_SNA 11 /* IBM SNA */
145#define AF_DECnet 12 /* DECnet */
146#define AF_DLI 13 /* DEC Direct data link interface */
147#define AF_LAT 14 /* LAT */
148#define AF_HYLINK 15 /* NSC Hyperchannel */
149#define AF_APPLETALK 16 /* Apple Talk */
150#define AF_ROUTE 17 /* Internal Routing Protocol */
151#define AF_LINK 18 /* Link layer interface */
152#define AF_COIP 20 /* connection-oriented IP, aka ST II */
153#define AF_CNT 21 /* Computer Network Technology */
154#define AF_IPX 23 /* Novell Internet Protocol */
155#define AF_INET6 24 /* IP version 6 */
156#define AF_ISDN 26 /* Integrated Services Digital Network*/
157#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
158#define AF_NATM 27 /* native ATM access */
159#define AF_ARP 28 /* (rev.) addr. res. prot. (RFC 826) */
160#define AF_MAX 31
161
162/*
163 * Structure used by kernel to store most
164 * addresses.
165 */
166struct sockaddr {
167 uint8_t sa_len; /* total length */
168 sa_family_t sa_family; /* address family */
169 char sa_data[14]; /* actually longer; address value */
170};
171
172/*
173 * RFC 2553: protocol-independent placeholder for socket addresses
174 */
175#define _SS_MAXSIZE 128
176#define _SS_ALIGNSIZE (sizeof(int64_t))
177#define _SS_PAD1SIZE (_SS_ALIGNSIZE - 2)
178#define _SS_PAD2SIZE (_SS_MAXSIZE - 2 - _SS_PAD1SIZE - _SS_ALIGNSIZE)
179
181 uint8_t ss_len; /* address length */
182 sa_family_t ss_family; /* address family */
184 int64_t __ss_align;/* force desired structure storage alignment */
186};
187
188/*
189 * Protocol families, same as address families for now.
190 */
191#define PF_UNSPEC AF_UNSPEC
192#define PF_LOCAL AF_LOCAL
193#define PF_UNIX PF_LOCAL /* backward compatibility */
194#define PF_INET AF_INET
195#define PF_IMPLINK AF_IMPLINK
196#define PF_PUP AF_PUP
197#define PF_CHAOS AF_CHAOS
198#define PF_NS AF_NS
199#define PF_ISO AF_ISO
200#define PF_OSI AF_ISO
201#define PF_ECMA AF_ECMA
202#define PF_DATAKIT AF_DATAKIT
203#define PF_CCITT AF_CCITT
204#define PF_SNA AF_SNA
205#define PF_DECnet AF_DECnet
206#define PF_DLI AF_DLI
207#define PF_LAT AF_LAT
208#define PF_HYLINK AF_HYLINK
209#define PF_APPLETALK AF_APPLETALK
210#define PF_ROUTE AF_ROUTE
211#define PF_LINK AF_LINK
212#if defined(_NETBSD_SOURCE)
213#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
214#endif
215#define PF_COIP AF_COIP
216#define PF_CNT AF_CNT
217#define PF_INET6 AF_INET6
218#define PF_IPX AF_IPX /* same format as AF_NS */
219#if defined(_NETBSD_SOURCE)
220#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
221#define PF_PIP pseudo_AF_PIP
222#endif
223#define PF_ISDN AF_ISDN /* same as E164 */
224#define PF_E164 AF_E164
225#define PF_NATM AF_NATM
226#define PF_ARP AF_ARP
227#if defined(_NETBSD_SOURCE)
228#define PF_KEY pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */
229#endif
230
231#define PF_MAX AF_MAX
232
233#define MSG_OOB 0x1 /* process out-of-band data */
234#define MSG_PEEK 0x2 /* peek at incoming message */
235#define MSG_DONTROUTE 0x4 /* send without using routing tables */
236#define MSG_EOR 0x8 /* data completes record */
237#define MSG_TRUNC 0x10 /* data discarded before delivery */
238#define MSG_CTRUNC 0x20 /* control data lost before delivery */
239#define MSG_WAITALL 0x40 /* wait for full request or error */
240#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
241#define MSG_BCAST 0x100 /* this message was rcvd using link-level brdcst */
242#define MSG_MCAST 0x200 /* this message was rcvd using link-level mcast */
243
244/*
245 * Types of socket shutdown(2).
246 */
247#define SHUT_RD 0 /* Disallow further receives. */
248#define SHUT_WR 1 /* Disallow further sends. */
249#define SHUT_RDWR 2 /* Disallow further sends/receives. */
250
251struct iovec {
252 void *iov_base; /* Base address. */
253 size_t iov_len; /* Length. */
254};
255
256/*
257 * Maximum queue length specifiable by listen.
258 */
259#define SOMAXCONN 128
260
261struct msghdr {
262 void *msg_name; /* optional address */
263 socklen_t msg_namelen; /* size of address */
264 struct iovec *msg_iov; /* scatter/gather array */
265 int msg_iovlen; /* # elements in msg_iov */
266 void *msg_control; /* ancillary data, see below */
267 socklen_t msg_controllen; /* ancillary data buffer len */
268 int msg_flags; /* flags on received message */
269};
270
271/* BSD-compatible socket API. */
273int bind(int, const struct sockaddr *, socklen_t);
274int connect(int, const struct sockaddr *, socklen_t);
277int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
278int listen(int, int);
279ssize_t recv(int, void *, size_t, int);
280ssize_t recvfrom(int, void * __restrict, size_t, int,
282ssize_t recvmsg(int s, struct msghdr *msg, int flags);
283ssize_t send(int, const void *, size_t, int);
284ssize_t sendto(int, const void *,
285 size_t, int, const struct sockaddr *, socklen_t);
286ssize_t sendmsg(int s, const struct msghdr *msg, int flags);
287int setsockopt(int, int, int, const void *, socklen_t);
288int shutdown(int, int);
289int socket(int, int, int);
290
291#ifdef __cplusplus
292}
293#endif
294
295#endif /* !_SYS_SOCKET_H_ */
u32 flags
Definition fixup.c:1
short int s[8]
Definition psptypes.h:8
float x
Definition psptypes.h:0
int bind(int, const struct sockaddr *, socklen_t)
#define _SS_PAD2SIZE
Definition socket.h:178
int getpeername(int, struct sockaddr *__restrict, socklen_t *__restrict)
int listen(int, int)
uint32_t socklen_t
Definition socket.h:75
ssize_t send(int, const void *, size_t, int)
int shutdown(int, int)
int accept(int, struct sockaddr *__restrict, socklen_t *__restrict)
ssize_t recvmsg(int s, struct msghdr *msg, int flags)
int connect(int, const struct sockaddr *, socklen_t)
int getsockopt(int, int, int, void *__restrict, socklen_t *__restrict)
ssize_t recv(int, void *, size_t, int)
ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t)
ssize_t sendmsg(int s, const struct msghdr *msg, int flags)
uint8_t sa_family_t
Definition socket.h:74
#define _SS_PAD1SIZE
Definition socket.h:177
int getsockname(int, struct sockaddr *__restrict, socklen_t *__restrict)
ssize_t recvfrom(int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict)
int socket(int, int, int)
int setsockopt(int, int, int, const void *, socklen_t)
Definition socket.h:251
void * iov_base
Definition socket.h:252
size_t iov_len
Definition socket.h:253
Definition socket.h:118
int l_linger
Definition socket.h:120
int l_onoff
Definition socket.h:119
Definition socket.h:261
struct iovec * msg_iov
Definition socket.h:264
socklen_t msg_namelen
Definition socket.h:263
void * msg_name
Definition socket.h:262
int msg_iovlen
Definition socket.h:265
int msg_flags
Definition socket.h:268
socklen_t msg_controllen
Definition socket.h:267
void * msg_control
Definition socket.h:266
Definition socket.h:180
sa_family_t ss_family
Definition socket.h:182
char __ss_pad2[_SS_PAD2SIZE]
Definition socket.h:185
char __ss_pad1[_SS_PAD1SIZE]
Definition socket.h:183
int64_t __ss_align
Definition socket.h:184
uint8_t ss_len
Definition socket.h:181
Definition socket.h:166
uint8_t sa_len
Definition socket.h:167
sa_family_t sa_family
Definition socket.h:168
char sa_data[14]
Definition socket.h:169