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