1 /* Copyright (C) 1991, 1992 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, 1992 Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
21 #define _SYS_SOCKET_H 1
30 /* Types of sockets. */
33 SOCK_STREAM = 1, /* Sequenced, reliable, connection-based
35 SOCK_DGRAM = 2, /* Connectionless, unreliable datagrams
36 of fixed maximum length. */
37 SOCK_RAW = 3, /* Raw protocol interface. */
38 SOCK_RDM = 4, /* Reliably-delivered messages. */
39 SOCK_SEQPACKET = 5, /* Sequenced, reliable, connection-based,
40 datagrams of fixed maximum length. */
43 /* Protocol families. */
44 #define PF_UNSPEC 0 /* Unspecified. */
45 #define PF_UNIX 1 /* Local to host (pipes and unix-domain). */
46 #define PF_INET 2 /* IP protocol family. */
47 #define PF_IMPLINK 3 /* ARPAnet IMP protocol. */
48 #define PF_PUP 4 /* PUP protocols. */
49 #define PF_CHAOS 5 /* MIT Chaos protocols. */
50 #define PF_NS 6 /* Xerox NS protocols. */
51 #define PF_ISO 7 /* ISO protocols. */
53 #define PF_ECMA 8 /* ECMA protocols. */
54 #define PF_DATAKIT 9 /* AT&T Datakit protocols. */
55 #define PF_CCITT 10 /* CCITT protocols (X.25 et al). */
56 #define PF_SNA 11 /* IBM SNA protocol. */
57 #define PF_DECnet 12 /* DECnet protocols. */
58 #define PF_DLI 13 /* Direct data link interface. */
59 #define PF_LAT 14 /* DEC Local Area Transport protocol. */
60 #define PF_HYLINK 15 /* NSC Hyperchannel protocol. */
61 #define PF_APPLETALK 16 /* Don't use this. */
62 #define PF_ROUTE 17 /* Internal Routing Protocol. */
63 #define PF_LINK 18 /* Link layer interface. */
66 /* Address families. */
67 #define AF_UNSPEC PF_UNSPEC
68 #define AF_UNIX PF_UNIX
69 #define AF_INET PF_INET
70 #define AF_IMPLINK PF_IMPLINK
72 #define AF_CHAOS PF_CHAOS
76 #define AF_ECMA PF_ECMA
77 #define AF_DATAKIT PF_DATAKIT
78 #define AF_CCITT PF_CCITT
80 #define AF_DECnet PF_DECnet
83 #define AF_HYLINK PF_HYLINK
84 #define AF_APPLETALK PF_APPLETALK
85 #define AF_ROUTE PF_ROUTE
86 #define AF_LINK PF_LINK
90 /* Structure describing a generic socket address. */
93 unsigned short int sa_family; /* Address family. */
94 char sa_data[14]; /* Address data. */
98 /* Create a new socket of type TYPE in domain DOMAIN, using
99 protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.
100 Returns a file descriptor for the new socket, or -1 for errors. */
101 extern int socket __P ((int __domain, enum __socket_type __type,
104 /* Create two new sockets, of type TYPE in domain DOMAIN and using
105 protocol PROTOCOL, which are connected to each other, and put file
106 descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero,
107 one will be chosen automatically. Returns 0 on success, -1 for errors. */
108 extern int socketpair __P ((int __domain, enum __socket_type __type,
109 int __protocol, int __fds[2]));
111 /* Give the socket FD the local address ADDR (which is LEN bytes long). */
112 extern int bind __P ((int __fd, struct sockaddr * __addr, size_t __len));
114 /* Put the local address of FD into *ADDR and its length in *LEN. */
115 extern int getsockname __P ((int __fd, struct sockaddr * __addr,
118 /* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
119 For connectionless socket types, just set the default address to send to
120 and the only address from which to accept transmissions.
121 Return 0 on success, -1 for errors. */
122 extern int connect __P ((int __fd, struct sockaddr * __addr, size_t __len));
124 /* Put the address of the peer connected to socket FD into *ADDR
125 (which is *LEN bytes long), and its actual length into *LEN. */
126 extern int getpeername __P ((int __fd, struct sockaddr * __addr,
130 /* Bits in the FLAGS argument to `send', `recv', et al. */
133 MSG_OOB = 1, /* Process out-of-band data. */
134 MSG_PEEK = 2, /* Peek at incoming messages. */
135 MSG_DONTROUTE = 4, /* Don't use local routing. */
138 /* Send N bytes of BUF to socket FD. Returns the number sent or -1. */
139 extern int send __P ((int __fd, __ptr_t __buf, size_t __n, int __flags));
141 /* Read N bytes into BUF from socket FD.
142 Returns the number read or -1 for errors. */
143 extern int recv __P ((int __fd, __ptr_t __buf, size_t __n, int __flags));
145 /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
146 ADDR_LEN bytes long). Returns the number sent, or -1 for errors. */
147 extern int sendto __P ((int __fd, __ptr_t __buf, size_t __n, int __flags,
148 struct sockaddr * __addr, size_t __addr_len));
150 /* Read N bytes into BUF through socket FD.
151 If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
152 the sender, and store the actual size of the address in *ADDR_LEN.
153 Returns the number of bytes read or -1 for errors. */
154 extern int recvfrom __P ((int __fd, __ptr_t __buf, size_t __n, int __flags,
155 struct sockaddr * __addr, size_t * __addr_len));
159 /* Structure describing messages sent by
160 `sendmsg' and received by `recvmsg'. */
163 __ptr_t msg_name; /* Address to send to/receive from. */
164 size_t msg_namelen; /* Length of address data. */
166 struct iovec *msg_iov; /* Vector of data to send/receive into. */
167 size_t msg_iovlen; /* Number of elements in the vector. */
169 __ptr_t msg_accrights; /* Access rights information. */
170 size_t msg_accrightslen; /* Length of access rights information. */
173 /* Send a message described MESSAGE on socket FD.
174 Returns the number of bytes sent, or -1 for errors. */
175 extern int sendmsg __P ((int __fd, __const struct msghdr * __message,
178 /* Receive a message as described by MESSAGE from socket FD.
179 Returns the number of bytes read or -1 for errors. */
180 extern int recvmsg __P ((int __fd, struct msghdr * __message, int __flags));
183 /* Protocol number used to manipulate socket-level options
184 with `getsockopt' and `setsockopt'. */
185 #define SOL_SOCKET 0xffff
187 /* Socket-level options for `getsockopt' and `setsockopt'. */
190 SO_DEBUG = 0x0001, /* Record debugging information. */
191 SO_ACCEPTCONN = 0x0002, /* Accept connections on socket. */
192 SO_REUSEADDR = 0x0004, /* Allow reuse of local addresses. */
193 SO_KEEPALIVE = 0x0008, /* Keep connections alive and send
194 SIGPIPE when they die. */
195 SO_DONTROUTE = 0x0010, /* Don't do local routing. */
196 SO_BROADCAST = 0x0020, /* Allow transmission of
197 broadcast messages. */
198 SO_USELOOPBACK = 0x0040, /* Use the software loopback to avoid
199 hardware use when possible. */
200 SO_LINGER = 0x0080, /* Block on close of a reliable
201 socket to transmit pending data. */
202 SO_OOBINLINE = 0x0100, /* Receive out-of-band data in-band. */
204 SO_SNDBUF = 0x1001, /* Send buffer size. */
205 SO_RCVBUF = 0x1002, /* Receive buffer. */
206 SO_SNDLOWAT = 0x1003, /* Send low-water mark. */
207 SO_RCVLOWAT = 0x1004, /* Receive low-water mark. */
208 SO_SNDTIMEO = 0x1005, /* Send timeout. */
209 SO_RCVTIMEO = 0x1006, /* Receive timeout. */
211 SO_ERROR = 0x1007, /* Get and clear error status. */
212 SO_TYPE = 0x1008, /* Get socket type. */
215 /* Structure used to manipulate the SO_LINGER option. */
218 int l_onoff; /* Nonzero to linger on close. */
219 int l_linger; /* Time to linger. */
223 /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
224 into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
225 actual length. Returns 0 on success, -1 for errors. */
226 extern int getsockopt __P ((int __fd, int __level, int __optname,
227 __ptr_t __optval, size_t * __optlen));
229 /* Set socket FD's option OPTNAME at protocol level LEVEL
230 to *OPTVAL (which is OPTLEN bytes long).
231 Returns 0 on success, -1 for errors. */
232 extern int setsockopt __P ((int __fd, int __level, int __optname,
233 __ptr_t __optval, size_t __optlen));
236 /* Prepare to accept connections on socket FD.
237 N connection requests will be queued before further requests are refused.
238 Returns 0 on success, -1 for errors. */
239 extern int listen __P ((int __fd, unsigned int __n));
241 /* Await a connection on socket FD.
242 When a connection arrives, open a new socket to communicate with it,
243 set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
244 peer and *ADDR_LEN to the address's actual length, and return the
245 new socket's descriptor, or -1 for errors. */
246 extern int accept __P ((int __fd, struct sockaddr * __addr,
247 size_t * __addr_len));
249 /* Shut down all or part of the connection open on socket FD.
250 HOW determines what to shut down:
251 0 = No more receptions;
252 1 = No more transmissions;
253 2 = No more receptions or transmissions.
254 Returns 0 on success, -1 for errors. */
255 extern int shutdown __P ((int __fd, int __how));
260 #endif /* sys/socket.h */