Tue Jul 9 09:37:55 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[glibc.git] / sysdeps / unix / sysv / linux / sys / socket.h
bloba680d5fb29fefa5480187e9070ebc82cea664a90
1 /* Copyright (C) 1991, 92, 94, 95, 96 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. */
19 #ifndef _SYS_SOCKET_H
21 #define _SYS_SOCKET_H 1
22 #include <features.h>
24 __BEGIN_DECLS
26 #define __need_size_t
27 #include <stddef.h>
30 /* Get Linux specific constants and data types. */
31 #include <linux/socket.h>
33 /* This is the type we use for generic socket address arguments.
35 With GCC 2.7 and later, the funky union causes redeclarations or uses with
36 any of the listed types to be allowed without complaint. */
37 #if (!defined (__GNUC__) || __GNUC__ < 2 || \
38 (__GNUC__ == 2 && __GNUC_MINOR__ < 7))
39 #define __SOCKADDR_ARG struct sockaddr *
40 #define __CONST_SOCKADDR_ARG __const struct sockaddr *
41 #else
42 /* Add more `struct sockaddr_AF' types here as necessary.
43 These are all the ones I found on NetBSD and Linux. */
44 #define __SOCKADDR_ALLTYPES \
45 __SOCKADDR_ONETYPE (sockaddr) \
46 __SOCKADDR_ONETYPE (sockaddr_at) \
47 __SOCKADDR_ONETYPE (sockaddr_ax25) \
48 __SOCKADDR_ONETYPE (sockaddr_dl) \
49 __SOCKADDR_ONETYPE (sockaddr_eon) \
50 __SOCKADDR_ONETYPE (sockaddr_in) \
51 __SOCKADDR_ONETYPE (sockaddr_in6) \
52 __SOCKADDR_ONETYPE (sockaddr_inarp) \
53 __SOCKADDR_ONETYPE (sockaddr_ipx) \
54 __SOCKADDR_ONETYPE (sockaddr_iso) \
55 __SOCKADDR_ONETYPE (sockaddr_ns) \
56 __SOCKADDR_ONETYPE (sockaddr_un) \
57 __SOCKADDR_ONETYPE (sockaddr_x25)
59 #define __SOCKADDR_ONETYPE(type) struct type *__##type##__;
60 typedef union { __SOCKADDR_ALLTYPES
61 } __SOCKADDR_ARG __attribute__ ((__transparent_union__));
62 #undef __SOCKADDR_ONETYPE
63 #define __SOCKADDR_ONETYPE(type) __const struct type *__##type##__;
64 typedef union { __SOCKADDR_ALLTYPES
65 } __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__));
66 #undef __SOCKADDR_ONETYPE
67 #endif
70 /* Create a new socket of type TYPE in domain DOMAIN, using
71 protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.
72 Returns a file descriptor for the new socket, or -1 for errors. */
73 extern int socket __P ((int __domain, int __type, int __protocol));
75 /* Create two new sockets, of type TYPE in domain DOMAIN and using
76 protocol PROTOCOL, which are connected to each other, and put file
77 descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero,
78 one will be chosen automatically. Returns 0 on success, -1 for errors. */
79 extern int socketpair __P ((int __domain, int __type, int __protocol,
80 int __fds[2]));
82 /* Give the socket FD the local address ADDR (which is LEN bytes long). */
83 extern int bind __P ((int __fd, __CONST_SOCKADDR_ARG __addr, size_t __len));
85 /* Put the local address of FD into *ADDR and its length in *LEN. */
86 extern int getsockname __P ((int __fd, __SOCKADDR_ARG __addr,
87 size_t *__len));
89 /* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
90 For connectionless socket types, just set the default address to send to
91 and the only address from which to accept transmissions.
92 Return 0 on success, -1 for errors. */
93 extern int connect __P ((int __fd,
94 __CONST_SOCKADDR_ARG __addr, size_t __len));
96 /* Put the address of the peer connected to socket FD into *ADDR
97 (which is *LEN bytes long), and its actual length into *LEN. */
98 extern int getpeername __P ((int __fd, __SOCKADDR_ARG __addr,
99 size_t *__len));
102 /* Send N bytes of BUF to socket FD. Returns the number sent or -1. */
103 extern int send __P ((int __fd, __ptr_t __buf, size_t __n, int __flags));
105 /* Read N bytes into BUF from socket FD.
106 Returns the number read or -1 for errors. */
107 extern int recv __P ((int __fd, __ptr_t __buf, size_t __n, int __flags));
109 /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
110 ADDR_LEN bytes long). Returns the number sent, or -1 for errors. */
111 extern int sendto __P ((int __fd, __ptr_t __buf, size_t __n, int __flags,
112 __CONST_SOCKADDR_ARG __addr, size_t __addr_len));
114 /* Read N bytes into BUF through socket FD.
115 If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
116 the sender, and store the actual size of the address in *ADDR_LEN.
117 Returns the number of bytes read or -1 for errors. */
118 extern int recvfrom __P ((int __fd, __ptr_t __buf, size_t __n, int __flags,
119 __SOCKADDR_ARG __addr, size_t *__addr_len));
122 /* Send a message described MESSAGE on socket FD.
123 Returns the number of bytes sent, or -1 for errors. */
124 extern int sendmsg __P ((int __fd, __const struct msghdr *__message,
125 int __flags));
127 /* Receive a message as described by MESSAGE from socket FD.
128 Returns the number of bytes read or -1 for errors. */
129 extern int recvmsg __P ((int __fd, struct msghdr *__message, int __flags));
132 /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
133 into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
134 actual length. Returns 0 on success, -1 for errors. */
135 extern int getsockopt __P ((int __fd, int __level, int __optname,
136 __ptr_t __optval, size_t *__optlen));
138 /* Set socket FD's option OPTNAME at protocol level LEVEL
139 to *OPTVAL (which is OPTLEN bytes long).
140 Returns 0 on success, -1 for errors. */
141 extern int setsockopt __P ((int __fd, int __level, int __optname,
142 __ptr_t __optval, size_t __optlen));
145 /* Prepare to accept connections on socket FD.
146 N connection requests will be queued before further requests are refused.
147 Returns 0 on success, -1 for errors. */
148 extern int listen __P ((int __fd, unsigned int __n));
150 /* Await a connection on socket FD.
151 When a connection arrives, open a new socket to communicate with it,
152 set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
153 peer and *ADDR_LEN to the address's actual length, and return the
154 new socket's descriptor, or -1 for errors. */
155 extern int accept __P ((int __fd, __SOCKADDR_ARG __addr,
156 size_t *__addr_len));
158 /* Shut down all or part of the connection open on socket FD.
159 HOW determines what to shut down:
160 0 = No more receptions;
161 1 = No more transmissions;
162 2 = No more receptions or transmissions.
163 Returns 0 on success, -1 for errors. */
164 extern int shutdown __P ((int __fd, int __how));
167 __END_DECLS
169 #endif /* sys/socket.h */