Subversion Repositories SvarDOS

Rev

Rev 616 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
207 mateuszvis 1
/*!\file sys/socket.h
2
 *
3
 * BSD socket API.
4
 */
5
 
6
/* Modified for emx by hv and em 1994-1995
7
 *
8
 * Copyright (c) 1982,1985,1986,1988 Regents of the University of California.
9
 * All rights reserved.
10
 *
11
 * Redistribution and use in source and binary forms, with or without
12
 * modification, are permitted provided that the following conditions
13
 * are met:
14
 * 1. Redistributions of source code must retain the above copyright
15
 *    notice, this list of conditions and the following disclaimer.
16
 * 2. Redistributions in binary form must reproduce the above copyright
17
 *    notice, this list of conditions and the following disclaimer in the
18
 *    documentation and/or other materials provided with the distribution.
19
 * 3. All advertising materials mentioning features or use of this software
20
 *    must display the following acknowledgement:
21
 *      This product includes software developed by the University of
22
 *      California, Berkeley and its contributors.
23
 * 4. Neither the name of the University nor the names of its contributors
24
 *    may be used to endorse or promote products derived from this software
25
 *    without specific prior written permission.
26
 *
27
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37
 * SUCH DAMAGE.
38
 *
39
 *      from: @(#)socket.h      7.13 (Berkeley) 4/20/91
40
 *      $Id: socket.h,v 1.5 1993/06/27 05:59:06 andrew Exp $
41
 */
42
 
43
#ifndef __SYS_SOCKET_H
44
#define __SYS_SOCKET_H
45
 
46
#ifndef __SYS_W32API_H
47
#include <sys/w32api.h>
48
#endif
49
 
50
#ifndef __SYS_WERRNO_H
51
/*#include <sys/werrno.h>*/
52
#endif
53
 
54
#ifndef __SYS_CDEFS_H
55
#include <sys/cdefs.h>
56
#endif
57
 
58
#ifndef __SYS_WTYPES_H
59
#include <sys/wtypes.h>
60
#endif
61
 
62
#ifndef __SYS_WTIME_H
63
#include <sys/wtime.h>
64
#endif
65
 
66
#ifndef __NETINET_IN_H
67
#include <netinet/in.h>
68
#endif
69
 
70
/*
71
 * Definitions related to sockets: types, address families, options.
72
 */
73
 
74
/*
75
 * This is used instead of -1, since the socket type is signed.
76
 */
77
#define INVALID_SOCKET  (int)(~0)
78
#define SOCKET_ERROR    (-1)
79
 
80
/*
81
 * Types
82
 */
83
#define SOCK_STREAM     1               /* stream socket */
84
#define SOCK_DGRAM      2               /* datagram socket */
85
#define SOCK_RAW        3               /* raw-protocol interface */
86
#define SOCK_RDM        4               /* reliably-delivered message */
87
#define SOCK_SEQPACKET  5               /* sequenced packet stream */
88
#define SOCK_PACKET     10              /* linux specific way of        */
89
                                        /* getting packets at the dev   */
90
                                        /* level.  For writing rarp and */
91
                                        /* other similar things on the  */
92
                                        /* user level.                  */
93
 
94
/*
95
 * Option flags per-socket.
96
 */
97
#define SO_DEBUG        0x0001          /* turn on debugging info recording */
98
#define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
99
#define SO_REUSEADDR    0x0004          /* allow local address reuse */
100
#define SO_KEEPALIVE    0x0008          /* keep connections alive */
101
#define SO_DONTROUTE    0x0010          /* just use interface addresses */
102
#define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
103
#define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
104
#define SO_LINGER       0x0080          /* linger on close if data present */
105
#define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
106
 
107
#define SO_DONTLINGER   (int)(~SO_LINGER)
108
 
109
/*
110
 * Additional options, not kept in so_options.
111
 */
112
#define SO_SNDBUF       0x1001          /* send buffer size */
113
#define SO_RCVBUF       0x1002          /* receive buffer size */
114
#define SO_SNDLOWAT     0x1003          /* send low-water mark */
115
#define SO_RCVLOWAT     0x1004          /* receive low-water mark */
116
#define SO_SNDTIMEO     0x1005          /* send timeout */
117
#define SO_RCVTIMEO     0x1006          /* receive timeout */
118
#define SO_ERROR        0x1007          /* get error status and clear */
119
#define SO_TYPE         0x1008          /* get socket type */
120
 
121
 
122
#include <sys/packon.h>
123
 
124
/*
125
 * Structure used for manipulating linger option.
126
 */
127
struct linger {
128
       int l_onoff;                /* option on/off */
129
       int l_linger;               /* linger time */
130
     };
131
 
132
/*
133
 * Level number for (get/set)sockopt() to apply to socket itself.
134
 */
135
#define SOL_SOCKET      0xffff          /* options for socket level */
136
 
137
/*
138
 * Address families.
139
 */
140
#define AF_UNSPEC       0               /* unspecified */
141
#define AF_UNIX         1               /* local to host (pipes, portals) */
142
#define AF_INET         2               /* internetwork: UDP, TCP, etc. */
143
#define AF_IMPLINK      3               /* arpanet imp addresses */
144
#define AF_PUP          4               /* pup protocols: e.g. BSP */
145
#define AF_CHAOS        5               /* mit CHAOS protocols */
146
#define AF_NS           6               /* XEROX NS protocols */
147
#define AF_ISO          7               /* ISO protocols */
148
#define AF_OSI          AF_ISO
149
#define AF_ECMA         8               /* european computer manufacturers */
150
#define AF_DATAKIT      9               /* datakit protocols */
151
#define AF_CCITT        10              /* CCITT protocols, X.25 etc */
152
#define AF_SNA          11              /* IBM SNA */
153
#define AF_DECnet       12              /* DECnet */
154
#define AF_DLI          13              /* DEC Direct data link interface */
155
#define AF_LAT          14              /* LAT */
156
#define AF_HYLINK       15              /* NSC Hyperchannel */
157
#define AF_APPLETALK    16              /* Apple Talk */
158
#define AF_ROUTE        17              /* Internal Routing Protocol */
159
#define AF_LINK         18              /* Link layer interface */
160
#define pseudo_AF_XTP   19              /* eXpress Transfer Protocol (no AF) */
161
#define AF_INET6        24              /* IPv6 address family */
162
#define AF_PACKET       25              /* raw packets */
163
#define AF_MAX          26
164
 
165
/*
166
 * Structure used by kernel to store most
167
 * addresses.
168
 * is called struct osockaddr in 4.4BSD
169
 */
170
struct sockaddr {
171
       u_short sa_family;              /* address family */
172
       char    sa_data[14];            /* up to 14 bytes of direct address */
173
     };
174
 
175
/*
176
 * Structure used by kernel to pass protocol
177
 * information in raw sockets.
178
 */
179
struct sockproto {
180
       u_short sp_family;              /* address family */
181
       u_short sp_protocol;            /* protocol */
182
     };
183
 
184
/*
185
 * Protocol families, same as address families for now.
186
 */
187
#define PF_UNSPEC       AF_UNSPEC
188
#define PF_UNIX         AF_UNIX
189
#define PF_INET         AF_INET
190
#define PF_INET6        AF_INET6
191
#define PF_IMPLINK      AF_IMPLINK
192
#define PF_PUP          AF_PUP
193
#define PF_CHAOS        AF_CHAOS
194
#define PF_NS           AF_NS
195
#define PF_ISO          AF_ISO
196
#define PF_OSI          AF_ISO
197
#define PF_ECMA         AF_ECMA
198
#define PF_DATAKIT      AF_DATAKIT
199
#define PF_CCITT        AF_CCITT
200
#define PF_SNA          AF_SNA
201
#define PF_DECnet       AF_DECnet
202
#define PF_DLI          AF_DLI
203
#define PF_LAT          AF_LAT
204
#define PF_HYLINK       AF_HYLINK
205
#define PF_APPLETALK    AF_APPLETALK
206
#define PF_ROUTE        AF_ROUTE
207
#define PF_LINK         AF_LINK
208
#define PF_PACKET       AF_PACKET
209
#define PF_XTP          pseudo_AF_XTP   /* really just proto family, no AF */
210
 
211
#define PF_MAX          AF_MAX
212
 
213
/*
214
 * Maximum queue length specifiable by listen.
215
 */
216
#define SOMAXCONN       32
217
#define MSG_OOB         0x1             /* process out-of-band data */
218
#define MSG_PEEK        0x2             /* peek at incoming message */
219
#define MSG_DONTROUTE   0x4             /* send without using routing tables */
220
#define MSG_EOR         0x8             /* data completes record */
221
#define MSG_TRUNC       0x10            /* data discarded before delivery */
222
#define MSG_CTRUNC      0x20            /* control data lost before delivery */
223
#define MSG_WAITALL     0x40            /* wait for full request or error */
224
 
225
#define MSG_MAXIOVLEN   16
226
 
227
 
228
/*
229
 * Header for ancillary data objects in msg_control buffer.
230
 * Used for additional information with/about a datagram
231
 * not expressible by flags.  The format is a sequence
232
 * of message elements headed by cmsghdr structures.
233
 */
234
struct cmsghdr {
235
       u_int   cmsg_len;               /* data byte count, including hdr */
236
       int     cmsg_level;             /* originating protocol */
237
       int     cmsg_type;              /* protocol-specific type */
238
       /* followed by  u_char  cmsg_data[]; */
239
     };
240
 
241
struct msghdr {
242
       char         *msg_name;         /* Contains an optional address. */
243
       int           msg_namelen;      /* len of optional address */
244
       struct iovec *msg_iov;          /* scatter/gather array. */
245
       int           msg_iovlen;       /* number of elements in msg_iov */
246
       char         *msg_accrights;    /* does not apply to IP - not changed */
247
       int           msg_accrightslen; /* does not apply to IP */
248
     };
249
 
250
/* CMSG_DATA clashes with <wincrypt.h>
251
 */
252
#if (defined(WIN32) || defined(_WIN32)) && \
253
    !defined(_WINDOWS_H) && !defined(_INC_WINDOWS) && !defined(__windows_h__)
254
  #error Include <windows.h> before this point.
255
#endif
256
 
257
/* given pointer to struct adatahdr, return pointer to data */
258
#undef  CMSG_DATA
259
#define CMSG_DATA(cmsg)         ((u_char *)((cmsg) + 1))
260
 
261
/* given pointer to struct adatahdr, return pointer to next adatahdr */
262
#define CMSG_NXTHDR(mhdr, cmsg) \
263
        (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
264
            (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
265
            (struct cmsghdr *)NULL : \
266
            (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
267
 
268
#define CMSG_FIRSTHDR(mhdr)     ((struct cmsghdr *)(mhdr)->msg_control)
269
 
270
/* "Socket"-level control message types: */
271
#define SCM_RIGHTS      0x01            /* access rights (array of int) */
272
 
273
#include <sys/packoff.h>
274
 
275
__BEGIN_DECLS
276
 
277
W32_FUNC int    W32_CALL accept (int, struct sockaddr *, int *);
278
W32_FUNC int    W32_CALL bind (int, const struct sockaddr *, int);
279
W32_FUNC int    W32_CALL closesocket (int s);
280
W32_FUNC int    W32_CALL connect (int, const struct sockaddr *, int);
281
W32_FUNC int    W32_CALL ioctlsocket (int s, long cmd, char *argp);
282
W32_FUNC int    MS_CDECL fcntlsocket (int s, int cmd, ...);
283
 
284
W32_FUNC int    W32_CALL getdomainname (char *name, int len);
285
W32_FUNC int    W32_CALL setdomainname (const char *name, int len);
286
W32_FUNC int    W32_CALL gethostname (char *name, int len);
287
W32_FUNC int    W32_CALL sethostname (const char *name, int len);
288
 
289
W32_FUNC u_long W32_CALL gethostid (void);
290
W32_FUNC u_long W32_CALL sethostid (u_long ip);
291
W32_FUNC int    W32_CALL getpeername (int, struct sockaddr *, int *);
292
W32_FUNC int    W32_CALL getsockname (int, struct sockaddr *, int *);
293
W32_FUNC int    W32_CALL getsockopt (int, int, int, void *, int *);
294
W32_FUNC int    W32_CALL listen (int, int);
295
W32_FUNC int    W32_CALL recv (int, void *, int, int);
296
W32_FUNC int    W32_CALL recvfrom (int, void *, int, int, struct sockaddr *, int *);
297
W32_FUNC int    W32_CALL send (int, const void *, int, int);
298
W32_FUNC int    W32_CALL sendto (int, const void *, int, int, const struct sockaddr *, int);
299
W32_FUNC int    W32_CALL setsockopt (int, int, int, const void *, int);
300
W32_FUNC int    W32_CALL shutdown (int, int);
301
W32_FUNC int    W32_CALL socket (int, int, int);
302
 
303
__END_DECLS
304
 
305
#endif