Tue Jul 9 09:37:55 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[glibc.git] / sysdeps / generic / sys / socket.h
blob6ee3ebe52eb8dedf3dbdaf10cac2ab3479051517
1 /* Copyright (C) 1991, 92, 94, 95, 96 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 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_INET6 26 /* IP version 6. */
73 #define PF_MAX 27
75 /* Address families. */
76 #define AF_UNSPEC PF_UNSPEC
77 #define AF_LOCAL PF_LOCAL
78 #define AF_UNIX PF_UNIX
79 #define AF_INET PF_INET
80 #define AF_IMPLINK PF_IMPLINK
81 #define AF_PUP PF_PUP
82 #define AF_CHAOS PF_CHAOS
83 #define AF_NS PF_NS
84 #define AF_ISO PF_ISO
85 #define AF_OSI PF_OSI
86 #define AF_ECMA PF_ECMA
87 #define AF_DATAKIT PF_DATAKIT
88 #define AF_CCITT PF_CCITT
89 #define AF_SNA PF_SNA
90 #define AF_DECnet PF_DECnet
91 #define AF_DLI PF_DLI
92 #define AF_LAT PF_LAT
93 #define AF_HYLINK PF_HYLINK
94 #define AF_APPLETALK PF_APPLETALK
95 #define AF_ROUTE PF_ROUTE
96 #define AF_LINK PF_LINK
97 #define pseudo_AF_XTP PF_XTP
98 #define AF_COIP PF_COIP
99 #define AF_CNT PF_CNT
100 #define pseudo_AF_RTIP PF_RTIP
101 #define AF_IPX PF_IPX
102 #define AF_SIP PF_SIP
103 #define pseudo_AF_PIP PF_PIP
104 #define AF_INET6 PF_INET6
105 #define AF_MAX PF_MAX
108 /* Get the definition of the macro to define the common sockaddr members. */
109 #include <sockaddrcom.h>
111 /* Structure describing a generic socket address. */
112 struct sockaddr
114 __SOCKADDR_COMMON (sa_); /* Common data: address family and length. */
115 char sa_data[14]; /* Address data. */
118 /* This is the type we use for generic socket address arguments.
120 With GCC 2.7 and later, the funky union causes redeclarations or uses with
121 any of the listed types to be allowed without complaint. */
122 #if (!defined (__GNUC__) || __GNUC__ < 2 || \
123 (__GNUC__ == 2 && __GNUC_MINOR__ < 7))
124 #define __SOCKADDR_ARG struct sockaddr *
125 #define __CONST_SOCKADDR_ARG __const struct sockaddr *
126 #else
127 /* Add more `struct sockaddr_AF' types here as necessary.
128 These are all the ones I found on NetBSD and Linux. */
129 #define __SOCKADDR_ALLTYPES \
130 __SOCKADDR_ONETYPE (sockaddr) \
131 __SOCKADDR_ONETYPE (sockaddr_at) \
132 __SOCKADDR_ONETYPE (sockaddr_ax25) \
133 __SOCKADDR_ONETYPE (sockaddr_dl) \
134 __SOCKADDR_ONETYPE (sockaddr_eon) \
135 __SOCKADDR_ONETYPE (sockaddr_in) \
136 __SOCKADDR_ONETYPE (sockaddr_in6) \
137 __SOCKADDR_ONETYPE (sockaddr_inarp) \
138 __SOCKADDR_ONETYPE (sockaddr_ipx) \
139 __SOCKADDR_ONETYPE (sockaddr_iso) \
140 __SOCKADDR_ONETYPE (sockaddr_ns) \
141 __SOCKADDR_ONETYPE (sockaddr_un) \
142 __SOCKADDR_ONETYPE (sockaddr_x25)
144 #define __SOCKADDR_ONETYPE(type) struct type *__##type##__;
145 typedef union { __SOCKADDR_ALLTYPES
146 } __SOCKADDR_ARG __attribute__ ((__transparent_union__));
147 #undef __SOCKADDR_ONETYPE
148 #define __SOCKADDR_ONETYPE(type) __const struct type *__##type##__;
149 typedef union { __SOCKADDR_ALLTYPES
150 } __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__));
151 #undef __SOCKADDR_ONETYPE
152 #endif
155 /* Create a new socket of type TYPE in domain DOMAIN, using
156 protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.
157 Returns a file descriptor for the new socket, or -1 for errors. */
158 extern int socket __P ((int __domain, enum __socket_type __type,
159 int __protocol));
161 /* Create two new sockets, of type TYPE in domain DOMAIN and using
162 protocol PROTOCOL, which are connected to each other, and put file
163 descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero,
164 one will be chosen automatically. Returns 0 on success, -1 for errors. */
165 extern int socketpair __P ((int __domain, enum __socket_type __type,
166 int __protocol, int __fds[2]));
168 /* Give the socket FD the local address ADDR (which is LEN bytes long). */
169 extern int bind __P ((int __fd, __CONST_SOCKADDR_ARG __addr, size_t __len));
171 /* Put the local address of FD into *ADDR and its length in *LEN. */
172 extern int getsockname __P ((int __fd, __SOCKADDR_ARG __addr,
173 size_t *__len));
175 /* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
176 For connectionless socket types, just set the default address to send to
177 and the only address from which to accept transmissions.
178 Return 0 on success, -1 for errors. */
179 extern int connect __P ((int __fd,
180 __CONST_SOCKADDR_ARG __addr, size_t __len));
182 /* Put the address of the peer connected to socket FD into *ADDR
183 (which is *LEN bytes long), and its actual length into *LEN. */
184 extern int getpeername __P ((int __fd, __SOCKADDR_ARG __addr,
185 size_t *__len));
188 /* Bits in the FLAGS argument to `send', `recv', et al. */
189 enum
191 MSG_OOB = 0x01, /* Process out-of-band data. */
192 MSG_PEEK = 0x02, /* Peek at incoming messages. */
193 MSG_DONTROUTE = 0x04, /* Don't use local routing. */
194 MSG_EOR = 0x08, /* Data completes record. */
195 MSG_TRUNC = 0x10, /* Data discarded before delivery. */
196 MSG_CTRUNC = 0x20, /* Control data lost before delivery. */
197 MSG_WAITALL = 0x40, /* Wait for full request or error. */
198 MSG_DONTWAIT = 0x80, /* This message should be nonblocking. */
201 /* Send N bytes of BUF to socket FD. Returns the number sent or -1. */
202 extern int send __P ((int __fd, __ptr_t __buf, size_t __n, int __flags));
204 /* Read N bytes into BUF from socket FD.
205 Returns the number read or -1 for errors. */
206 extern int recv __P ((int __fd, __ptr_t __buf, size_t __n, int __flags));
208 /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
209 ADDR_LEN bytes long). Returns the number sent, or -1 for errors. */
210 extern int sendto __P ((int __fd, __ptr_t __buf, size_t __n, int __flags,
211 __CONST_SOCKADDR_ARG __addr, size_t __addr_len));
213 /* Read N bytes into BUF through socket FD.
214 If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
215 the sender, and store the actual size of the address in *ADDR_LEN.
216 Returns the number of bytes read or -1 for errors. */
217 extern int recvfrom __P ((int __fd, __ptr_t __buf, size_t __n, int __flags,
218 __SOCKADDR_ARG __addr, size_t *__addr_len));
222 /* Structure describing messages sent by
223 `sendmsg' and received by `recvmsg'. */
224 struct msghdr
226 __ptr_t msg_name; /* Address to send to/receive from. */
227 size_t msg_namelen; /* Length of address data. */
229 struct iovec *msg_iov; /* Vector of data to send/receive into. */
230 size_t msg_iovlen; /* Number of elements in the vector. */
232 __ptr_t msg_accrights; /* Access rights information. */
233 size_t msg_accrightslen; /* Length of access rights information. */
236 /* Send a message described MESSAGE on socket FD.
237 Returns the number of bytes sent, or -1 for errors. */
238 extern int sendmsg __P ((int __fd, __const struct msghdr *__message,
239 int __flags));
241 /* Receive a message as described by MESSAGE from socket FD.
242 Returns the number of bytes read or -1 for errors. */
243 extern int recvmsg __P ((int __fd, struct msghdr *__message, int __flags));
246 /* Protocol number used to manipulate socket-level options
247 with `getsockopt' and `setsockopt'. */
248 #define SOL_SOCKET 0xffff
250 /* Socket-level options for `getsockopt' and `setsockopt'. */
251 enum
253 SO_DEBUG = 0x0001, /* Record debugging information. */
254 SO_ACCEPTCONN = 0x0002, /* Accept connections on socket. */
255 SO_REUSEADDR = 0x0004, /* Allow reuse of local addresses. */
256 SO_KEEPALIVE = 0x0008, /* Keep connections alive and send
257 SIGPIPE when they die. */
258 SO_DONTROUTE = 0x0010, /* Don't do local routing. */
259 SO_BROADCAST = 0x0020, /* Allow transmission of
260 broadcast messages. */
261 SO_USELOOPBACK = 0x0040, /* Use the software loopback to avoid
262 hardware use when possible. */
263 SO_LINGER = 0x0080, /* Block on close of a reliable
264 socket to transmit pending data. */
265 SO_OOBINLINE = 0x0100, /* Receive out-of-band data in-band. */
267 SO_REUSEPORT = 0x0200, /* Allow local address and port reuse. */
269 SO_SNDBUF = 0x1001, /* Send buffer size. */
270 SO_RCVBUF = 0x1002, /* Receive buffer. */
271 SO_SNDLOWAT = 0x1003, /* Send low-water mark. */
272 SO_RCVLOWAT = 0x1004, /* Receive low-water mark. */
273 SO_SNDTIMEO = 0x1005, /* Send timeout. */
274 SO_RCVTIMEO = 0x1006, /* Receive timeout. */
276 SO_ERROR = 0x1007, /* Get and clear error status. */
277 SO_STYLE = 0x1008, /* Get socket connection style. */
278 SO_TYPE = SO_STYLE, /* Compatible name for SO_STYLE. */
281 /* Structure used to manipulate the SO_LINGER option. */
282 struct linger
284 int l_onoff; /* Nonzero to linger on close. */
285 int l_linger; /* Time to linger. */
289 /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
290 into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
291 actual length. Returns 0 on success, -1 for errors. */
292 extern int getsockopt __P ((int __fd, int __level, int __optname,
293 __ptr_t __optval, size_t *__optlen));
295 /* Set socket FD's option OPTNAME at protocol level LEVEL
296 to *OPTVAL (which is OPTLEN bytes long).
297 Returns 0 on success, -1 for errors. */
298 extern int setsockopt __P ((int __fd, int __level, int __optname,
299 __ptr_t __optval, size_t __optlen));
302 /* Prepare to accept connections on socket FD.
303 N connection requests will be queued before further requests are refused.
304 Returns 0 on success, -1 for errors. */
305 extern int listen __P ((int __fd, unsigned int __n));
307 /* Await a connection on socket FD.
308 When a connection arrives, open a new socket to communicate with it,
309 set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
310 peer and *ADDR_LEN to the address's actual length, and return the
311 new socket's descriptor, or -1 for errors. */
312 extern int accept __P ((int __fd, __SOCKADDR_ARG __addr,
313 size_t *__addr_len));
315 /* Shut down all or part of the connection open on socket FD.
316 HOW determines what to shut down:
317 0 = No more receptions;
318 1 = No more transmissions;
319 2 = No more receptions or transmissions.
320 Returns 0 on success, -1 for errors. */
321 extern int shutdown __P ((int __fd, int __how));
324 /* Determine whether FILDES if the property identified by the value if
325 FDTYPE. */
326 extern int isfdtype __P ((int __fildes, int __fdtype));
328 __END_DECLS
330 #endif /* sys/socket.h */