Watt-32 tcp/ip  2.2 dev-rel.10
socket.h
Go to the documentation of this file.
1 
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/pack_on.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 #define MSG_NOSIGNAL 0x80 /* don't raise SIGPIPE on reset */
225 
226 #define MSG_MAXIOVLEN 16
227 
228 
229 /*
230  * Header for ancillary data objects in msg_control buffer.
231  * Used for additional information with/about a datagram
232  * not expressible by flags. The format is a sequence
233  * of message elements headed by cmsghdr structures.
234  */
235 struct cmsghdr {
236  u_int cmsg_len; /* data byte count, including hdr */
237  int cmsg_level; /* originating protocol */
238  int cmsg_type; /* protocol-specific type */
239  /* followed by u_char cmsg_data[]; */
240  };
241 
242 struct msghdr {
243  char *msg_name; /* Contains an optional address. */
244  int msg_namelen; /* len of optional address */
245  struct iovec *msg_iov; /* scatter/gather array. */
246  int msg_iovlen; /* number of elements in msg_iov */
247  char *msg_accrights; /* does not apply to IP - not changed */
248  int msg_accrightslen; /* does not apply to IP */
249  };
250 
251 /* CMSG_DATA clashes with <wincrypt.h>
252  */
253 #if (defined(WIN32) || defined(_WIN32)) && !defined(__CYGWIN__) && \
254  !defined(_WINDOWS_H) && !defined(_INC_WINDOWS) && !defined(__windows_h__)
255  #error Include <windows.h> before this point.
256 #endif
257 
258 /* given pointer to 'struct cmsghdr', return pointer to data
259  */
260 #undef CMSG_DATA
261 #define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1))
262 
263 /* given pointer to 'struct msghdr', return pointer to next 'msghdr'
264  */
265 #define CMSG_NXTHDR(mhdr, cmsg) \
266  (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
267  (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
268  (struct cmsghdr *)NULL : \
269  (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
270 
271 #define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
272 
273 /* "Socket"-level control message types: */
274 #define SCM_RIGHTS 0x01 /* access rights (array of int) */
275 
276 #include <sys/pack_off.h>
277 
278 __BEGIN_DECLS
279 
280 W32_FUNC int W32_CALL accept (int, struct sockaddr *, int *);
281 W32_FUNC int W32_CALL bind (int, const struct sockaddr *, int);
282 W32_FUNC int W32_CALL closesocket (int s);
283 W32_FUNC int W32_CALL connect (int, const struct sockaddr *, int);
284 W32_FUNC int W32_CALL ioctlsocket (int s, long cmd, char *argp);
285 W32_FUNC int MS_CDECL fcntlsocket (int s, int cmd, ...);
286 
287 W32_FUNC int W32_CALL getdomainname (char *name, size_t len);
288 W32_FUNC int W32_CALL setdomainname (const char *name, size_t len);
289 
290 W32_FUNC int W32_CALL getpeername (int, struct sockaddr *, int *);
291 W32_FUNC int W32_CALL getsockname (int, struct sockaddr *, int *);
292 W32_FUNC int W32_CALL getsockopt (int, int, int, void *, int *);
293 W32_FUNC int W32_CALL listen (int, int);
294 W32_FUNC int W32_CALL recv (int, void *, int, int);
295 W32_FUNC int W32_CALL recvfrom (int, void *, int, int, struct sockaddr *, int *);
296 W32_FUNC int W32_CALL recvmsg (int, struct msghdr *, 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 sendmsg (int, const struct msghdr *, int);
300 
301 W32_FUNC int W32_CALL setsockopt (int, int, int, const void *, int);
302 W32_FUNC int W32_CALL shutdown (int, int);
303 W32_FUNC int W32_CALL socket (int, int, int);
304 
305 #ifdef __DJGPP__
306  W32_FUNC int W32_CALL gethostname (char *name, int len);
307 #else
308  W32_FUNC int W32_CALL gethostname (char *name, size_t len);
309 #endif
310 
311 #if defined(__CYGWIN__)
312  /* CygWin's <unistd.h> doesn't agree with other vendors here.
313  */
314  W32_FUNC long W32_CALL gethostid (void);
315  W32_FUNC long W32_CALL sethostid (u_long ip);
316  W32_FUNC int W32_CALL sethostname (const char *name, size_t len);
317 #else
318  W32_FUNC u_long W32_CALL gethostid (void);
319  W32_FUNC u_long W32_CALL sethostid (u_long ip);
320  W32_FUNC int W32_CALL sethostname (const char *name, int len);
321 #endif
322 
323 __END_DECLS
324 
325 #endif
W32_FUNC int W32_CALL getdomainname(char *name, size_t len)
BSD-style: Return domain name of this host.
Definition: bsdname.c:186
W32_FUNC int MS_CDECL fcntlsocket(int s, int cmd,...)
Definition: fcntl.c:69
W32_FUNC int W32_CALL setdomainname(const char *name, size_t len)
BSD-style: Set the host's domain name.
Definition: bsdname.c:213
Definition: socket.h:242
W32_FUNC long W32_CALL gethostid(void)
BSD style: returns local IPv4-address.
Definition: bsdname.c:68
W32_FUNC int W32_CALL bind(int, const struct sockaddr *, int)
bind() - bind name to socket.
Definition: bind.c:63
Definition: ip.h:67
int W32_CALL sethostname(const char *fqdn, SETHOSTNAME_ARG2 len)
BSD-style: Expects a "Fully Qualified Domain Name" in `fqdn'.
Definition: bsdname.c:293
Definition: socket.h:127
Definition: wtypes.h:179
W32_FUNC int W32_CALL shutdown(int, int)
Definition: shutdown.c:46
__BEGIN_DECLS W32_FUNC int W32_CALL accept(int, struct sockaddr *, int *)
Definition: accept.c:59
XHOSTID_RETV W32_CALL sethostid(DWORD ip)
BSD-style: Sets local IPv4-address.
Definition: bsdname.c:79
W32_FUNC int W32_CALL socket(int, int, int)
socket().
Definition: socket.c:1794