1 /* $Copyright:
2  *
3  * Copyright � 1998-1999 by the Massachusetts Institute of Technology.
4  *
5  * All rights reserved.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation for any purpose and without fee is hereby granted,
9  * provided that the above copyright notice appear in all copies and that
10  * both that copyright notice and this permission notice appear in
11  * supporting documentation, and that the name of M.I.T. not be used in
12  * advertising or publicity pertaining to distribution of the software
13  * without specific, written prior permission.  Furthermore if you modify
14  * this software you must label your software as modified software and not
15  * distribute it in such a fashion that it might be confused with the
16  * original MIT software. M.I.T. makes no representations about the
17  * suitability of this software for any purpose.  It is provided "as is"
18  * without express or implied warranty.
19  *
20  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
21  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
22  * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23  *
24  * Individual source code files are copyright MIT, Cygnus Support,
25  * OpenVision, Oracle, Sun Soft, FundsXpress, and others.
26  *
27  * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,
28  * and Zephyr are trademarks of the Massachusetts Institute of Technology
29  * (MIT).  No commercial use of these trademarks may be made without prior
30  * written permission of MIT.
31  *
32  * "Commercial use" means use of a name in a product or other for-profit
33  * manner.  It does NOT prevent a commercial firm from referring to the MIT
34  * trademarks in order to convey information (although in doing so,
35  * recognition of their trademark status should be given).
36  * $
37  */
38 
39 /* $Header: /src/NCBI/vault.ncbi/distrib/connect/mitsock/s_socket.h,v 1.1 2001/04/03 20:35:35 juran Exp $ */
40 
41 /*
42  *
43  * Sockets.h -- Main external header file for the sockets library.
44  *
45  */
46 
47 #include <unix.h>
48 #include <MacTypes.h>
49 #include <Events.h>
50 #include <OpenTptInternet.h>
51 #include "neti_in.h"
52 #include "s_types.h"
53 
54 #ifndef _SOCKETS_
55 #define _SOCKETS_
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 
62 /*******************/
63 /* API Definitions */
64 /*******************/
65 
66 #define FD_SETSIZE		256    	/*	The maximum # of sockets -- cannot be changed	*/
67 
68 /* socket types need to match PROTOCOLS in neti_in.h  */
69 #define SOCK_STREAM		1		/*	stream socket -- connection oriented 			*/
70 #define SOCK_DGRAM		2		/*	datagram socket -- connectionless				*/
71 #define SOCK_RAW		3		/*	raw socket 										*/
72 #define SOCK_RDM		4		/*	reliably delivered message socket				*/
73 #define SOCK_SEQPACKET	5		/*	sequenced packet socket							*/
74 
75 /*
76  * Option flags per-socket.
77  */
78 #define	SO_DEBUG		0x0001		/* turn on debugging info recording */
79 #define	SO_ACCEPTCONN	0x0002		/* socket has had listen() */
80 #define	SO_REUSEADDR	0x0004		/* allow local address reuse */
81 #define	SO_KEEPALIVE	0x0008		/* keep connections alive */
82 #define	SO_DONTROUTE	0x0010		/* just use interface addresses */
83 #define	SO_BROADCAST	0x0020		/* permit sending of broadcast msgs */
84 #define	SO_USELOOPBACK	0x0040		/* bypass hardware when possible */
85 #define	SO_LINGER		0x0080		/* linger on close if data present */
86 #define	SO_OOBINLINE	0x0100		/* leave received OOB data in line */
87 
88 /*
89  * Additional options, not kept in so_options.
90  */
91 #define SO_SNDBUF	0x1001		/* send buffer size */
92 #define SO_RCVBUF	0x1002		/* receive buffer size */
93 #define SO_SNDLOWAT	0x1003		/* send low-water mark */
94 #define SO_RCVLOWAT	0x1004		/* receive low-water mark */
95 #define SO_SNDTIMEO	0x1005		/* send timeout */
96 #define SO_RCVTIMEO	0x1006		/* receive timeout */
97 #define	SO_ERROR	0x1007		/* get error status and clear */
98 #define	SO_TYPE		0x1008		/* get socket type */
99 
100 /*
101  * Structure used for manipulating linger option.
102  */
103 struct	linger {
104 	long	l_onoff;		/* option on/off */
105 	long	l_linger;		/* linger time */
106 };
107 
108 /*
109  * Level number for (get/set)sockopt() to apply to socket itself.
110  */
111 #define	SOL_SOCKET	0xffff		/* options for socket level */
112 
113 /*
114  * address families
115  */
116 #define AF_UNSPEC		0		//	Unspecified
117 #define AF_UNIX			1		//	Unix internal protocols
118 #define AF_INET			2		//  also in OpenTransportProviders.h
119 #define	AF_IMPLINK		3		// arpanet imp addresses
120 #define	AF_PUP			4		// pup protocols: e.g. BSP
121 #define	AF_CHAOS		5		// mit CHAOS protocols
122 #define	AF_NS			6		// XEROX NS protocols
123 #define	AF_ISO			7		// ISO protocols
124 #define	AF_OSI			AF_ISO
125 #define	AF_ECMA			8		// european computer manufacturers
126 #define	AF_DATAKIT		9		// datakit protocols
127 #define	AF_CCITT		10		// CCITT protocols, X.25 etc
128 #define	AF_SNA			11		// IBM SNA
129 #define AF_DECnet		12		// DECnet
130 #define AF_DLI			13		// DEC Direct data link interface
131 #define AF_LAT			14		// LAT
132 #define	AF_HYLINK		15		// NSC Hyperchannel
133 #define	AF_APPLETALK	16		// Apple Talk
134 #define	AF_ROUTE		17		// Internal Routing Protocol
135 #define	AF_LINK			18		// Link layer interface
136 #define	pseudo_AF_XTP	19		// eXpress Transfer Protocol (no AF)
137 
138 /* protocol families */
139 #define PF_UNSPEC		AF_UNSPEC	//	Unspecified
140 #define PF_UNIX			AF_UNIX		//	Unix internal protocols
141 #define PF_INET			AF_INET		//	Internet protocols
142 #define	PF_IMPLINK		AF_IMPLINK
143 #define	PF_PUP			AF_PUP
144 #define	PF_CHAOS		AF_CHAOS
145 #define	PF_NS			AF_NS
146 #define	PF_ISO			AF_ISO
147 #define	PF_OSI			AF_ISO
148 #define	PF_ECMA			AF_ECMA
149 #define	PF_DATAKIT		AF_DATAKIT
150 #define	PF_CCITT		AF_CCITT
151 #define	PF_SNA			AF_SNA
152 #define PF_DECnet		AF_DECnet
153 #define PF_DLI			AF_DLI
154 #define PF_LAT			AF_LAT
155 #define	PF_HYLINK		AF_HYLINK
156 #define	PF_APPLETALK	AF_APPLETALK
157 #define	PF_ROUTE		AF_ROUTE
158 #define	PF_LINK			AF_LINK
159 #define	PF_XTP			pseudo_AF_XTP	/* really just proto family, no AF */
160 
161 /* IP Address Wildcard */
162 #ifndef	INADDR_ANY	// already in neti_in.h
163 #define INADDR_ANY      kOTAnyInetAddress
164 #endif
165 #define INADDR_NONE		0xffffffff
166 
167 /* recv and send flags */
168 #define MSG_DONTROUTE	1
169 #define MSG_DONTWAIT	2
170 #define MSG_OOB			4
171 #define MSG_PEEK		8
172 #define MSG_WAITALL		16
173 
174 /* s_fnctl() requests */
175 #define F_GETFL			3		/* Get file flags 									*/
176 #define F_SETFL			4		/* Set file flags 									*/
177 
178 /* shutdown() flags */
179 #define SHUT_RD			0		/* Shutdown read side of the connection				*/
180 #define SHUT_WR			1		/* Shutdown write side of the connection			*/
181 #define SHUT_RDWR		2		/* Shutdown read and write sides of the connection	*/
182 
183 /* IP address sizes */
184 #define INET_ADDRSTRLEN		16	/* for IPv4 dotted decimal							*/
185 #define INET6_ADDRSTRLEN	46	/* for IPv6 dhex string								*/
186 #define INADDRSZ			4	/* size of IPv4 addr in bytes 						*/
187 #define IN6ADDRSZ			16	/* size of IPv6 addr in bytes						*/
188 
189 /* host name size */
190 #define MAXHOSTNAMESIZE		kMaxHostNameLen
191 #define MAXHOSTNAMELEN		kMaxHostNameLen
192 
193 
194 /****************************/
195 /* API Structures and Types */
196 /****************************/
197 
198 /* An internet address */
199 typedef UInt32  in_addr_t;
200 
201 /* structure used to store addresses */
202 struct sockaddr {
203 	UInt16	sa_family;
204 	char	sa_data[14];
205 };
206 
207 /* INET protocol structures */
208 struct in_addr {
209 	in_addr_t	s_addr;
210 };
211 
212 /* A TCP address -- the same as a OT InetAddress */
213 struct sockaddr_in {				/* struct InetAddress {				*/
214 	UInt16			sin_family;		/* OTAddressType	fAddressType	*/
215 	UInt16			sin_port;		/* InetPort			fPort			*/
216 	struct in_addr 	sin_addr;		/* InetHost			fHost			*/
217 	char 			sin_zero[8];	/* UInt8			fUnused			*/
218 };									/* };								*/
219 
220 /* Structure for non-contiguous data */
221 struct iovec {
222   struct iovec *next;			/* For compatibility with Open Transport */
223   void         *iov_base;		/* Starting address of buffer */
224   size_t        iov_len;		/* size of buffer */
225 };
226 
227 /* For poll() */
228 struct pollfd {
229   int   fd;
230   short events;
231   short revents;
232 };
233 
234 /*
235  * Internal Function Prototypes
236  */
237 
238 #define SocketsLibIsPresent_ ((Ptr) socket != (Ptr) kUnresolvedCFragSymbolAddress)
239 
240 /* Sockets Control API calls */
241 OSStatus 			   AbortSocketOperation(int sockFD);
242 OSStatus 			   AbortAllDNSOperations(void);
243 Boolean                IsValidSocket(int sockFD);
244 
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 
250 #endif /* _SOCKETS_ */