about summary refs log tree commit diff
path: root/include/sys/socket.h
blob: ec088572bd214c15b5078efb5abffdecf365d2db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef _SYS_SOCKET_H
#include <socket/sys/socket.h>

#ifndef _ISOMAC
/* Now define the internal interfaces.  */

/* Create a new socket of type TYPE in domain DOMAIN, using
   protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
   Returns a file descriptor for the new socket, or -1 for errors.  */
extern int __socket (int __domain, int __type,
		     int __protocol) attribute_hidden;

/* Create two new sockets, of type TYPE in domain DOMAIN and using
   protocol PROTOCOL, which are connected to each other, and put file
   descriptors for them in FDS[0] and FDS[1].  If PROTOCOL is zero,
   one will be chosen automatically.  Returns 0 on success, -1 for errors.  */
extern int __socketpair (int __domain, int __type, int __protocol,
			 int __fds[2]) attribute_hidden;

/* Return a socket of any type.  The socket can be used in subsequent
   ioctl calls to talk to the kernel.  */
extern int __opensock (void) internal_function attribute_hidden;

/* Put the address of the peer connected to socket FD into *ADDR
   (which is *LEN bytes long), and its actual length into *LEN.  */
extern int __getpeername (int __fd, __SOCKADDR_ARG __addr,
			  socklen_t *__len) attribute_hidden;

/* Send N bytes of BUF to socket FD.  Returns the number sent or -1.  */
extern ssize_t __libc_send (int __fd, const void *__buf, size_t __n,
			    int __flags);
extern ssize_t __send (int __fd, const void *__buf, size_t __n, int __flags);
libc_hidden_proto (__send)

/* Read N bytes into BUF from socket FD.
   Returns the number read or -1 for errors.  */
extern ssize_t __libc_recv (int __fd, void *__buf, size_t __n, int __flags);

/* Send N bytes of BUF on socket FD to peer at address ADDR (which is
   ADDR_LEN bytes long).  Returns the number sent, or -1 for errors.  */
extern ssize_t __libc_sendto (int __fd, const void *__buf, size_t __n,
			      int __flags, __CONST_SOCKADDR_ARG __addr,
			      socklen_t __addr_len);

/* Read N bytes into BUF through socket FD.
   If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
   the sender, and store the actual size of the address in *ADDR_LEN.
   Returns the number of bytes read or -1 for errors.  */
extern ssize_t __libc_recvfrom (int __fd, void *__restrict __buf, size_t __n,
				int __flags, __SOCKADDR_ARG __addr,
				socklen_t *__restrict __addr_len);

/* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
   For connectionless socket types, just set the default address to send to
   and the only address from which to accept transmissions.
   Return 0 on success, -1 for errors.  */
extern int __libc_connect (int __fd, __CONST_SOCKADDR_ARG __addr,
			   socklen_t __len);
extern int __connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
libc_hidden_proto (__connect)

/* Read N bytes into BUF from socket FD.
   Returns the number read or -1 for errors.

   This function is a cancellation point and therefore not marked with
   __THROW.  */
extern ssize_t __recv (int __fd, void *__buf, size_t __n, int __flags)
     attribute_hidden;

/* Send N bytes of BUF on socket FD to peer at address ADDR (which is
   ADDR_LEN bytes long).  Returns the number sent, or -1 for errors.  */
extern ssize_t __libc_sendto (int __fd, const void *__buf, size_t __n,
			      int __flags, __CONST_SOCKADDR_ARG __addr,
			      socklen_t __addr_len);
extern ssize_t __sendto (int __fd, const void *__buf, size_t __n,
			 int __flags, __CONST_SOCKADDR_ARG __addr,
			 socklen_t __addr_len) attribute_hidden;

/* Read N bytes into BUF through socket FD.
   If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
   the sender, and store the actual size of the address in *ADDR_LEN.
   Returns the number of bytes read or -1 for errors.  */
extern ssize_t __recvfrom (int __fd, void *__restrict __buf, size_t __n,
			   int __flags, __SOCKADDR_ARG __addr,
			   socklen_t *__restrict __addr_len) attribute_hidden;

/* Send a message described MESSAGE on socket FD.
   Returns the number of bytes sent, or -1 for errors.  */
extern ssize_t __libc_sendmsg (int __fd, const struct msghdr *__message,
			       int __flags);
extern ssize_t __sendmsg (int __fd, const struct msghdr *__message,
			  int __flags) attribute_hidden;

/* Receive a message as described by MESSAGE from socket FD.
   Returns the number of bytes read or -1 for errors.  */
extern ssize_t __libc_recvmsg (int __fd, struct msghdr *__message,
			       int __flags);
extern ssize_t __recvmsg (int __fd, struct msghdr *__message,
			  int __flags) attribute_hidden;

/* Set socket FD's option OPTNAME at protocol level LEVEL
   to *OPTVAL (which is OPTLEN bytes long).
   Returns 0 on success, -1 for errors.  */
extern int __setsockopt (int __fd, int __level, int __optname,
			 const void *__optval,
			 socklen_t __optlen) attribute_hidden;

/* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
   into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
   actual length.  Returns 0 on success, -1 for errors.  */
extern int __getsockopt (int __fd, int __level, int __optname,
			 void *__restrict __optval,
			 socklen_t *__restrict __optlen) attribute_hidden;

/* Put the local address of FD into *ADDR and its length in *LEN.  */
extern int __getsockname (int __fd, __SOCKADDR_ARG __addr,
			  socklen_t *__restrict __len) attribute_hidden;

/* Give the socket FD the local address ADDR (which is LEN bytes long).  */
extern int __bind (int __fd, __CONST_SOCKADDR_ARG __addr,
		   socklen_t __len) attribute_hidden;

/* Prepare to accept connections on socket FD.
   N connection requests will be queued before further requests are refused.
   Returns 0 on success, -1 for errors.  */
extern int __listen (int __fd, int __n) attribute_hidden;

/* Await a connection on socket FD.
   When a connection arrives, open a new socket to communicate with it,
   set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
   peer and *ADDR_LEN to the address's actual length, and return the
   new socket's descriptor, or -1 for errors.  */
extern int __libc_accept (int __fd, __SOCKADDR_ARG __addr,
			  socklen_t *__restrict __addr_len)
     __THROW attribute_hidden;
libc_hidden_proto (accept)
extern int __libc_accept4 (int __fd, __SOCKADDR_ARG __addr,
			   socklen_t *__restrict __addr_len, int __flags)
     __THROW attribute_hidden;

/* Return the length of a `sockaddr' structure.  */
#ifdef _HAVE_SA_LEN
# define SA_LEN(_x)      (_x)->sa_len
#else
extern int __libc_sa_len (sa_family_t __af);
libc_hidden_proto (__libc_sa_len)
# define SA_LEN(_x)      __libc_sa_len((_x)->sa_family)
#endif

#ifdef SOCK_CLOEXEC
extern int __have_sock_cloexec attribute_hidden;
/* At lot of other functionality became available at the same time as
   SOCK_CLOEXEC.  Avoid defining separate variables for all of them
   unless it is really necessary.  */
# define __have_paccept __have_sock_cloexec
#endif

#endif
#endif