]> git.ipfire.org Git - thirdparty/glibc.git/blame - socket/sys/socket.h
Update.
[thirdparty/glibc.git] / socket / sys / socket.h
CommitLineData
07a4742f 1/* Declarations of socket constants, types, and functions.
390955cb 2 Copyright (C) 1991,92,94,95,96,97,98,99 Free Software Foundation, Inc.
54d79e99
UD
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
0e3426bb
RM
19
20#ifndef _SYS_SOCKET_H
0e3426bb 21#define _SYS_SOCKET_H 1
5107cf1d 22
0e3426bb
RM
23#include <features.h>
24
25__BEGIN_DECLS
26
27#define __need_size_t
28#include <stddef.h>
29
30
07a4742f
RM
31/* This operating system-specific header file defines the SOCK_*, PF_*,
32 AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr',
33 `struct msghdr', and `struct linger' types. */
5107cf1d 34#include <bits/socket.h>
07a4742f 35
2064087b
RM
36#ifdef __USE_BSD
37/* This is the 4.3 BSD `struct sockaddr' format, which is used as wire
38 format in the grotty old 4.3 `talk' protocol. */
39struct osockaddr
40 {
41 unsigned short int sa_family;
42 unsigned char sa_data[14];
43 };
44#endif
0e3426bb
RM
45
46/* This is the type we use for generic socket address arguments.
47
a3e59be8
UD
48 With GCC 2.7 and later, the funky union causes redeclarations or
49 uses with any of the listed types to be allowed without complaint.
50 G++ 2.7 does not support transparent unions so there we want the
51 old-style declaration, too. */
55c14926 52#if (!defined __GNUC__ || __GNUC__ < 2 || defined __cplusplus || \
0e3426bb 53 (__GNUC__ == 2 && __GNUC_MINOR__ < 7))
55c14926
UD
54# define __SOCKADDR_ARG struct sockaddr *
55# define __CONST_SOCKADDR_ARG __const struct sockaddr *
0e3426bb
RM
56#else
57/* Add more `struct sockaddr_AF' types here as necessary.
58 These are all the ones I found on NetBSD and Linux. */
55c14926 59# define __SOCKADDR_ALLTYPES \
0e3426bb
RM
60 __SOCKADDR_ONETYPE (sockaddr) \
61 __SOCKADDR_ONETYPE (sockaddr_at) \
62 __SOCKADDR_ONETYPE (sockaddr_ax25) \
63 __SOCKADDR_ONETYPE (sockaddr_dl) \
64 __SOCKADDR_ONETYPE (sockaddr_eon) \
65 __SOCKADDR_ONETYPE (sockaddr_in) \
66 __SOCKADDR_ONETYPE (sockaddr_in6) \
67 __SOCKADDR_ONETYPE (sockaddr_inarp) \
68 __SOCKADDR_ONETYPE (sockaddr_ipx) \
69 __SOCKADDR_ONETYPE (sockaddr_iso) \
70 __SOCKADDR_ONETYPE (sockaddr_ns) \
71 __SOCKADDR_ONETYPE (sockaddr_un) \
72 __SOCKADDR_ONETYPE (sockaddr_x25)
73
55c14926 74# define __SOCKADDR_ONETYPE(type) struct type *__##type##__;
0e3426bb
RM
75typedef union { __SOCKADDR_ALLTYPES
76 } __SOCKADDR_ARG __attribute__ ((__transparent_union__));
55c14926
UD
77# undef __SOCKADDR_ONETYPE
78# define __SOCKADDR_ONETYPE(type) __const struct type *__##type##__;
0e3426bb
RM
79typedef union { __SOCKADDR_ALLTYPES
80 } __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__));
55c14926 81# undef __SOCKADDR_ONETYPE
0e3426bb
RM
82#endif
83
84
85/* Create a new socket of type TYPE in domain DOMAIN, using
86 protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.
87 Returns a file descriptor for the new socket, or -1 for errors. */
88extern int socket __P ((int __domain, int __type, int __protocol));
89
90/* Create two new sockets, of type TYPE in domain DOMAIN and using
91 protocol PROTOCOL, which are connected to each other, and put file
92 descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero,
93 one will be chosen automatically. Returns 0 on success, -1 for errors. */
94extern int socketpair __P ((int __domain, int __type, int __protocol,
95 int __fds[2]));
96
97/* Give the socket FD the local address ADDR (which is LEN bytes long). */
55c14926 98extern int bind __P ((int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len));
0e3426bb
RM
99
100/* Put the local address of FD into *ADDR and its length in *LEN. */
101extern int getsockname __P ((int __fd, __SOCKADDR_ARG __addr,
55c14926 102 socklen_t *__len));
0e3426bb
RM
103
104/* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
105 For connectionless socket types, just set the default address to send to
106 and the only address from which to accept transmissions.
107 Return 0 on success, -1 for errors. */
07a4742f 108extern int __connect __P ((int __fd,
55c14926 109 __CONST_SOCKADDR_ARG __addr, socklen_t __len));
0e3426bb 110extern int connect __P ((int __fd,
55c14926 111 __CONST_SOCKADDR_ARG __addr, socklen_t __len));
0e3426bb
RM
112
113/* Put the address of the peer connected to socket FD into *ADDR
114 (which is *LEN bytes long), and its actual length into *LEN. */
115extern int getpeername __P ((int __fd, __SOCKADDR_ARG __addr,
40a55d20 116 socklen_t *__len));
0e3426bb
RM
117
118
119/* Send N bytes of BUF to socket FD. Returns the number sent or -1. */
a5113b14
UD
120extern int __send __P ((int __fd, __const __ptr_t __buf, size_t __n,
121 int __flags));
122extern int send __P ((int __fd, __const __ptr_t __buf, size_t __n,
123 int __flags));
0e3426bb
RM
124
125/* Read N bytes into BUF from socket FD.
126 Returns the number read or -1 for errors. */
127extern int recv __P ((int __fd, __ptr_t __buf, size_t __n, int __flags));
128
129/* Send N bytes of BUF on socket FD to peer at address ADDR (which is
130 ADDR_LEN bytes long). Returns the number sent, or -1 for errors. */
a5113b14
UD
131extern int sendto __P ((int __fd, __const __ptr_t __buf, size_t __n,
132 int __flags, __CONST_SOCKADDR_ARG __addr,
55c14926 133 socklen_t __addr_len));
0e3426bb
RM
134
135/* Read N bytes into BUF through socket FD.
136 If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
137 the sender, and store the actual size of the address in *ADDR_LEN.
138 Returns the number of bytes read or -1 for errors. */
139extern int recvfrom __P ((int __fd, __ptr_t __buf, size_t __n, int __flags,
55c14926 140 __SOCKADDR_ARG __addr, socklen_t *__addr_len));
0e3426bb
RM
141
142
143/* Send a message described MESSAGE on socket FD.
144 Returns the number of bytes sent, or -1 for errors. */
145extern int sendmsg __P ((int __fd, __const struct msghdr *__message,
146 int __flags));
147
148/* Receive a message as described by MESSAGE from socket FD.
149 Returns the number of bytes read or -1 for errors. */
150extern int recvmsg __P ((int __fd, struct msghdr *__message, int __flags));
151
152
153/* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
154 into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
155 actual length. Returns 0 on success, -1 for errors. */
156extern int getsockopt __P ((int __fd, int __level, int __optname,
55c14926 157 __ptr_t __optval, socklen_t *__optlen));
0e3426bb
RM
158
159/* Set socket FD's option OPTNAME at protocol level LEVEL
160 to *OPTVAL (which is OPTLEN bytes long).
161 Returns 0 on success, -1 for errors. */
162extern int setsockopt __P ((int __fd, int __level, int __optname,
14ea22e9 163 __const __ptr_t __optval, socklen_t __optlen));
0e3426bb
RM
164
165
166/* Prepare to accept connections on socket FD.
167 N connection requests will be queued before further requests are refused.
168 Returns 0 on success, -1 for errors. */
169extern int listen __P ((int __fd, unsigned int __n));
170
171/* Await a connection on socket FD.
172 When a connection arrives, open a new socket to communicate with it,
173 set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
174 peer and *ADDR_LEN to the address's actual length, and return the
175 new socket's descriptor, or -1 for errors. */
176extern int accept __P ((int __fd, __SOCKADDR_ARG __addr,
55c14926 177 socklen_t *__addr_len));
0e3426bb
RM
178
179/* Shut down all or part of the connection open on socket FD.
180 HOW determines what to shut down:
181 0 = No more receptions;
182 1 = No more transmissions;
183 2 = No more receptions or transmissions.
184 Returns 0 on success, -1 for errors. */
185extern int shutdown __P ((int __fd, int __how));
186
187
07a4742f
RM
188/* FDTYPE is S_IFSOCK or another S_IF* macro defined in <sys/stat.h>;
189 returns 1 if FD is open on an object of the indicated type, 0 if not,
190 or -1 for errors (setting errno). */
191extern int isfdtype __P ((int __fd, int __fdtype));
192
0e3426bb
RM
193__END_DECLS
194
195#endif /* sys/socket.h */