1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License Version
6
* 1.1 (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is the Netscape Portable Runtime (NSPR).
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998-2000
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
#ifndef macksocket_h___
39
#define macksocket_h___
42
// Interface visible to xp code
43
// C socket type definitions and routines
46
#include <OpenTptInternet.h> // All the internet typedefs
47
#include <utime.h> // For timeval
49
* sleep and delay conflict with the same in unistd.h from Metrowerks. OT
52
* extern pascal void OTDelay(UInt32 seconds);
53
* extern pascal void OTIdle(void);
55
* #define sleep(x) OTDelay(x)
56
* #define delay(x) OTDelay(x)
67
unsigned char sa_len; /* total length */
68
unsigned char sa_family; /* address family */
69
char sa_data[14]; /* actually longer; address value */
78
unsigned char sin_len;
79
unsigned char sin_family; // AF_INET
80
unsigned short sin_port;
81
struct in_addr sin_addr;
86
char *h_name; /* official name of host */
87
char **h_aliases; /* alias list */
88
int h_addrtype; /* host address type */
89
int h_length; /* length of address */
90
char **h_addr_list; /* list of addresses from name server */
91
#define h_addr h_addr_list[0] /* address, for backward compatiblity */
94
// Necessary network defines, found by grepping unix headers when XP code would not compile
98
#define IPPROTO_TCP INET_TCP // Default TCP protocol
99
#define IPPROTO_UDP INET_UDP // Default UDP protocol
100
#define INADDR_ANY kOTAnyInetAddress
101
#define SOL_SOCKET XTI_GENERIC // Any type of socket
102
#define SO_REUSEADDR IP_REUSEADDR
103
#define SO_BROADCAST IP_BROADCAST
104
#define MSG_PEEK 0x2 // Just look at a message waiting, don�t actually read it.
106
typedef unsigned long u_long;
108
/* ldap.h has its own definition of fd_set */
112
typedef long fd_mask;
113
#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
116
#define howmany(x, y) (((x)+((y)-1))/(y))
118
#define FD_SETSIZE 64
119
typedef struct fd_set{
120
fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
123
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
124
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
125
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
126
#define FD_ZERO(p) memset (p, 0, sizeof(*(p)))
134
extern unsigned long inet_addr(const char *cp);
135
extern char *inet_ntoa(struct in_addr in);
137
inline unsigned long htonl(unsigned long hostlong) {return hostlong;}
138
inline unsigned long ntohl(unsigned long netlong) {return netlong;}
139
inline unsigned short ntohs(unsigned short netshort) {return netshort;}
140
inline unsigned short htons(unsigned short hostshort) {return hostshort;}
143
// UNIX look-alike routines
144
// They make sure that the arguments passed in are valid, and then
146
extern struct hostent *macsock_gethostbyaddr(const void *addr, int addrlen, int type);
148
extern int macsock_socket(int domain, int type, int protocol);
149
extern int macsock_ioctl(int sID, unsigned int request, void *value);
150
extern int macsock_connect(int sID, struct sockaddr *name, int namelen);
151
extern int macsock_write(int sID, const void *buffer, unsigned buflen);
152
extern int macsock_read(int sID, void *buf, unsigned nbyte);
153
extern int macsock_close(int sID);
155
extern int macsock_accept(int sID, struct sockaddr *addr, int *addrlen);
156
extern int macsock_bind(int sID, const struct sockaddr *name, int namelen);
157
extern int macsock_listen(int sID, int backlog);
159
extern int macsock_shutdown(int sID, int how);
160
extern int macsock_getpeername(int sID, struct sockaddr *name, int *namelen);
161
extern int macsock_getsockname(int sID, struct sockaddr *name, int *namelen);
162
extern int macsock_getsockopt(int sID, int level, int optname, void *optval,int *optlen);
163
extern int macsock_setsockopt(int sID, int level, int optname, const void *optval,int optlen);
164
extern int macsock_socketavailable(int sID, size_t *bytesAvailable);
165
extern int macsock_dup(int sID);
167
extern int macsock_send(int sID, const void *msg, int len, int flags);
168
extern int macsock_sendto(int sID, const void *msg, int len, int flags, struct sockaddr *toAddr, int toLen);
169
extern int macsock_recvfrom(int sID, void *buf, int len, int flags, struct sockaddr *from, int *fromLen);
170
extern int macsock_recv(int sID, void *buf, int len, int flags);
172
extern int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
175
#define macsock_gethostbyaddr PR_GetHostByAddr
176
#define macsock_socket PR_Socket
177
#define macsock_connect PR_Connect
178
#define macsock_write PR_Write
179
#define macsock_read PR_Read
180
#define macsock_close PR_Close
181
#define macsock_accept PR_Accept
182
#define macsock_bind PR_Bind
183
#define macsock_listen PR_Listen
184
#define macsock_shutdown PR_Shutdown
185
#define macsock_getpeername PR_GetPeerName
186
#define macsock_getsockname PR_GetSockName
187
#define macsock_socketavailable PR_SocketAvailable
188
#define macsock_send PR_Send
189
#define macsock_sendto PR_SendTo
190
#define macsock_recvfrom PR_RecvFrom
191
#define macsock_recv PR_Recv
204
/* New definitions that are not defined in macsock.h in macsock library */
206
char *p_name; /* official protocol name */
207
char **p_aliases; /* alias list */
208
int p_proto; /* protocol # */
211
extern struct protoent *getprotobyname(const char * name);
212
extern struct protoent *getprotobynumber(int number);
214
extern int gethostname (char *name, int namelen);
215
extern struct hostent *gethostbyname(const char * name);
216
extern struct hostent *gethostbyaddr(const void *addr, int addrlen, int type);
218
#define INADDR_LOOPBACK 0x7F000001
220
#define SO_KEEPALIVE TCP_KEEPALIVE
221
#define SO_RCVBUF XTI_RCVBUF
222
#define SO_SNDBUF XTI_SNDBUF
223
#define SO_LINGER XTI_LINGER /* linger on close if data present */
225
#define IPPROTO_IP INET_IP
227
/* Get/Set sock opt until fixed in NSPR 2.0 */
229
int l_onoff; /* option on/off */
230
int l_linger; /* linger time */
234
struct in_addr imr_multiaddr; /* IP multicast address of group */
235
struct in_addr imr_interface; /* local IP address of interface */
238
#endif /* macksocket_h___ */