]>
Commit | Line | Data |
---|---|---|
07a4742f RM |
1 | /* Declarations of socket constants, types, and functions. |
2 | Copyright (C) 1991, 92, 94, 95, 96 Free Software Foundation, Inc. | |
0e3426bb RM |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Library General Public License as | |
7 | published by the Free Software Foundation; either version 2 of the | |
8 | License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Library General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Library General Public | |
16 | License along with the GNU C Library; see the file COPYING.LIB. If | |
17 | not, write to the Free Software Foundation, Inc., 675 Mass Ave, | |
18 | Cambridge, MA 02139, USA. */ | |
19 | ||
20 | #ifndef _SYS_SOCKET_H | |
21 | ||
22 | #define _SYS_SOCKET_H 1 | |
23 | #include <features.h> | |
24 | ||
25 | __BEGIN_DECLS | |
26 | ||
27 | #define __need_size_t | |
28 | #include <stddef.h> | |
29 | ||
30 | ||
07a4742f RM |
31 | /* This operating system-specific header file defines the SOCK_*, PF_*, |
32 | AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr', | |
33 | `struct msghdr', and `struct linger' types. */ | |
34 | #include <socketbits.h> | |
35 | ||
0e3426bb RM |
36 | |
37 | /* This is the type we use for generic socket address arguments. | |
38 | ||
39 | With GCC 2.7 and later, the funky union causes redeclarations or uses with | |
40 | any of the listed types to be allowed without complaint. */ | |
41 | #if (!defined (__GNUC__) || __GNUC__ < 2 || \ | |
42 | (__GNUC__ == 2 && __GNUC_MINOR__ < 7)) | |
43 | #define __SOCKADDR_ARG struct sockaddr * | |
44 | #define __CONST_SOCKADDR_ARG __const struct sockaddr * | |
45 | #else | |
46 | /* Add more `struct sockaddr_AF' types here as necessary. | |
47 | These are all the ones I found on NetBSD and Linux. */ | |
48 | #define __SOCKADDR_ALLTYPES \ | |
49 | __SOCKADDR_ONETYPE (sockaddr) \ | |
50 | __SOCKADDR_ONETYPE (sockaddr_at) \ | |
51 | __SOCKADDR_ONETYPE (sockaddr_ax25) \ | |
52 | __SOCKADDR_ONETYPE (sockaddr_dl) \ | |
53 | __SOCKADDR_ONETYPE (sockaddr_eon) \ | |
54 | __SOCKADDR_ONETYPE (sockaddr_in) \ | |
55 | __SOCKADDR_ONETYPE (sockaddr_in6) \ | |
56 | __SOCKADDR_ONETYPE (sockaddr_inarp) \ | |
57 | __SOCKADDR_ONETYPE (sockaddr_ipx) \ | |
58 | __SOCKADDR_ONETYPE (sockaddr_iso) \ | |
59 | __SOCKADDR_ONETYPE (sockaddr_ns) \ | |
60 | __SOCKADDR_ONETYPE (sockaddr_un) \ | |
61 | __SOCKADDR_ONETYPE (sockaddr_x25) | |
62 | ||
63 | #define __SOCKADDR_ONETYPE(type) struct type *__##type##__; | |
64 | typedef union { __SOCKADDR_ALLTYPES | |
65 | } __SOCKADDR_ARG __attribute__ ((__transparent_union__)); | |
66 | #undef __SOCKADDR_ONETYPE | |
67 | #define __SOCKADDR_ONETYPE(type) __const struct type *__##type##__; | |
68 | typedef union { __SOCKADDR_ALLTYPES | |
69 | } __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__)); | |
70 | #undef __SOCKADDR_ONETYPE | |
71 | #endif | |
72 | ||
73 | ||
74 | /* Create a new socket of type TYPE in domain DOMAIN, using | |
75 | protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically. | |
76 | Returns a file descriptor for the new socket, or -1 for errors. */ | |
77 | extern int socket __P ((int __domain, int __type, int __protocol)); | |
78 | ||
79 | /* Create two new sockets, of type TYPE in domain DOMAIN and using | |
80 | protocol PROTOCOL, which are connected to each other, and put file | |
81 | descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero, | |
82 | one will be chosen automatically. Returns 0 on success, -1 for errors. */ | |
83 | extern int socketpair __P ((int __domain, int __type, int __protocol, | |
84 | int __fds[2])); | |
85 | ||
86 | /* Give the socket FD the local address ADDR (which is LEN bytes long). */ | |
87 | extern int bind __P ((int __fd, __CONST_SOCKADDR_ARG __addr, size_t __len)); | |
88 | ||
89 | /* Put the local address of FD into *ADDR and its length in *LEN. */ | |
90 | extern int getsockname __P ((int __fd, __SOCKADDR_ARG __addr, | |
91 | size_t *__len)); | |
92 | ||
93 | /* Open a connection on socket FD to peer at ADDR (which LEN bytes long). | |
94 | For connectionless socket types, just set the default address to send to | |
95 | and the only address from which to accept transmissions. | |
96 | Return 0 on success, -1 for errors. */ | |
07a4742f RM |
97 | extern int __connect __P ((int __fd, |
98 | __CONST_SOCKADDR_ARG __addr, size_t __len)); | |
0e3426bb RM |
99 | extern int connect __P ((int __fd, |
100 | __CONST_SOCKADDR_ARG __addr, size_t __len)); | |
101 | ||
102 | /* Put the address of the peer connected to socket FD into *ADDR | |
103 | (which is *LEN bytes long), and its actual length into *LEN. */ | |
104 | extern int getpeername __P ((int __fd, __SOCKADDR_ARG __addr, | |
105 | size_t *__len)); | |
106 | ||
107 | ||
108 | /* Send N bytes of BUF to socket FD. Returns the number sent or -1. */ | |
07a4742f | 109 | extern int __send __P ((int __fd, __ptr_t __buf, size_t __n, int __flags)); |
0e3426bb RM |
110 | extern int send __P ((int __fd, __ptr_t __buf, size_t __n, int __flags)); |
111 | ||
112 | /* Read N bytes into BUF from socket FD. | |
113 | Returns the number read or -1 for errors. */ | |
114 | extern int recv __P ((int __fd, __ptr_t __buf, size_t __n, int __flags)); | |
115 | ||
116 | /* Send N bytes of BUF on socket FD to peer at address ADDR (which is | |
117 | ADDR_LEN bytes long). Returns the number sent, or -1 for errors. */ | |
118 | extern int sendto __P ((int __fd, __ptr_t __buf, size_t __n, int __flags, | |
119 | __CONST_SOCKADDR_ARG __addr, size_t __addr_len)); | |
120 | ||
121 | /* Read N bytes into BUF through socket FD. | |
122 | If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of | |
123 | the sender, and store the actual size of the address in *ADDR_LEN. | |
124 | Returns the number of bytes read or -1 for errors. */ | |
125 | extern int recvfrom __P ((int __fd, __ptr_t __buf, size_t __n, int __flags, | |
126 | __SOCKADDR_ARG __addr, size_t *__addr_len)); | |
127 | ||
128 | ||
129 | /* Send a message described MESSAGE on socket FD. | |
130 | Returns the number of bytes sent, or -1 for errors. */ | |
131 | extern int sendmsg __P ((int __fd, __const struct msghdr *__message, | |
132 | int __flags)); | |
133 | ||
134 | /* Receive a message as described by MESSAGE from socket FD. | |
135 | Returns the number of bytes read or -1 for errors. */ | |
136 | extern int recvmsg __P ((int __fd, struct msghdr *__message, int __flags)); | |
137 | ||
138 | ||
139 | /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL | |
140 | into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's | |
141 | actual length. Returns 0 on success, -1 for errors. */ | |
142 | extern int getsockopt __P ((int __fd, int __level, int __optname, | |
143 | __ptr_t __optval, size_t *__optlen)); | |
144 | ||
145 | /* Set socket FD's option OPTNAME at protocol level LEVEL | |
146 | to *OPTVAL (which is OPTLEN bytes long). | |
147 | Returns 0 on success, -1 for errors. */ | |
148 | extern int setsockopt __P ((int __fd, int __level, int __optname, | |
149 | __ptr_t __optval, size_t __optlen)); | |
150 | ||
151 | ||
152 | /* Prepare to accept connections on socket FD. | |
153 | N connection requests will be queued before further requests are refused. | |
154 | Returns 0 on success, -1 for errors. */ | |
155 | extern int listen __P ((int __fd, unsigned int __n)); | |
156 | ||
157 | /* Await a connection on socket FD. | |
158 | When a connection arrives, open a new socket to communicate with it, | |
159 | set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting | |
160 | peer and *ADDR_LEN to the address's actual length, and return the | |
161 | new socket's descriptor, or -1 for errors. */ | |
162 | extern int accept __P ((int __fd, __SOCKADDR_ARG __addr, | |
163 | size_t *__addr_len)); | |
164 | ||
165 | /* Shut down all or part of the connection open on socket FD. | |
166 | HOW determines what to shut down: | |
167 | 0 = No more receptions; | |
168 | 1 = No more transmissions; | |
169 | 2 = No more receptions or transmissions. | |
170 | Returns 0 on success, -1 for errors. */ | |
171 | extern int shutdown __P ((int __fd, int __how)); | |
172 | ||
173 | ||
07a4742f RM |
174 | /* FDTYPE is S_IFSOCK or another S_IF* macro defined in <sys/stat.h>; |
175 | returns 1 if FD is open on an object of the indicated type, 0 if not, | |
176 | or -1 for errors (setting errno). */ | |
177 | extern int isfdtype __P ((int __fd, int __fdtype)); | |
178 | ||
0e3426bb RM |
179 | __END_DECLS |
180 | ||
181 | #endif /* sys/socket.h */ |