15139
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
1 /* Workable version of <sys/socket.h> based on winsock.h */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
2
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
3 #ifndef _SOCKET_H_
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
4 #define _SOCKET_H_
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
5
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
6 /* defeat the multiple include protection */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
7 #ifdef _WINSOCKAPI_
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
8 #undef _WINSOCKAPI_
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
9 #endif
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
10
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
11 /* avoid confusion with our version of select */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
12 #ifdef select
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
13 #undef select
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
14 #define MUST_REDEF_SELECT
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
15 #endif
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
16
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
17 /* avoid clashing with our version of FD_SET if already defined */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
18 #ifdef FD_SET
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
19 #undef FD_SET
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
20 #undef FD_CLR
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
21 #undef FD_ISSET
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
22 #undef FD_ZERO
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
23 #endif
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
24
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
25 /* allow us to provide our own version of fd_set */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
26 #define fd_set ws_fd_set
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
27
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
28 /* avoid duplicate definition of timeval */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
29 #ifdef HAVE_TIMEVAL
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
30 #define timeval ws_timeval
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
31 #endif
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
32
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
33 #include <winsock.h>
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
34
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
35 /* redefine select to reference our version */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
36 #ifdef MUST_REDEF_SELECT
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
37 #define select sys_select
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
38 #undef MUST_REDEF_SELECT
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
39 #endif
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
40
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
41 /* revert to our version of FD_SET */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
42 #undef FD_SET
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
43 #undef FD_CLR
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
44 #undef FD_ISSET
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
45 #undef FD_ZERO
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
46 #undef fd_set
|
16594
|
47 #include "w32.h"
|
15139
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
48
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
49 #ifdef HAVE_TIMEVAL
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
50 #undef timeval
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
51 #endif
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
52
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
53 /* shadow functions where we provide our own wrapper */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
54 #define socket sys_socket
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
55 #define bind sys_bind
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
56 #define connect sys_connect
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
57 #define htons sys_htons
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
58 #define ntohs sys_ntohs
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
59 #define inet_addr sys_inet_addr
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
60 #define gethostname sys_gethostname
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
61 #define gethostbyname sys_gethostbyname
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
62 #define getservbyname sys_getservbyname
|
18726
|
63 #define shutdown sys_shutdown
|
15139
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
64
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
65 int sys_socket(int af, int type, int protocol);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
66 int sys_bind (int s, const struct sockaddr *addr, int namelen);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
67 int sys_connect (int s, const struct sockaddr *addr, int namelen);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
68 u_short sys_htons (u_short hostshort);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
69 u_short sys_ntohs (u_short netshort);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
70 unsigned long sys_inet_addr (const char * cp);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
71 int sys_gethostname (char * name, int namelen);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
72 struct hostent * sys_gethostbyname(const char * name);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
73 struct servent * sys_getservbyname(const char * name, const char * proto);
|
18726
|
74 int sys_shutdown (int socket, int how);
|
15139
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
75
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
76 /* we are providing a real h_errno variable */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
77 #undef h_errno
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
78 extern int h_errno;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
79
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
80 /* map winsock error codes to standard names */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
81 #define EWOULDBLOCK WSAEWOULDBLOCK
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
82 #define EINPROGRESS WSAEINPROGRESS
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
83 #define EALREADY WSAEALREADY
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
84 #define ENOTSOCK WSAENOTSOCK
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
85 #define EDESTADDRREQ WSAEDESTADDRREQ
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
86 #define EMSGSIZE WSAEMSGSIZE
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
87 #define EPROTOTYPE WSAEPROTOTYPE
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
88 #define ENOPROTOOPT WSAENOPROTOOPT
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
89 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
90 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
91 #define EOPNOTSUPP WSAEOPNOTSUPP
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
92 #define EPFNOSUPPORT WSAEPFNOSUPPORT
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
93 #define EAFNOSUPPORT WSAEAFNOSUPPORT
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
94 #define EADDRINUSE WSAEADDRINUSE
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
95 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
96 #define ENETDOWN WSAENETDOWN
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
97 #define ENETUNREACH WSAENETUNREACH
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
98 #define ENETRESET WSAENETRESET
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
99 #define ECONNABORTED WSAECONNABORTED
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
100 #define ECONNRESET WSAECONNRESET
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
101 #define ENOBUFS WSAENOBUFS
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
102 #define EISCONN WSAEISCONN
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
103 #define ENOTCONN WSAENOTCONN
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
104 #define ESHUTDOWN WSAESHUTDOWN
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
105 #define ETOOMANYREFS WSAETOOMANYREFS
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
106 #define ETIMEDOUT WSAETIMEDOUT
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
107 #define ECONNREFUSED WSAECONNREFUSED
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
108 #define ELOOP WSAELOOP
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
109 /* #define ENAMETOOLONG WSAENAMETOOLONG */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
110 #define EHOSTDOWN WSAEHOSTDOWN
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
111 #define EHOSTUNREACH WSAEHOSTUNREACH
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
112 /* #define ENOTEMPTY WSAENOTEMPTY */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
113 #define EPROCLIM WSAEPROCLIM
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
114 #define EUSERS WSAEUSERS
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
115 #define EDQUOT WSAEDQUOT
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
116 #define ESTALE WSAESTALE
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
117 #define EREMOTE WSAEREMOTE
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
118
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
119 #endif /* _SOCKET_H_ */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
120
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
121 /* end of socket.h */
|