]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/include/sys/socket.h
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / include / sys / socket.h
1 /* Declarations of socket constants, types, and functions.
2    Copyright (C) 1991,92,1994-2001,2003,2005,2007,2008
3    Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5
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.
10
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.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <http://www.gnu.org/licenses/>.  */
19
20 #ifndef _SYS_SOCKET_H
21 #define _SYS_SOCKET_H   1
22
23 #include <features.h>
24
25 __BEGIN_DECLS
26
27 #include <sys/uio.h>
28 #define __need_size_t
29 #include <stddef.h>
30 #ifdef __USE_GNU
31 /* Get the __sigset_t definition.  */
32 # include <bits/sigset.h>
33 #endif
34
35
36 /* This operating system-specific header file defines the SOCK_*, PF_*,
37    AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr',
38    `struct msghdr', and `struct linger' types.  */
39 #include <bits/socket.h>
40
41 #ifdef __USE_BSD
42 /* This is the 4.3 BSD `struct sockaddr' format, which is used as wire
43    format in the grotty old 4.3 `talk' protocol.  */
44 struct osockaddr
45   {
46     unsigned short int sa_family;
47     unsigned char sa_data[14];
48   };
49 #endif
50
51 /* The following constants should be used for the second parameter of
52    `shutdown'.  */
53 enum
54 {
55   SHUT_RD = 0,          /* No more receptions.  */
56 #define SHUT_RD         SHUT_RD
57   SHUT_WR,              /* No more transmissions.  */
58 #define SHUT_WR         SHUT_WR
59   SHUT_RDWR             /* No more receptions or transmissions.  */
60 #define SHUT_RDWR       SHUT_RDWR
61 };
62
63 /* This is the type we use for generic socket address arguments.
64
65    With GCC 2.7 and later, the funky union causes redeclarations or
66    uses with any of the listed types to be allowed without complaint.
67    G++ 2.7 does not support transparent unions so there we want the
68    old-style declaration, too.  */
69 #if defined __cplusplus || !__GNUC_PREREQ (2, 7) || !defined __USE_GNU
70 # define __SOCKADDR_ARG         struct sockaddr *__restrict
71 # define __CONST_SOCKADDR_ARG   const struct sockaddr *
72 #else
73 /* Add more `struct sockaddr_AF' types here as necessary.
74    These are all the ones I found on NetBSD and Linux.  */
75 # define __SOCKADDR_ALLTYPES \
76   __SOCKADDR_ONETYPE (sockaddr) \
77   __SOCKADDR_ONETYPE (sockaddr_at) \
78   __SOCKADDR_ONETYPE (sockaddr_ax25) \
79   __SOCKADDR_ONETYPE (sockaddr_dl) \
80   __SOCKADDR_ONETYPE (sockaddr_eon) \
81   __SOCKADDR_ONETYPE (sockaddr_in) \
82   __SOCKADDR_ONETYPE (sockaddr_in6) \
83   __SOCKADDR_ONETYPE (sockaddr_inarp) \
84   __SOCKADDR_ONETYPE (sockaddr_ipx) \
85   __SOCKADDR_ONETYPE (sockaddr_iso) \
86   __SOCKADDR_ONETYPE (sockaddr_ns) \
87   __SOCKADDR_ONETYPE (sockaddr_un) \
88   __SOCKADDR_ONETYPE (sockaddr_x25)
89
90 # define __SOCKADDR_ONETYPE(type) struct type *__restrict __##type##__;
91 typedef union { __SOCKADDR_ALLTYPES
92               } __SOCKADDR_ARG __attribute__ ((__transparent_union__));
93 # undef __SOCKADDR_ONETYPE
94 # define __SOCKADDR_ONETYPE(type) const struct type *__restrict __##type##__;
95 typedef union { __SOCKADDR_ALLTYPES
96               } __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__));
97 # undef __SOCKADDR_ONETYPE
98 #endif
99
100
101 /* Create a new socket of type TYPE in domain DOMAIN, using
102    protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
103    Returns a file descriptor for the new socket, or -1 for errors.  */
104 extern int socket (int __domain, int __type, int __protocol) __THROW;
105 libc_hidden_proto(socket)
106
107 /* Create two new sockets, of type TYPE in domain DOMAIN and using
108    protocol PROTOCOL, which are connected to each other, and put file
109    descriptors for them in FDS[0] and FDS[1].  If PROTOCOL is zero,
110    one will be chosen automatically.  Returns 0 on success, -1 for errors.  */
111 extern int socketpair (int __domain, int __type, int __protocol,
112                        int __fds[2]) __THROW;
113
114 /* Give the socket FD the local address ADDR (which is LEN bytes long).  */
115 extern int bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
116      __THROW;
117 libc_hidden_proto(bind)
118
119 /* Put the local address of FD into *ADDR and its length in *LEN.  */
120 extern int getsockname (int __fd, __SOCKADDR_ARG __addr,
121                         socklen_t *__restrict __len) __THROW;
122 libc_hidden_proto(getsockname)
123
124 /* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
125    For connectionless socket types, just set the default address to send to
126    and the only address from which to accept transmissions.
127    Return 0 on success, -1 for errors.
128
129    This function is a cancellation point and therefore not marked with
130    __THROW.  */
131 extern int connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
132 libc_hidden_proto(connect)
133
134 /* Put the address of the peer connected to socket FD into *ADDR
135    (which is *LEN bytes long), and its actual length into *LEN.  */
136 extern int getpeername (int __fd, __SOCKADDR_ARG __addr,
137                         socklen_t *__restrict __len) __THROW;
138
139
140 /* Send N bytes of BUF to socket FD.  Returns the number sent or -1.
141
142    This function is a cancellation point and therefore not marked with
143    __THROW.  */
144 extern ssize_t send (int __fd, const void *__buf, size_t __n, int __flags);
145 libc_hidden_proto(send)
146
147 /* Read N bytes into BUF from socket FD.
148    Returns the number read or -1 for errors.
149
150    This function is a cancellation point and therefore not marked with
151    __THROW.  */
152 extern ssize_t recv (int __fd, void *__buf, size_t __n, int __flags);
153 libc_hidden_proto(recv)
154
155 /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
156    ADDR_LEN bytes long).  Returns the number sent, or -1 for errors.
157
158    This function is a cancellation point and therefore not marked with
159    __THROW.  */
160 extern ssize_t sendto (int __fd, const void *__buf, size_t __n,
161                        int __flags, __CONST_SOCKADDR_ARG __addr,
162                        socklen_t __addr_len);
163 #ifdef _LIBC
164 extern __typeof(sendto) __sendto_nocancel attribute_hidden;
165 libc_hidden_proto(sendto)
166 #endif
167
168 /* Read N bytes into BUF through socket FD.
169    If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
170    the sender, and store the actual size of the address in *ADDR_LEN.
171    Returns the number of bytes read or -1 for errors.
172
173    This function is a cancellation point and therefore not marked with
174    __THROW.  */
175 extern ssize_t recvfrom (int __fd, void *__restrict __buf, size_t __n,
176                          int __flags, __SOCKADDR_ARG __addr,
177                          socklen_t *__restrict __addr_len);
178 #ifdef _LIBC
179 extern __typeof(recvfrom) __recvfrom_nocancel attribute_hidden;
180 libc_hidden_proto(recvfrom)
181 #endif
182
183
184 /* Send a message described MESSAGE on socket FD.
185    Returns the number of bytes sent, or -1 for errors.
186
187    This function is a cancellation point and therefore not marked with
188    __THROW.  */
189 extern ssize_t sendmsg (int __fd, const struct msghdr *__message,
190                         int __flags);
191 libc_hidden_proto(sendmsg)
192
193 /* Receive a message as described by MESSAGE from socket FD.
194    Returns the number of bytes read or -1 for errors.
195
196    This function is a cancellation point and therefore not marked with
197    __THROW.  */
198 extern ssize_t recvmsg (int __fd, struct msghdr *__message, int __flags);
199 libc_hidden_proto(recvmsg)
200
201
202 /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
203    into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
204    actual length.  Returns 0 on success, -1 for errors.  */
205 extern int getsockopt (int __fd, int __level, int __optname,
206                        void *__restrict __optval,
207                        socklen_t *__restrict __optlen) __THROW;
208
209 /* Set socket FD's option OPTNAME at protocol level LEVEL
210    to *OPTVAL (which is OPTLEN bytes long).
211    Returns 0 on success, -1 for errors.  */
212 extern int setsockopt (int __fd, int __level, int __optname,
213                        const void *__optval, socklen_t __optlen) __THROW;
214 libc_hidden_proto(setsockopt)
215
216
217 /* Prepare to accept connections on socket FD.
218    N connection requests will be queued before further requests are refused.
219    Returns 0 on success, -1 for errors.  */
220 extern int listen (int __fd, int __n) __THROW;
221 libc_hidden_proto(listen)
222
223 /* Await a connection on socket FD.
224    When a connection arrives, open a new socket to communicate with it,
225    set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
226    peer and *ADDR_LEN to the address's actual length, and return the
227    new socket's descriptor, or -1 for errors.
228
229    This function is a cancellation point and therefore not marked with
230    __THROW.  */
231 extern int accept (int __fd, __SOCKADDR_ARG __addr,
232                    socklen_t *__restrict __addr_len);
233 libc_hidden_proto(accept)
234
235 #if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU
236 /* Similar to 'accept' but takes an additional parameter to specify flags.
237
238    This function is a cancellation point and therefore not marked with
239    __THROW.  */
240 extern int accept4 (int __fd, __SOCKADDR_ARG __addr,
241                     socklen_t *__restrict __addr_len, int __flags);
242 #endif
243
244 /* Shut down all or part of the connection open on socket FD.
245    HOW determines what to shut down:
246      SHUT_RD   = No more receptions;
247      SHUT_WR   = No more transmissions;
248      SHUT_RDWR = No more receptions or transmissions.
249    Returns 0 on success, -1 for errors.  */
250 extern int shutdown (int __fd, int __how) __THROW;
251
252
253 #if 0 /*def __USE_XOPEN2K*/
254 /* Determine wheter socket is at a out-of-band mark.  */
255 extern int sockatmark (int __fd) __THROW;
256 #endif
257
258
259 #ifdef __USE_MISC
260 /* FDTYPE is S_IFSOCK or another S_IF* macro defined in <sys/stat.h>;
261    returns 1 if FD is open on an object of the indicated type, 0 if not,
262    or -1 for errors (setting errno).  */
263 extern int isfdtype (int __fd, int __fdtype) __THROW;
264 #endif
265
266 __END_DECLS
267
268 #ifdef _LIBC
269 extern int __socketcall(int, unsigned long *) attribute_hidden;
270 #endif
271
272 #endif /* sys/socket.h */