* misc/sys/cdefs.h (__va_arg_pack): Define for GCC 4.3+.
[glibc.git] / socket / sys / socket.h
blob6d9eab7f943f19ba59054e6bf1ed17095f60f8a5
1 /* Declarations of socket constants, types, and functions.
2 Copyright (C) 1991,92,1994-2001,2003,2005,2007
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #ifndef _SYS_SOCKET_H
22 #define _SYS_SOCKET_H 1
24 #include <features.h>
26 __BEGIN_DECLS
28 #include <sys/uio.h>
29 #define __need_size_t
30 #include <stddef.h>
33 /* This operating system-specific header file defines the SOCK_*, PF_*,
34 AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr',
35 `struct msghdr', and `struct linger' types. */
36 #include <bits/socket.h>
38 #ifdef __USE_BSD
39 /* This is the 4.3 BSD `struct sockaddr' format, which is used as wire
40 format in the grotty old 4.3 `talk' protocol. */
41 struct osockaddr
43 unsigned short int sa_family;
44 unsigned char sa_data[14];
46 #endif
48 /* The following constants should be used for the second parameter of
49 `shutdown'. */
50 enum
52 SHUT_RD = 0, /* No more receptions. */
53 #define SHUT_RD SHUT_RD
54 SHUT_WR, /* No more transmissions. */
55 #define SHUT_WR SHUT_WR
56 SHUT_RDWR /* No more receptions or transmissions. */
57 #define SHUT_RDWR SHUT_RDWR
60 /* This is the type we use for generic socket address arguments.
62 With GCC 2.7 and later, the funky union causes redeclarations or
63 uses with any of the listed types to be allowed without complaint.
64 G++ 2.7 does not support transparent unions so there we want the
65 old-style declaration, too. */
66 #if defined __cplusplus || !__GNUC_PREREQ (2, 7) || !defined __USE_GNU
67 # define __SOCKADDR_ARG struct sockaddr *__restrict
68 # define __CONST_SOCKADDR_ARG __const struct sockaddr *
69 #else
70 /* Add more `struct sockaddr_AF' types here as necessary.
71 These are all the ones I found on NetBSD and Linux. */
72 # define __SOCKADDR_ALLTYPES \
73 __SOCKADDR_ONETYPE (sockaddr) \
74 __SOCKADDR_ONETYPE (sockaddr_at) \
75 __SOCKADDR_ONETYPE (sockaddr_ax25) \
76 __SOCKADDR_ONETYPE (sockaddr_dl) \
77 __SOCKADDR_ONETYPE (sockaddr_eon) \
78 __SOCKADDR_ONETYPE (sockaddr_in) \
79 __SOCKADDR_ONETYPE (sockaddr_in6) \
80 __SOCKADDR_ONETYPE (sockaddr_inarp) \
81 __SOCKADDR_ONETYPE (sockaddr_ipx) \
82 __SOCKADDR_ONETYPE (sockaddr_iso) \
83 __SOCKADDR_ONETYPE (sockaddr_ns) \
84 __SOCKADDR_ONETYPE (sockaddr_un) \
85 __SOCKADDR_ONETYPE (sockaddr_x25)
87 # define __SOCKADDR_ONETYPE(type) struct type *__restrict __##type##__;
88 typedef union { __SOCKADDR_ALLTYPES
89 } __SOCKADDR_ARG __attribute__ ((__transparent_union__));
90 # undef __SOCKADDR_ONETYPE
91 # define __SOCKADDR_ONETYPE(type) __const struct type *__restrict __##type##__;
92 typedef union { __SOCKADDR_ALLTYPES
93 } __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__));
94 # undef __SOCKADDR_ONETYPE
95 #endif
98 /* Create a new socket of type TYPE in domain DOMAIN, using
99 protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.
100 Returns a file descriptor for the new socket, or -1 for errors. */
101 extern int socket (int __domain, int __type, int __protocol) __THROW;
103 /* Create two new sockets, of type TYPE in domain DOMAIN and using
104 protocol PROTOCOL, which are connected to each other, and put file
105 descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero,
106 one will be chosen automatically. Returns 0 on success, -1 for errors. */
107 extern int socketpair (int __domain, int __type, int __protocol,
108 int __fds[2]) __THROW;
110 /* Give the socket FD the local address ADDR (which is LEN bytes long). */
111 extern int bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
112 __THROW;
114 /* Put the local address of FD into *ADDR and its length in *LEN. */
115 extern int getsockname (int __fd, __SOCKADDR_ARG __addr,
116 socklen_t *__restrict __len) __THROW;
118 /* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
119 For connectionless socket types, just set the default address to send to
120 and the only address from which to accept transmissions.
121 Return 0 on success, -1 for errors.
123 This function is a cancellation point and therefore not marked with
124 __THROW. */
125 extern int connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
127 /* Put the address of the peer connected to socket FD into *ADDR
128 (which is *LEN bytes long), and its actual length into *LEN. */
129 extern int getpeername (int __fd, __SOCKADDR_ARG __addr,
130 socklen_t *__restrict __len) __THROW;
133 /* Send N bytes of BUF to socket FD. Returns the number sent or -1.
135 This function is a cancellation point and therefore not marked with
136 __THROW. */
137 extern ssize_t send (int __fd, __const void *__buf, size_t __n, int __flags);
139 /* Read N bytes into BUF from socket FD.
140 Returns the number read or -1 for errors.
142 This function is a cancellation point and therefore not marked with
143 __THROW. */
144 extern ssize_t recv (int __fd, void *__buf, size_t __n, int __flags);
146 /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
147 ADDR_LEN bytes long). Returns the number sent, or -1 for errors.
149 This function is a cancellation point and therefore not marked with
150 __THROW. */
151 extern ssize_t sendto (int __fd, __const void *__buf, size_t __n,
152 int __flags, __CONST_SOCKADDR_ARG __addr,
153 socklen_t __addr_len);
155 /* Read N bytes into BUF through socket FD.
156 If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
157 the sender, and store the actual size of the address in *ADDR_LEN.
158 Returns the number of bytes read or -1 for errors.
160 This function is a cancellation point and therefore not marked with
161 __THROW. */
162 extern ssize_t recvfrom (int __fd, void *__restrict __buf, size_t __n,
163 int __flags, __SOCKADDR_ARG __addr,
164 socklen_t *__restrict __addr_len);
167 /* Send a message described MESSAGE on socket FD.
168 Returns the number of bytes sent, or -1 for errors.
170 This function is a cancellation point and therefore not marked with
171 __THROW. */
172 extern ssize_t sendmsg (int __fd, __const struct msghdr *__message,
173 int __flags);
175 /* Receive a message as described by MESSAGE from socket FD.
176 Returns the number of bytes read or -1 for errors.
178 This function is a cancellation point and therefore not marked with
179 __THROW. */
180 extern ssize_t recvmsg (int __fd, struct msghdr *__message, int __flags);
183 /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
184 into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
185 actual length. Returns 0 on success, -1 for errors. */
186 extern int getsockopt (int __fd, int __level, int __optname,
187 void *__restrict __optval,
188 socklen_t *__restrict __optlen) __THROW;
190 /* Set socket FD's option OPTNAME at protocol level LEVEL
191 to *OPTVAL (which is OPTLEN bytes long).
192 Returns 0 on success, -1 for errors. */
193 extern int setsockopt (int __fd, int __level, int __optname,
194 __const void *__optval, socklen_t __optlen) __THROW;
197 /* Prepare to accept connections on socket FD.
198 N connection requests will be queued before further requests are refused.
199 Returns 0 on success, -1 for errors. */
200 extern int listen (int __fd, int __n) __THROW;
202 /* Await a connection on socket FD.
203 When a connection arrives, open a new socket to communicate with it,
204 set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
205 peer and *ADDR_LEN to the address's actual length, and return the
206 new socket's descriptor, or -1 for errors.
208 This function is a cancellation point and therefore not marked with
209 __THROW. */
210 extern int accept (int __fd, __SOCKADDR_ARG __addr,
211 socklen_t *__restrict __addr_len);
213 /* Shut down all or part of the connection open on socket FD.
214 HOW determines what to shut down:
215 SHUT_RD = No more receptions;
216 SHUT_WR = No more transmissions;
217 SHUT_RDWR = No more receptions or transmissions.
218 Returns 0 on success, -1 for errors. */
219 extern int shutdown (int __fd, int __how) __THROW;
222 #ifdef __USE_XOPEN2K
223 /* Determine wheter socket is at a out-of-band mark. */
224 extern int sockatmark (int __fd) __THROW;
225 #endif
228 #ifdef __USE_MISC
229 /* FDTYPE is S_IFSOCK or another S_IF* macro defined in <sys/stat.h>;
230 returns 1 if FD is open on an object of the indicated type, 0 if not,
231 or -1 for errors (setting errno). */
232 extern int isfdtype (int __fd, int __fdtype) __THROW;
233 #endif
236 /* Define some macros helping to catch buffer overflows. */
237 #if __USE_FORTIFY_LEVEL > 0 && defined __extern_always_inline
238 # include <bits/socket2.h>
239 #endif
241 __END_DECLS
243 #endif /* sys/socket.h */