PSPSDK 1.0+beta2
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 * Protocol families, same as address families for now.
174 */
175#define PF_UNSPEC AF_UNSPEC
176#define PF_LOCAL AF_LOCAL
177#define PF_UNIX PF_LOCAL /* backward compatibility */
178#define PF_INET AF_INET
179#define PF_IMPLINK AF_IMPLINK
180#define PF_PUP AF_PUP
181#define PF_CHAOS AF_CHAOS
182#define PF_NS AF_NS
183#define PF_ISO AF_ISO
184#define PF_OSI AF_ISO
185#define PF_ECMA AF_ECMA
186#define PF_DATAKIT AF_DATAKIT
187#define PF_CCITT AF_CCITT
188#define PF_SNA AF_SNA
189#define PF_DECnet AF_DECnet
190#define PF_DLI AF_DLI
191#define PF_LAT AF_LAT
192#define PF_HYLINK AF_HYLINK
193#define PF_APPLETALK AF_APPLETALK
194#define PF_ROUTE AF_ROUTE
195#define PF_LINK AF_LINK
196#if defined(_NETBSD_SOURCE)
197#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
198#endif
199#define PF_COIP AF_COIP
200#define PF_CNT AF_CNT
201#define PF_INET6 AF_INET6
202#define PF_IPX AF_IPX /* same format as AF_NS */
203#if defined(_NETBSD_SOURCE)
204#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
205#define PF_PIP pseudo_AF_PIP
206#endif
207#define PF_ISDN AF_ISDN /* same as E164 */
208#define PF_E164 AF_E164
209#define PF_NATM AF_NATM
210#define PF_ARP AF_ARP
211#if defined(_NETBSD_SOURCE)
212#define PF_KEY pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */
213#endif
214
215#define PF_MAX AF_MAX
216
217#define MSG_OOB 0x1 /* process out-of-band data */
218#define MSG_PEEK 0x2 /* peek at incoming message */
219#define MSG_DONTROUTE 0x4 /* send without using routing tables */
220#define MSG_EOR 0x8 /* data completes record */
221#define MSG_TRUNC 0x10 /* data discarded before delivery */
222#define MSG_CTRUNC 0x20 /* control data lost before delivery */
223#define MSG_WAITALL 0x40 /* wait for full request or error */
224#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
225#define MSG_BCAST 0x100 /* this message was rcvd using link-level brdcst */
226#define MSG_MCAST 0x200 /* this message was rcvd using link-level mcast */
227
228/*
229 * Types of socket shutdown(2).
230 */
231#define SHUT_RD 0 /* Disallow further receives. */
232#define SHUT_WR 1 /* Disallow further sends. */
233#define SHUT_RDWR 2 /* Disallow further sends/receives. */
234
235struct iovec {
236 void *iov_base; /* Base address. */
237 size_t iov_len; /* Length. */
238};
239
240/*
241 * Maximum queue length specifiable by listen.
242 */
243#define SOMAXCONN 128
244
245struct msghdr {
246 void *msg_name; /* optional address */
247 socklen_t msg_namelen; /* size of address */
248 struct iovec *msg_iov; /* scatter/gather array */
249 int msg_iovlen; /* # elements in msg_iov */
250 void *msg_control; /* ancillary data, see below */
251 socklen_t msg_controllen; /* ancillary data buffer len */
252 int msg_flags; /* flags on received message */
253};
254
255/* BSD-compatible socket API. */
257int bind(int, const struct sockaddr *, socklen_t);
258int connect(int, const struct sockaddr *, socklen_t);
261int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
262int listen(int, int);
263ssize_t recv(int, void *, size_t, int);
264ssize_t recvfrom(int, void * __restrict, size_t, int,
266ssize_t recvmsg(int s, struct msghdr *msg, int flags);
267ssize_t send(int, const void *, size_t, int);
268ssize_t sendto(int, const void *,
269 size_t, int, const struct sockaddr *, socklen_t);
270ssize_t sendmsg(int s, const struct msghdr *msg, int flags);
271int setsockopt(int, int, int, const void *, socklen_t);
272int shutdown(int, int);
273int socket(int, int, int);
274
275#ifdef __cplusplus
276}
277#endif
278
279#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)
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
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:235
void * iov_base
Definition socket.h:236
size_t iov_len
Definition socket.h:237
Definition socket.h:118
int l_linger
Definition socket.h:120
int l_onoff
Definition socket.h:119
Definition socket.h:245
struct iovec * msg_iov
Definition socket.h:248
socklen_t msg_namelen
Definition socket.h:247
void * msg_name
Definition socket.h:246
int msg_iovlen
Definition socket.h:249
int msg_flags
Definition socket.h:252
socklen_t msg_controllen
Definition socket.h:251
void * msg_control
Definition socket.h:250
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