1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
21 #define _SYS_SOCKET_H 1
28 /* Types of sockets. */
31 SOCK_STREAM = 1, /* Sequenced, reliable, connection-based
33 SOCK_DGRAM = 2, /* Connectionless, unreliable datagrams
34 of fixed maximum length. */
35 SOCK_RAW = 3, /* Raw protocol interface. */
36 SOCK_RDM = 4, /* Reliably-delivered messages. */
37 SOCK_SEQPACKET = 5, /* Sequenced, reliable, connection-based,
38 datagrams of fixed maximum length. */
41 /* Protocol families. */
42 #define PF_UNSPEC 0 /* Unspecified. */
43 #define PF_UNIX 1 /* Local to host (pipes and unix-domain). */
44 #define PF_INET 2 /* IP protocol family. */
45 #define PF_IMPLINK 3 /* ARPAnet IMP protocol. */
46 #define PF_PUP 4 /* PUP protocols. */
47 #define PF_CHAOS 5 /* MIT Chaos protocols. */
48 #define PF_NS 6 /* Xerox NS protocols. */
49 #define PF_NBS 7 /* NBS/NIST protocols. */
50 #define PF_ECMA 8 /* ECMA protocols. */
51 #define PF_DATAKIT 9 /* AT&T Datakit protocols. */
52 #define PF_CCITT 10 /* CCITT protocols (X.25 et al). */
53 #define PF_SNA 11 /* IBM SNA protocol. */
54 #define PF_DECnet 12 /* DECnet protocols. */
55 #define PF_DLI 13 /* Direct data link interface. */
56 #define PF_LAT 14 /* DEC Local Area Transport protocol. */
57 #define PF_HYLINK 15 /* NSC Hyperchannel protocol. */
60 /* Address families. */
61 #define AF_UNSPEC PF_UNSPEC
62 #define AF_UNIX PF_UNIX
63 #define AF_INET PF_INET
64 #define AF_IMPLINK PF_IMPLINK
66 #define AF_CHAOS PF_CHAOS
69 #define AF_ECMA PF_ECMA
70 #define AF_DATAKIT PF_DATAKIT
71 #define AF_CCITT PF_CCITT
73 #define AF_DECnet PF_DECnet
76 #define AF_HYLINK PF_HYLINK
80 /* Structure describing a generic socket address. */
83 unsigned short int sa_family; /* Address family. */
84 char sa_data[14]; /* Address data. */
88 /* Create a new socket of type TYPE in domain DOMAIN, using
89 protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.
90 Returns a file descriptor for the new socket, or -1 for errors. */
91 extern int EXFUN(socket, (int __domain, enum __socket_type __type,
94 /* Create two new sockets, of type TYPE in domain DOMAIN and using
95 protocol PROTOCOL, which are connected to each other, and put file
96 descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero,
97 one will be chosen automatically. Returns 0 on success, -1 for errors. */
98 extern int EXFUN(socketpair, (int __domain, enum __socket_type __type,
99 int __protocol, int __fds[2]));
101 /* Give the socket FD the local address ADDR (which is LEN bytes long). */
102 extern int EXFUN(bind, (int __fd, struct sockaddr *__addr, size_t __len));
104 /* Put the local address of FD into *ADDR and its length in *LEN. */
105 extern int EXFUN(getsockname, (int __fd, struct sockaddr *__addr,
108 /* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
109 For connectionless socket types, just set the default address to send to
110 and the only address from which to accept transmissions.
111 Return 0 on success, -1 for errors. */
112 extern int EXFUN(connect, (int __fd, struct sockaddr *__addr, size_t __len));
114 /* Put the address of the peer connected to socket FD into *ADDR
115 (which is *LEN bytes long), and its actual length into *LEN. */
116 extern int EXFUN(getpeername, (int __fd, struct sockaddr *__addr,
120 /* Bits in the FLAGS argument to `send', `recv', et al. */
123 MSG_OOB = 1, /* Process out-of-band data. */
124 MSG_PEEK = 2, /* Peek at incoming messages. */
125 MSG_DONTROUTE = 4, /* Don't use local routing. */
128 /* Send N bytes of BUF to socket FD. Returns the number sent or -1. */
129 extern int EXFUN(send, (int __fd, PTR __buf, size_t __n, int __flags));
131 /* Read N bytes into BUF from socket FD.
132 Returns the number read or -1 for errors. */
133 extern int EXFUN(recv, (int __fd, PTR __buf, size_t __n, int __flags));
135 /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
136 ADDR_LEN bytes long). Returns the number sent, or -1 for errors. */
137 extern int EXFUN(sendto, (int __fd, PTR __buf, size_t __n, int __flags,
138 struct sockaddr *__addr, size_t __addr_len));
140 /* Read N bytes into BUF through socket FD.
141 If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
142 the sender, and store the actual size of the address in *ADDR_LEN.
143 Returns the number of bytes read or -1 for errors. */
144 extern int EXFUN(recvfrom, (int __fd, PTR __buf, size_t __n, int __flags,
145 struct sockaddr *__addr, size_t *__addr_len));
149 /* Structure describing messages sent by
150 `sendmsg' and received by `recvmsg'. */
153 PTR msg_name; /* Address to send to/receive from. */
154 size_t msg_namelen; /* Length of address data. */
156 struct iovec *msg_iov; /* Vector of data to send/receive into. */
157 size_t msg_iovlen; /* Number of elements in the vector. */
159 PTR msg_accrights; /* Access rights information. */
160 size_t msg_accrightslen; /* Length of access rights information. */
163 /* Send a message described MESSAGE on socket FD.
164 Returns the number of bytes sent, or -1 for errors. */
165 extern int EXFUN(sendmsg, (int __fd, CONST struct msghdr *__message,
168 /* Receive a message as described by MESSAGE from socket FD.
169 Returns the number of bytes read or -1 for errors. */
170 extern int EXFUN(recvmsg, (int __fd, struct msghdr *__message, int __flags));
173 /* Protocol number used to manipulate socket-level options
174 with `getsockopt' and `setsockopt'. */
175 #define SOL_SOCKET 0xffff
177 /* Socket-level options for `getsockopt' and `setsockopt'. */
180 SO_DEBUG = 0x0001, /* Record debugging information. */
181 SO_ACCEPTCONN = 0x0002, /* Accept connections on socket. */
182 SO_REUSEADDR = 0x0004, /* Allow reuse of local addresses. */
183 SO_KEEPALIVE = 0x0008, /* Keep connections alive and send
184 SIGPIPE when they die. */
185 SO_DONTROUTE = 0x0010, /* Don't do local routing. */
186 SO_BROADCAST = 0x0020, /* Allow transmission of
187 broadcast messages. */
188 SO_USELOOPBACK = 0x0040, /* Use the software loopback to avoid
189 hardware use when possible. */
190 SO_LINGER = 0x0080, /* Block on close of a reliable
191 socket to transmit pending data. */
192 SO_OOBINLINE = 0x0100, /* Receive out-of-band data in-band. */
194 SO_SNDBUF = 0x1001, /* Send buffer size. */
195 SO_RCVBUF = 0x1002, /* Receive buffer. */
196 SO_SNDLOWAT = 0x1003, /* Send low-water mark. */
197 SO_RCVLOWAT = 0x1004, /* Receive low-water mark. */
198 SO_SNDTIMEO = 0x1005, /* Send timeout. */
199 SO_RCVTIMEO = 0x1006, /* Receive timeout. */
201 SO_ERROR = 0x1007, /* Get and clear error status. */
202 SO_TYPE = 0x1008, /* Get socket type. */
205 /* Structure used to manipulate the SO_LINGER option. */
208 int l_onoff; /* Nonzero to linger on close. */
209 int l_linger; /* Time to linger. */
213 /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
214 into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
215 actual length. Returns 0 on success, -1 for errors. */
216 extern int EXFUN(getsockopt, (int __fd, int __level, int __optname,
217 PTR __optval, size_t *__optlen));
219 /* Set socket FD's option OPTNAME at protocol level LEVEL
220 to *OPTVAL (which is OPTLEN bytes long).
221 Returns 0 on success, -1 for errors. */
222 extern int EXFUN(setsockopt, (int __fd, int __level, int __optname,
223 PTR __optval, size_t __optlen));
226 /* Prepare to accept connections on socket FD.
227 N connection requests will be queued before further requests are refused.
228 Returns 0 on success, -1 for errors. */
229 extern int EXFUN(listen, (int __fd, unsigned int __n));
231 /* Await a connection on socket FD.
232 When a connection arrives, open a new socket to communicate with it,
233 set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
234 peer and *ADDR_LEN to the address's actual length, and return the
235 new socket's descriptor, or -1 for errors. */
236 extern int EXFUN(accept, (int __fd, struct sockaddr *__addr,
237 size_t *__addr_len));
239 /* Shut down all or part of the connection open on socket FD.
240 HOW determines what to shut down:
241 0 = No more receptions;
242 1 = No more transmissions;
243 2 = No more receptions or transmissions.
244 Returns 0 on success, -1 for errors. */
245 extern int EXFUN(shutdown, (int __fd, int __how));
248 #endif /* sys/socket.h */