Updated to fedora-glibc-20080728T2320
[glibc.git] / include / sys / socket.h
blobdf892783a0a8f5912ca6040a1ceb85e71cf29fbb
1 #ifndef _SYS_SOCKET_H
2 #include <socket/sys/socket.h>
4 /* Now define the internal interfaces. */
6 /* Create a new socket of type TYPE in domain DOMAIN, using
7 protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.
8 Returns a file descriptor for the new socket, or -1 for errors. */
9 extern int __socket (int __domain, int __type,
10 int __protocol) attribute_hidden;
12 /* Create two new sockets, of type TYPE in domain DOMAIN and using
13 protocol PROTOCOL, which are connected to each other, and put file
14 descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero,
15 one will be chosen automatically. Returns 0 on success, -1 for errors. */
16 extern int __socketpair (int __domain, int __type, int __protocol,
17 int __fds[2]) attribute_hidden;
19 /* Return a socket of any type. The socket can be used in subsequent
20 ioctl calls to talk to the kernel. */
21 extern int __opensock (void) internal_function attribute_hidden;
23 /* Put the address of the peer connected to socket FD into *ADDR
24 (which is *LEN bytes long), and its actual length into *LEN. */
25 extern int __getpeername (int __fd, __SOCKADDR_ARG __addr,
26 socklen_t *__len) attribute_hidden;
28 /* Send N bytes of BUF to socket FD. Returns the number sent or -1. */
29 extern ssize_t __libc_send (int __fd, __const void *__buf, size_t __n,
30 int __flags);
31 extern ssize_t __send (int __fd, __const void *__buf, size_t __n, int __flags);
32 libc_hidden_proto (__send)
34 /* Read N bytes into BUF from socket FD.
35 Returns the number read or -1 for errors. */
36 extern ssize_t __libc_recv (int __fd, void *__buf, size_t __n, int __flags);
38 /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
39 ADDR_LEN bytes long). Returns the number sent, or -1 for errors. */
40 extern ssize_t __libc_sendto (int __fd, __const void *__buf, size_t __n,
41 int __flags, __CONST_SOCKADDR_ARG __addr,
42 socklen_t __addr_len);
44 /* Read N bytes into BUF through socket FD.
45 If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
46 the sender, and store the actual size of the address in *ADDR_LEN.
47 Returns the number of bytes read or -1 for errors. */
48 extern ssize_t __libc_recvfrom (int __fd, void *__restrict __buf, size_t __n,
49 int __flags, __SOCKADDR_ARG __addr,
50 socklen_t *__restrict __addr_len);
52 /* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
53 For connectionless socket types, just set the default address to send to
54 and the only address from which to accept transmissions.
55 Return 0 on success, -1 for errors. */
56 extern int __libc_connect (int __fd, __CONST_SOCKADDR_ARG __addr,
57 socklen_t __len);
58 extern int __connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
59 extern int __connect_internal (int __fd, __CONST_SOCKADDR_ARG __addr,
60 socklen_t __len) attribute_hidden;
62 /* Read N bytes into BUF from socket FD.
63 Returns the number read or -1 for errors.
65 This function is a cancellation point and therefore not marked with
66 __THROW. */
67 extern ssize_t __recv (int __fd, void *__buf, size_t __n, int __flags)
68 attribute_hidden;
70 /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
71 ADDR_LEN bytes long). Returns the number sent, or -1 for errors. */
72 extern ssize_t __libc_sendto (int __fd, __const void *__buf, size_t __n,
73 int __flags, __CONST_SOCKADDR_ARG __addr,
74 socklen_t __addr_len);
75 extern ssize_t __sendto (int __fd, __const void *__buf, size_t __n,
76 int __flags, __CONST_SOCKADDR_ARG __addr,
77 socklen_t __addr_len) attribute_hidden;
79 /* Read N bytes into BUF through socket FD.
80 If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
81 the sender, and store the actual size of the address in *ADDR_LEN.
82 Returns the number of bytes read or -1 for errors. */
83 extern ssize_t __recvfrom (int __fd, void *__restrict __buf, size_t __n,
84 int __flags, __SOCKADDR_ARG __addr,
85 socklen_t *__restrict __addr_len) attribute_hidden;
87 /* Send a message described MESSAGE on socket FD.
88 Returns the number of bytes sent, or -1 for errors. */
89 extern ssize_t __libc_sendmsg (int __fd, __const struct msghdr *__message,
90 int __flags);
91 extern ssize_t __sendmsg (int __fd, __const struct msghdr *__message,
92 int __flags) attribute_hidden;
94 /* Receive a message as described by MESSAGE from socket FD.
95 Returns the number of bytes read or -1 for errors. */
96 extern ssize_t __libc_recvmsg (int __fd, struct msghdr *__message,
97 int __flags);
98 extern ssize_t __recvmsg (int __fd, struct msghdr *__message,
99 int __flags) attribute_hidden;
101 /* Set socket FD's option OPTNAME at protocol level LEVEL
102 to *OPTVAL (which is OPTLEN bytes long).
103 Returns 0 on success, -1 for errors. */
104 extern int __setsockopt (int __fd, int __level, int __optname,
105 __const void *__optval,
106 socklen_t __optlen) attribute_hidden;
108 /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
109 into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
110 actual length. Returns 0 on success, -1 for errors. */
111 extern int __getsockopt (int __fd, int __level, int __optname,
112 void *__restrict __optval,
113 socklen_t *__restrict __optlen) attribute_hidden;
115 /* Put the local address of FD into *ADDR and its length in *LEN. */
116 extern int __getsockname (int __fd, __SOCKADDR_ARG __addr,
117 socklen_t *__restrict __len) attribute_hidden;
119 /* Give the socket FD the local address ADDR (which is LEN bytes long). */
120 extern int __bind (int __fd, __CONST_SOCKADDR_ARG __addr,
121 socklen_t __len) attribute_hidden;
123 /* Prepare to accept connections on socket FD.
124 N connection requests will be queued before further requests are refused.
125 Returns 0 on success, -1 for errors. */
126 extern int __listen (int __fd, int __n) attribute_hidden;
128 /* Await a connection on socket FD.
129 When a connection arrives, open a new socket to communicate with it,
130 set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
131 peer and *ADDR_LEN to the address's actual length, and return the
132 new socket's descriptor, or -1 for errors. */
133 extern int __libc_accept (int __fd, __SOCKADDR_ARG __addr,
134 socklen_t *__restrict __addr_len)
135 __THROW;
136 libc_hidden_proto (accept)
138 /* Return the length of a `sockaddr' structure. */
139 #ifdef _HAVE_SA_LEN
140 # define SA_LEN(_x) (_x)->sa_len
141 #else
142 extern int __libc_sa_len (sa_family_t __af);
143 extern int __libc_sa_len_internal (sa_family_t __af) attribute_hidden;
144 # ifndef NOT_IN_libc
145 # define SA_LEN(_x) INTUSE(__libc_sa_len)((_x)->sa_family)
146 # else
147 # define SA_LEN(_x) __libc_sa_len((_x)->sa_family)
148 # endif
149 #endif
152 #ifndef NOT_IN_libc
153 # define __connect(fd, addr, len) INTUSE(__connect) (fd, addr, len)
154 #endif
156 #ifdef SOCK_CLOEXEC
157 extern int __have_sock_cloexec;
158 /* At lot of other functionality became available at the same time as
159 SOCK_CLOEXEC. Avoid defining separate variables for all of them
160 unless it is really necessary. */
161 # define __have_paccept __have_sock_cloexec
162 #endif
164 #endif