(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / include / sys / socket.h
blob937909a1250068a4667d6f2c6dd62569bd1eab73
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 /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
63 ADDR_LEN bytes long). Returns the number sent, or -1 for errors. */
64 extern ssize_t __libc_sendto (int __fd, __const void *__buf, size_t __n,
65 int __flags, __CONST_SOCKADDR_ARG __addr,
66 socklen_t __addr_len);
67 extern ssize_t __sendto (int __fd, __const void *__buf, size_t __n,
68 int __flags, __CONST_SOCKADDR_ARG __addr,
69 socklen_t __addr_len) attribute_hidden;
71 /* Read N bytes into BUF through socket FD.
72 If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
73 the sender, and store the actual size of the address in *ADDR_LEN.
74 Returns the number of bytes read or -1 for errors. */
75 extern ssize_t __recvfrom (int __fd, void *__restrict __buf, size_t __n,
76 int __flags, __SOCKADDR_ARG __addr,
77 socklen_t *__restrict __addr_len) attribute_hidden;
79 /* Send a message described MESSAGE on socket FD.
80 Returns the number of bytes sent, or -1 for errors. */
81 extern ssize_t __libc_sendmsg (int __fd, __const struct msghdr *__message,
82 int __flags);
83 extern ssize_t __sendmsg (int __fd, __const struct msghdr *__message,
84 int __flags) attribute_hidden;
86 /* Receive a message as described by MESSAGE from socket FD.
87 Returns the number of bytes read or -1 for errors. */
88 extern ssize_t __libc_recvmsg (int __fd, struct msghdr *__message,
89 int __flags);
90 extern ssize_t __recvmsg (int __fd, struct msghdr *__message,
91 int __flags) attribute_hidden;
93 /* Set socket FD's option OPTNAME at protocol level LEVEL
94 to *OPTVAL (which is OPTLEN bytes long).
95 Returns 0 on success, -1 for errors. */
96 extern int __setsockopt (int __fd, int __level, int __optname,
97 __const void *__optval,
98 socklen_t __optlen) attribute_hidden;
100 /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
101 into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
102 actual length. Returns 0 on success, -1 for errors. */
103 extern int __getsockopt (int __fd, int __level, int __optname,
104 void *__restrict __optval,
105 socklen_t *__restrict __optlen) attribute_hidden;
107 /* Put the local address of FD into *ADDR and its length in *LEN. */
108 extern int __getsockname (int __fd, __SOCKADDR_ARG __addr,
109 socklen_t *__restrict __len) attribute_hidden;
111 /* Give the socket FD the local address ADDR (which is LEN bytes long). */
112 extern int __bind (int __fd, __CONST_SOCKADDR_ARG __addr,
113 socklen_t __len) attribute_hidden;
115 /* Prepare to accept connections on socket FD.
116 N connection requests will be queued before further requests are refused.
117 Returns 0 on success, -1 for errors. */
118 extern int __listen (int __fd, int __n) attribute_hidden;
120 /* Await a connection on socket FD.
121 When a connection arrives, open a new socket to communicate with it,
122 set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
123 peer and *ADDR_LEN to the address's actual length, and return the
124 new socket's descriptor, or -1 for errors. */
125 extern int __libc_accept (int __fd, __SOCKADDR_ARG __addr,
126 socklen_t *__restrict __addr_len)
127 __THROW;
128 libc_hidden_proto (accept)
130 /* Return the length of a `sockaddr' structure. */
131 #ifdef _HAVE_SA_LEN
132 # define SA_LEN(_x) (_x)->sa_len
133 #else
134 extern int __libc_sa_len (sa_family_t __af);
135 extern int __libc_sa_len_internal (sa_family_t __af) attribute_hidden;
136 # ifndef NOT_IN_libc
137 # define SA_LEN(_x) INTUSE(__libc_sa_len)((_x)->sa_family)
138 # else
139 # define SA_LEN(_x) __libc_sa_len((_x)->sa_family)
140 # endif
141 #endif
144 #ifndef NOT_IN_libc
145 # define __connect(fd, addr, len) INTUSE(__connect) (fd, addr, len)
146 #endif
148 #endif