RTEMS CPU Kit with SuperCore
socket.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
3  * The Regents of the University of California. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 4. Neither the name of the University nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * @(#)socket.h 8.4 (Berkeley) 2/21/94
30  * $FreeBSD: src/sys/sys/socket.h,v 1.88 2005/04/13 00:01:46 mdodd Exp $
31  */
32 
33 
34 #ifndef _SYS_SOCKET_H_
35 #define _SYS_SOCKET_H_
36 
37 #include <sys/cdefs.h>
38 #include <rtems/bsdnet/_types.h>
39 #include <sys/types.h>
40 
41 /*
42  * Definitions related to sockets: types, address families, options.
43  */
44 
45 /*
46  * Data types.
47  */
48 
49 #ifndef _SA_FAMILY_T_DECLARED
50 typedef __sa_family_t sa_family_t;
51 #define _SA_FAMILY_T_DECLARED
52 #endif
53 
54 #ifndef _SOCKLEN_T_DECLARED
55 typedef __socklen_t socklen_t;
56 #define _SOCKLEN_T_DECLARED
57 #endif
58 
59 /*
60  * Types
61  */
62 #define SOCK_STREAM 1 /* stream socket */
63 #define SOCK_DGRAM 2 /* datagram socket */
64 #define SOCK_RAW 3 /* raw-protocol interface */
65 #if __BSD_VISIBLE
66 #define SOCK_RDM 4 /* reliably-delivered message */
67 #endif
68 #define SOCK_SEQPACKET 5 /* sequenced packet stream */
69 
70 /*
71  * Option flags per-socket.
72  */
73 #define SO_DEBUG 0x0001 /* turn on debugging info recording */
74 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
75 #define SO_REUSEADDR 0x0004 /* allow local address reuse */
76 #define SO_KEEPALIVE 0x0008 /* keep connections alive */
77 #define SO_DONTROUTE 0x0010 /* just use interface addresses */
78 #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
79 #if __BSD_VISIBLE
80 #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
81 #endif
82 #define SO_LINGER 0x0080 /* linger on close if data present */
83 #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
84 #if __BSD_VISIBLE
85 #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
86 #define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */
87 #define SO_NOSIGPIPE 0x0800 /* no SIGPIPE from EPIPE */
88 #define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
89 #define SO_BINTIME 0x2000 /* timestamp received dgram traffic */
90 #endif
91 
92 /*
93  * Additional options, not kept in so_options.
94  */
95 #define SO_SNDBUF 0x1001 /* send buffer size */
96 #define SO_RCVBUF 0x1002 /* receive buffer size */
97 #define SO_SNDLOWAT 0x1003 /* send low-water mark */
98 #define SO_RCVLOWAT 0x1004 /* receive low-water mark */
99 #define SO_SNDTIMEO 0x1005 /* send timeout */
100 #define SO_RCVTIMEO 0x1006 /* receive timeout */
101 #define SO_ERROR 0x1007 /* get error status and clear */
102 #define SO_TYPE 0x1008 /* get socket type */
103 #define SO_PRIVSTATE 0x1009 /* get/deny privileged state */
104 
105 /*
106  * RTEMS addition: get and set wakeup functions.
107  */
108 #define SO_SNDWAKEUP 0x1020 /* wakeup when ready to send */
109 #define SO_RCVWAKEUP 0x1021 /* wakeup when ready to receive */
110 
111 /*
112  * Structure used for manipulating linger option.
113  */
114 struct linger {
115  int l_onoff; /* option on/off */
116  int l_linger; /* linger time */
117 };
118 
119 /*
120  * RTEMS addition: structure used to get and set wakeup function.
121  */
122 struct socket;
123 struct sockwakeup {
124  void (*sw_pfn)(struct socket *, void *);
125  void *sw_arg;
126 };
127 
128 /*
129  * Level number for (get/set)sockopt() to apply to socket itself.
130  */
131 #define SOL_SOCKET 0xffff /* options for socket level */
132 
133 /*
134  * Address families.
135  */
136 #define AF_UNSPEC 0 /* unspecified */
137 #if __BSD_VISIBLE
138 #define AF_LOCAL AF_UNIX /* local to host (pipes, portals) */
139 #endif
140 #define AF_UNIX 1 /* standardized name for AF_LOCAL */
141 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
142 #if __BSD_VISIBLE
143 #define AF_IMPLINK 3 /* arpanet imp addresses */
144 #define AF_PUP 4 /* pup protocols: e.g. BSP */
145 #define AF_CHAOS 5 /* mit CHAOS protocols */
146 #define AF_NETBIOS 6 /* SMB protocols */
147 #define AF_ISO 7 /* ISO protocols */
148 #define AF_OSI AF_ISO
149 #define AF_ECMA 8 /* European computer manufacturers */
150 #define AF_DATAKIT 9 /* datakit protocols */
151 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
152 #define AF_SNA 11 /* IBM SNA */
153 #define AF_DECnet 12 /* DECnet */
154 #define AF_DLI 13 /* DEC Direct data link interface */
155 #define AF_LAT 14 /* LAT */
156 #define AF_HYLINK 15 /* NSC Hyperchannel */
157 #define AF_APPLETALK 16 /* Apple Talk */
158 #define AF_ROUTE 17 /* Internal Routing Protocol */
159 #define AF_LINK 18 /* Link layer interface */
160 #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
161 #define AF_COIP 20 /* connection-oriented IP, aka ST II */
162 #define AF_CNT 21 /* Computer Network Technology */
163 #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
164 #define AF_IPX 23 /* Novell Internet Protocol */
165 #define AF_SIP 24 /* Simple Internet Protocol */
166 #define pseudo_AF_PIP 25 /* Help Identify PIP packets */
167 #define AF_ISDN 26 /* Integrated Services Digital Network*/
168 #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
169 #define pseudo_AF_KEY 27 /* Internal key-management function */
170 #endif
171 #define AF_INET6 28 /* IPv6 */
172 
173 #define AF_MAX 29
174 
175 /*
176  * Structure used by kernel to store most
177  * addresses.
178  */
179 struct sockaddr {
180  unsigned char sa_len; /* total length */
181  sa_family_t sa_family; /* address family */
182  char sa_data[14]; /* actually longer; address value */
183 };
184 
185 /*
186  * Structure used by kernel to pass protocol
187  * information in raw sockets.
188  */
189 struct sockproto {
190  unsigned short sp_family; /* address family */
191  unsigned short sp_protocol; /* protocol */
192 };
193 
194 /*
195  * Protocol families, same as address families for now.
196  */
197 #define PF_UNSPEC AF_UNSPEC
198 #define PF_LOCAL AF_LOCAL
199 #define PF_UNIX PF_LOCAL /* backward compatibility */
200 #define PF_INET AF_INET
201 #define PF_IMPLINK AF_IMPLINK
202 #define PF_PUP AF_PUP
203 #define PF_CHAOS AF_CHAOS
204 #define PF_NETBIOS AF_NETBIOS
205 #define PF_ISO AF_ISO
206 #define PF_OSI AF_ISO
207 #define PF_ECMA AF_ECMA
208 #define PF_DATAKIT AF_DATAKIT
209 #define PF_CCITT AF_CCITT
210 #define PF_SNA AF_SNA
211 #define PF_DECnet AF_DECnet
212 #define PF_DLI AF_DLI
213 #define PF_LAT AF_LAT
214 #define PF_HYLINK AF_HYLINK
215 #define PF_APPLETALK AF_APPLETALK
216 #define PF_ROUTE AF_ROUTE
217 #define PF_LINK AF_LINK
218 #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
219 #define PF_COIP AF_COIP
220 #define PF_CNT AF_CNT
221 #define PF_SIP AF_SIP
222 #define PF_IPX AF_IPX
223 #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
224 #define PF_PIP pseudo_AF_PIP
225 #define PF_ISDN AF_ISDN
226 #define PF_KEY pseudo_AF_KEY
227 #define PF_INET6 AF_INET6
228 
229 #define PF_MAX AF_MAX
230 
231 /*
232  * Definitions for network related sysctl, CTL_NET.
233  *
234  * Second level is protocol family.
235  * Third level is protocol number.
236  *
237  * Further levels are defined by the individual families below.
238  */
239 #define NET_MAXID AF_MAX
240 
241 #define CTL_NET_NAMES { \
242  { 0, 0 }, \
243  { "unix", CTLTYPE_NODE }, \
244  { "inet", CTLTYPE_NODE }, \
245  { "implink", CTLTYPE_NODE }, \
246  { "pup", CTLTYPE_NODE }, \
247  { "chaos", CTLTYPE_NODE }, \
248  { "xerox_ns", CTLTYPE_NODE }, \
249  { "iso", CTLTYPE_NODE }, \
250  { "emca", CTLTYPE_NODE }, \
251  { "datakit", CTLTYPE_NODE }, \
252  { "ccitt", CTLTYPE_NODE }, \
253  { "ibm_sna", CTLTYPE_NODE }, \
254  { "decnet", CTLTYPE_NODE }, \
255  { "dec_dli", CTLTYPE_NODE }, \
256  { "lat", CTLTYPE_NODE }, \
257  { "hylink", CTLTYPE_NODE }, \
258  { "appletalk", CTLTYPE_NODE }, \
259  { "route", CTLTYPE_NODE }, \
260  { "link_layer", CTLTYPE_NODE }, \
261  { "xtp", CTLTYPE_NODE }, \
262  { "coip", CTLTYPE_NODE }, \
263  { "cnt", CTLTYPE_NODE }, \
264  { "rtip", CTLTYPE_NODE }, \
265  { "ipx", CTLTYPE_NODE }, \
266  { "sip", CTLTYPE_NODE }, \
267  { "pip", CTLTYPE_NODE }, \
268  { "isdn", CTLTYPE_NODE }, \
269  { "key", CTLTYPE_NODE }, \
270 }
271 
272 /*
273  * PF_ROUTE - Routing table
274  *
275  * Three additional levels are defined:
276  * Fourth: address family, 0 is wildcard
277  * Fifth: type of info, defined below
278  * Sixth: flag(s) to mask with for NET_RT_FLAGS
279  */
280 #define NET_RT_DUMP 1 /* dump; may limit to a.f. */
281 #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
282 #define NET_RT_IFLIST 3 /* survey interface list */
283 #define NET_RT_MAXID 4
284 
285 #define CTL_NET_RT_NAMES { \
286  { 0, 0 }, \
287  { "dump", CTLTYPE_STRUCT }, \
288  { "flags", CTLTYPE_STRUCT }, \
289  { "iflist", CTLTYPE_STRUCT }, \
290 }
291 
292 /*
293  * Maximum queue length specifiable by listen.
294  */
295 #define SOMAXCONN 128
296 
297 /*
298  * Message header for recvmsg and sendmsg calls.
299  * Used value-result for recvmsg, value only for sendmsg.
300  */
301 struct msghdr {
302  void *msg_name; /* optional address */
303  socklen_t msg_namelen; /* size of address */
304  struct iovec *msg_iov; /* scatter/gather array */
305  int msg_iovlen; /* # elements in msg_iov */
306  void *msg_control; /* ancillary data, see below */
307  socklen_t msg_controllen; /* ancillary data buffer len */
308  int msg_flags; /* flags on received message */
309 };
310 
311 #define MSG_OOB 0x1 /* process out-of-band data */
312 #define MSG_PEEK 0x2 /* peek at incoming message */
313 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
314 #define MSG_EOR 0x8 /* data completes record */
315 #define MSG_TRUNC 0x10 /* data discarded before delivery */
316 #define MSG_CTRUNC 0x20 /* control data lost before delivery */
317 #define MSG_WAITALL 0x40 /* wait for full request or error */
318 #if __BSD_VISIBLE
319 #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
320 #define MSG_EOF 0x100 /* data completes connection */
321 #define MSG_COMPAT 0x8000 /* used in sendit() */
322 #endif
323 
324 /*
325  * Header for ancillary data objects in msg_control buffer.
326  * Used for additional information with/about a datagram
327  * not expressible by flags. The format is a sequence
328  * of message elements headed by cmsghdr structures.
329  */
330 struct cmsghdr {
331  socklen_t cmsg_len; /* data byte count, including hdr */
332  int cmsg_level; /* originating protocol */
333  int cmsg_type; /* protocol-specific type */
334 /* followed by u_char cmsg_data[]; */
335 };
336 
337 /* given pointer to struct cmsghdr, return pointer to data */
338 #define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1))
339 
340 /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
341 #define CMSG_NXTHDR(mhdr, cmsg) \
342  (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
343  (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
344  (struct cmsghdr *)NULL : \
345  (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
346 
347 #define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
348 
349 /* "Socket"-level control message types: */
350 #define SCM_RIGHTS 0x01 /* access rights (array of int) */
351 #define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */
352 
353 /*
354  * 4.3 compat sockaddr, move to compat file later
355  */
356 struct osockaddr {
357  unsigned short sa_family; /* address family */
358  char sa_data[14]; /* up to 14 bytes of direct address */
359 };
360 
361 /*
362  * 4.3-compat message header (move to compat file later).
363  */
364 struct omsghdr {
365  char *msg_name; /* optional address */
366  int msg_namelen; /* size of address */
367  struct iovec *msg_iov; /* scatter/gather array */
368  int msg_iovlen; /* # elements in msg_iov */
369  char *msg_accrights; /* access rights sent/received */
370  int msg_accrightslen;
371 };
372 
373 /*
374  * howto arguments for shutdown(2), specified by Posix.1g.
375  */
376 #define SHUT_RD 0 /* shut down the reading side */
377 #define SHUT_WR 1 /* shut down the writing side */
378 #define SHUT_RDWR 2 /* shut down both sides */
379 
380 #ifndef _KERNEL
381 
382 __BEGIN_DECLS
383 int accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
384 int bind(int, const struct sockaddr *, socklen_t);
385 int connect(int, const struct sockaddr *, socklen_t);
386 int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
387 int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
388 int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
389 int listen(int, int);
390 ssize_t recv(int, void *, size_t, int);
391 ssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict);
392 ssize_t recvmsg(int, struct msghdr *, int);
393 ssize_t send(int, const void *, size_t, int);
394 ssize_t sendto(int, const void *,
395  size_t, int, const struct sockaddr *, socklen_t);
396 ssize_t sendmsg(int, const struct msghdr *, int);
397 int setsockopt(int, int, int, const void *, socklen_t);
398 int shutdown(int, int);
399 int socket(int, int, int);
400 int socketpair(int, int, int, int *);
401 __END_DECLS
402 
403 #endif /* !_KERNEL */
404 
405 #endif /* !_SYS_SOCKET_H_ */
Definition: socket.h:124
Definition: socket.h:302
Definition: socket.h:190
Definition: socketvar.h:49
Definition: socket.h:331
Definition: socket.h:365
Definition: socket.h:180
Definition: socket.h:115
Definition: _iovec.h:53
Definition: socket.h:357