Mon Dec 25 20:56:39 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
[glibc.git] / socket / sys / socket.h
blob9b88e642f73c0fe6e4fe7300b24337a3ee2d30d4
1 /* Copyright (C) 1991, 1992, 1994, 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
19 #ifndef _SYS_SOCKET_H
21 #define _SYS_SOCKET_H 1
22 #include <features.h>
24 __BEGIN_DECLS
26 #define __need_size_t
27 #include <stddef.h>
30 /* Types of sockets. */
31 enum __socket_type
33 SOCK_STREAM = 1, /* Sequenced, reliable, connection-based
34 byte streams. */
35 SOCK_DGRAM = 2, /* Connectionless, unreliable datagrams
36 of fixed maximum length. */
37 SOCK_RAW = 3, /* Raw protocol interface. */
38 SOCK_RDM = 4, /* Reliably-delivered messages. */
39 SOCK_SEQPACKET = 5, /* Sequenced, reliable, connection-based,
40 datagrams of fixed maximum length. */
43 /* Protocol families. */
44 #define PF_UNSPEC 0 /* Unspecified. */
45 #define PF_LOCAL 1 /* Local to host (pipes and file-domain). */
46 #define PF_UNIX PF_LOCAL /* Old BSD name for PF_LOCAL. */
47 #define PF_INET 2 /* IP protocol family. */
48 #define PF_IMPLINK 3 /* ARPAnet IMP protocol. */
49 #define PF_PUP 4 /* PUP protocols. */
50 #define PF_CHAOS 5 /* MIT Chaos protocols. */
51 #define PF_NS 6 /* Xerox NS protocols. */
52 #define PF_ISO 7 /* ISO protocols. */
53 #define PF_OSI PF_ISO
54 #define PF_ECMA 8 /* ECMA protocols. */
55 #define PF_DATAKIT 9 /* AT&T Datakit protocols. */
56 #define PF_CCITT 10 /* CCITT protocols (X.25 et al). */
57 #define PF_SNA 11 /* IBM SNA protocol. */
58 #define PF_DECnet 12 /* DECnet protocols. */
59 #define PF_DLI 13 /* Direct data link interface. */
60 #define PF_LAT 14 /* DEC Local Area Transport protocol. */
61 #define PF_HYLINK 15 /* NSC Hyperchannel protocol. */
62 #define PF_APPLETALK 16 /* Don't use this. */
63 #define PF_ROUTE 17 /* Internal Routing Protocol. */
64 #define PF_LINK 18 /* Link layer interface. */
65 #define PF_XTP 19 /* eXpress Transfer Protocol (no AF). */
66 #define PF_COIP 20 /* Connection-oriented IP, aka ST II. */
67 #define PF_CNT 21 /* Computer Network Technology. */
68 #define PF_RTIP 22 /* Help Identify RTIP packets. **/
69 #define PF_IPX 23 /* Novell Internet Protocol. */
70 #define PF_SIP 24 /* Simple Internet Protocol. */
71 #define PF_PIP 25 /* Help Identify PIP packets. */
72 #define PF_MAX 26
74 /* Address families. */
75 #define AF_UNSPEC PF_UNSPEC
76 #define AF_LOCAL PF_LOCAL
77 #define AF_UNIX PF_UNIX
78 #define AF_INET PF_INET
79 #define AF_IMPLINK PF_IMPLINK
80 #define AF_PUP PF_PUP
81 #define AF_CHAOS PF_CHAOS
82 #define AF_NS PF_NS
83 #define AF_ISO PF_ISO
84 #define AF_OSI PF_OSI
85 #define AF_ECMA PF_ECMA
86 #define AF_DATAKIT PF_DATAKIT
87 #define AF_CCITT PF_CCITT
88 #define AF_SNA PF_SNA
89 #define AF_DECnet PF_DECnet
90 #define AF_DLI PF_DLI
91 #define AF_LAT PF_LAT
92 #define AF_HYLINK PF_HYLINK
93 #define AF_APPLETALK PF_APPLETALK
94 #define AF_ROUTE PF_ROUTE
95 #define AF_LINK PF_LINK
96 #define pseudo_AF_XTP PF_XTP
97 #define AF_COIP PF_COIP
98 #define AF_CNT PF_CNT
99 #define pseudo_AF_RTIP PF_RTIP
100 #define AF_IPX PF_IPX
101 #define AF_SIP PF_SIP
102 #define pseudo_AF_PIP PF_PIP
103 #define AF_MAX PF_MAX
106 /* Get the definition of the macro to define the common sockaddr members. */
107 #include <sockaddrcom.h>
109 /* Structure describing a generic socket address. */
110 struct sockaddr
112 __SOCKADDR_COMMON (sa_); /* Common data: address family and length. */
113 char sa_data[14]; /* Address data. */
116 /* This is the type we use for generic socket address arguments.
118 With GCC 2.7 and later, the funky union causes redeclarations or uses with
119 any of the listed types to be allowed without complaint. */
120 #if (!defined (__GNUC__) || __GNUC__ < 2 || \
121 (__GNUC__ == 2 && __GNUC_MINOR__ < 7))
122 #define __SOCKADDR_ARG struct sockaddr *
123 #define __CONST_SOCKADDR_ARG __const struct sockaddr *
124 #else
125 /* Add more `struct sockaddr_AF' types here as necessary.
126 These are all the ones I found on NetBSD and Linux. */
127 #define __SOCKADDR_ALLTYPES \
128 __SOCKADDR_ONETYPE (sockaddr) \
129 __SOCKADDR_ONETYPE (sockaddr_at) \
130 __SOCKADDR_ONETYPE (sockaddr_ax25) \
131 __SOCKADDR_ONETYPE (sockaddr_dl) \
132 __SOCKADDR_ONETYPE (sockaddr_eon) \
133 __SOCKADDR_ONETYPE (sockaddr_in) \
134 __SOCKADDR_ONETYPE (sockaddr_in6) \
135 __SOCKADDR_ONETYPE (sockaddr_inarp) \
136 __SOCKADDR_ONETYPE (sockaddr_ipx) \
137 __SOCKADDR_ONETYPE (sockaddr_iso) \
138 __SOCKADDR_ONETYPE (sockaddr_ns) \
139 __SOCKADDR_ONETYPE (sockaddr_un) \
140 __SOCKADDR_ONETYPE (sockaddr_x25)
142 #define __SOCKADDR_ONETYPE(type) struct type *__##type##__;
143 typedef union { __SOCKADDR_ALLTYPES
144 } __SOCKADDR_ARG __attribute__ ((__transparent_union__));
145 #undef __SOCKADDR_ONETYPE
146 #define __SOCKADDR_ONETYPE(type) __const struct type *__##type##__;
147 typedef union { __SOCKADDR_ALLTYPES
148 } __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__));
149 #undef __SOCKADDR_ONETYPE
150 #endif
153 /* Create a new socket of type TYPE in domain DOMAIN, using
154 protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.
155 Returns a file descriptor for the new socket, or -1 for errors. */
156 extern int socket __P ((int __domain, enum __socket_type __type,
157 int __protocol));
159 /* Create two new sockets, of type TYPE in domain DOMAIN and using
160 protocol PROTOCOL, which are connected to each other, and put file
161 descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero,
162 one will be chosen automatically. Returns 0 on success, -1 for errors. */
163 extern int socketpair __P ((int __domain, enum __socket_type __type,
164 int __protocol, int __fds[2]));
166 /* Give the socket FD the local address ADDR (which is LEN bytes long). */
167 extern int bind __P ((int __fd, __CONST_SOCKADDR_ARG __addr, size_t __len));
169 /* Put the local address of FD into *ADDR and its length in *LEN. */
170 extern int getsockname __P ((int __fd, __SOCKADDR_ARG __addr,
171 size_t *__len));
173 /* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
174 For connectionless socket types, just set the default address to send to
175 and the only address from which to accept transmissions.
176 Return 0 on success, -1 for errors. */
177 extern int connect __P ((int __fd,
178 __CONST_SOCKADDR_ARG __addr, size_t __len));
180 /* Put the address of the peer connected to socket FD into *ADDR
181 (which is *LEN bytes long), and its actual length into *LEN. */
182 extern int getpeername __P ((int __fd, __SOCKADDR_ARG __addr,
183 size_t *__len));
186 /* Bits in the FLAGS argument to `send', `recv', et al. */
187 enum
189 MSG_OOB = 0x01, /* Process out-of-band data. */
190 MSG_PEEK = 0x02, /* Peek at incoming messages. */
191 MSG_DONTROUTE = 0x04, /* Don't use local routing. */
192 MSG_EOR = 0x08, /* Data completes record. */
193 MSG_TRUNC = 0x10, /* Data discarded before delivery. */
194 MSG_CTRUNC = 0x20, /* Control data lost before delivery. */
195 MSG_WAITALL = 0x40, /* Wait for full request or error. */
196 MSG_DONTWAIT = 0x80, /* This message should be nonblocking. */
199 /* Send N bytes of BUF to socket FD. Returns the number sent or -1. */
200 extern int send __P ((int __fd, __ptr_t __buf, size_t __n, int __flags));
202 /* Read N bytes into BUF from socket FD.
203 Returns the number read or -1 for errors. */
204 extern int recv __P ((int __fd, __ptr_t __buf, size_t __n, int __flags));
206 /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
207 ADDR_LEN bytes long). Returns the number sent, or -1 for errors. */
208 extern int sendto __P ((int __fd, __ptr_t __buf, size_t __n, int __flags,
209 __CONST_SOCKADDR_ARG __addr, size_t __addr_len));
211 /* Read N bytes into BUF through socket FD.
212 If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
213 the sender, and store the actual size of the address in *ADDR_LEN.
214 Returns the number of bytes read or -1 for errors. */
215 extern int recvfrom __P ((int __fd, __ptr_t __buf, size_t __n, int __flags,
216 __SOCKADDR_ARG __addr, size_t *__addr_len));
220 /* Structure describing messages sent by
221 `sendmsg' and received by `recvmsg'. */
222 struct msghdr
224 __ptr_t msg_name; /* Address to send to/receive from. */
225 size_t msg_namelen; /* Length of address data. */
227 struct iovec *msg_iov; /* Vector of data to send/receive into. */
228 size_t msg_iovlen; /* Number of elements in the vector. */
230 __ptr_t msg_accrights; /* Access rights information. */
231 size_t msg_accrightslen; /* Length of access rights information. */
234 /* Send a message described MESSAGE on socket FD.
235 Returns the number of bytes sent, or -1 for errors. */
236 extern int sendmsg __P ((int __fd, __const struct msghdr *__message,
237 int __flags));
239 /* Receive a message as described by MESSAGE from socket FD.
240 Returns the number of bytes read or -1 for errors. */
241 extern int recvmsg __P ((int __fd, struct msghdr *__message, int __flags));
244 /* Protocol number used to manipulate socket-level options
245 with `getsockopt' and `setsockopt'. */
246 #define SOL_SOCKET 0xffff
248 /* Socket-level options for `getsockopt' and `setsockopt'. */
249 enum
251 SO_DEBUG = 0x0001, /* Record debugging information. */
252 SO_ACCEPTCONN = 0x0002, /* Accept connections on socket. */
253 SO_REUSEADDR = 0x0004, /* Allow reuse of local addresses. */
254 SO_KEEPALIVE = 0x0008, /* Keep connections alive and send
255 SIGPIPE when they die. */
256 SO_DONTROUTE = 0x0010, /* Don't do local routing. */
257 SO_BROADCAST = 0x0020, /* Allow transmission of
258 broadcast messages. */
259 SO_USELOOPBACK = 0x0040, /* Use the software loopback to avoid
260 hardware use when possible. */
261 SO_LINGER = 0x0080, /* Block on close of a reliable
262 socket to transmit pending data. */
263 SO_OOBINLINE = 0x0100, /* Receive out-of-band data in-band. */
265 SO_REUSEPORT = 0x0200, /* Allow local address and port reuse. */
267 SO_SNDBUF = 0x1001, /* Send buffer size. */
268 SO_RCVBUF = 0x1002, /* Receive buffer. */
269 SO_SNDLOWAT = 0x1003, /* Send low-water mark. */
270 SO_RCVLOWAT = 0x1004, /* Receive low-water mark. */
271 SO_SNDTIMEO = 0x1005, /* Send timeout. */
272 SO_RCVTIMEO = 0x1006, /* Receive timeout. */
274 SO_ERROR = 0x1007, /* Get and clear error status. */
275 SO_STYLE = 0x1008, /* Get socket connection style. */
276 SO_TYPE = SO_STYLE, /* Compatible name for SO_STYLE. */
279 /* Structure used to manipulate the SO_LINGER option. */
280 struct linger
282 int l_onoff; /* Nonzero to linger on close. */
283 int l_linger; /* Time to linger. */
287 /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
288 into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
289 actual length. Returns 0 on success, -1 for errors. */
290 extern int getsockopt __P ((int __fd, int __level, int __optname,
291 __ptr_t __optval, size_t *__optlen));
293 /* Set socket FD's option OPTNAME at protocol level LEVEL
294 to *OPTVAL (which is OPTLEN bytes long).
295 Returns 0 on success, -1 for errors. */
296 extern int setsockopt __P ((int __fd, int __level, int __optname,
297 __ptr_t __optval, size_t __optlen));
300 /* Prepare to accept connections on socket FD.
301 N connection requests will be queued before further requests are refused.
302 Returns 0 on success, -1 for errors. */
303 extern int listen __P ((int __fd, unsigned int __n));
305 /* Await a connection on socket FD.
306 When a connection arrives, open a new socket to communicate with it,
307 set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
308 peer and *ADDR_LEN to the address's actual length, and return the
309 new socket's descriptor, or -1 for errors. */
310 extern int accept __P ((int __fd, __SOCKADDR_ARG __addr,
311 size_t *__addr_len));
313 /* Shut down all or part of the connection open on socket FD.
314 HOW determines what to shut down:
315 0 = No more receptions;
316 1 = No more transmissions;
317 2 = No more receptions or transmissions.
318 Returns 0 on success, -1 for errors. */
319 extern int shutdown __P ((int __fd, int __how));
322 __END_DECLS
324 #endif /* sys/socket.h */