Once again syncing after too long an absence
[p5sagit/p5-mst-13.2.git] / win32 / include / sys / socket.h
1 // sys/socket.h
2
3 // djl
4 // Provide UNIX compatibility
5
6 #ifndef  _INC_SYS_SOCKET
7 #define  _INC_SYS_SOCKET
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 #define WIN32_LEAN_AND_MEAN
14 #ifdef __GNUC__
15 #  define Win32_Winsock
16 #endif
17 #include <windows.h>
18 #include <winsock.h>
19
20 #define  ENOTSOCK       WSAENOTSOCK
21
22 #ifdef USE_SOCKETS_AS_HANDLES
23
24 #ifndef PERL_FD_SETSIZE
25 #define PERL_FD_SETSIZE         64
26 #endif
27
28 #define PERL_BITS_PER_BYTE      8
29 #define PERL_NFDBITS            (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
30
31 typedef int                     Perl_fd_mask;
32
33 typedef struct  Perl_fd_set {
34     Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
35 }                               Perl_fd_set;
36
37 #define PERL_FD_CLR(n,p) \
38     ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
39
40 #define PERL_FD_SET(n,p) \
41     ((p)->bits[(n)/PERL_NFDBITS] |=  ((unsigned)1 << ((n)%PERL_NFDBITS)))
42
43 #define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
44
45 #define PERL_FD_ISSET(n,p) \
46     ((p)->bits[(n)/PERL_NFDBITS] &   ((unsigned)1 << ((n)%PERL_NFDBITS)))
47
48 #else   /* USE_SOCKETS_AS_HANDLES */
49
50 #define Perl_fd_set     fd_set
51 #define PERL_FD_SET(n,p)        FD_SET(n,p)
52 #define PERL_FD_CLR(n,p)        FD_CLR(n,p)
53 #define PERL_FD_ISSET(n,p)      FD_ISSET(n,p)
54 #define PERL_FD_ZERO(p)         FD_ZERO(p)
55
56 #endif  /* USE_SOCKETS_AS_HANDLES */
57
58 SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
59 int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
60 int win32_closesocket (SOCKET s);
61 int win32_connect (SOCKET s, const struct sockaddr *name, int namelen);
62 int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp);
63 int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen);
64 int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen);
65 int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen);
66 u_long win32_htonl (u_long hostlong);
67 u_short win32_htons (u_short hostshort);
68 unsigned long win32_inet_addr (const char * cp);
69 char * win32_inet_ntoa (struct in_addr in);
70 int win32_listen (SOCKET s, int backlog);
71 u_long win32_ntohl (u_long netlong);
72 u_short win32_ntohs (u_short netshort);
73 int win32_recv (SOCKET s, char * buf, int len, int flags);
74 int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
75                          struct sockaddr *from, int * fromlen);
76 int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
77                   const struct timeval *timeout);
78 int win32_send (SOCKET s, const char * buf, int len, int flags);
79 int win32_sendto (SOCKET s, const char * buf, int len, int flags,
80                        const struct sockaddr *to, int tolen);
81 int win32_setsockopt (SOCKET s, int level, int optname,
82                            const char * optval, int optlen);
83 SOCKET win32_socket (int af, int type, int protocol);
84 int win32_shutdown (SOCKET s, int how);
85
86 /* Database function prototypes */
87
88 struct hostent * win32_gethostbyaddr(const char * addr, int len, int type);
89 struct hostent * win32_gethostbyname(const char * name);
90 int win32_gethostname (char * name, int namelen);
91 struct servent * win32_getservbyport(int port, const char * proto);
92 struct servent * win32_getservbyname(const char * name, const char * proto);
93 struct protoent * win32_getprotobynumber(int proto);
94 struct protoent * win32_getprotobyname(const char * name);
95 struct protoent *win32_getprotoent(void);
96 struct servent *win32_getservent(void);
97 void win32_sethostent(int stayopen);
98 void win32_setnetent(int stayopen);
99 struct netent * win32_getnetent(void);
100 struct netent * win32_getnetbyname(char *name);
101 struct netent * win32_getnetbyaddr(long net, int type);
102 void win32_setprotoent(int stayopen);
103 void win32_setservent(int stayopen);
104 void win32_endhostent(void);
105 void win32_endnetent(void);
106 void win32_endprotoent(void);
107 void win32_endservent(void);
108
109 #ifndef WIN32SCK_IS_STDSCK
110 //
111 // direct to our version
112 //
113 #define htonl           win32_htonl
114 #define htons           win32_htons
115 #define ntohl           win32_ntohl
116 #define ntohs           win32_ntohs
117 #define inet_addr       win32_inet_addr
118 #define inet_ntoa       win32_inet_ntoa
119
120 #define socket          win32_socket
121 #define bind            win32_bind
122 #define listen          win32_listen
123 #define accept          win32_accept
124 #define connect         win32_connect
125 #define send            win32_send
126 #define sendto          win32_sendto
127 #define recv            win32_recv
128 #define recvfrom        win32_recvfrom
129 #define shutdown        win32_shutdown
130 #define closesocket     win32_closesocket
131 #define ioctlsocket     win32_ioctlsocket
132 #define setsockopt      win32_setsockopt
133 #define getsockopt      win32_getsockopt
134 #define getpeername     win32_getpeername
135 #define getsockname     win32_getsockname
136 #define gethostname     win32_gethostname
137 #define gethostbyname   win32_gethostbyname
138 #define gethostbyaddr   win32_gethostbyaddr
139 #define getprotobyname  win32_getprotobyname
140 #define getprotobynumber win32_getprotobynumber
141 #define getservbyname   win32_getservbyname
142 #define getservbyport   win32_getservbyport
143 #define select          win32_select
144 #define endhostent      win32_endhostent
145 #define endnetent       win32_endnetent
146 #define endprotoent     win32_endprotoent
147 #define endservent      win32_endservent
148 #define getnetent       win32_getnetent
149 #define getnetbyname    win32_getnetbyname
150 #define getnetbyaddr    win32_getnetbyaddr
151 #define getprotoent     win32_getprotoent
152 #define getservent      win32_getservent
153 #define sethostent      win32_sethostent
154 #define setnetent       win32_setnetent
155 #define setprotoent     win32_setprotoent
156 #define setservent      win32_setservent
157
158 #ifdef USE_SOCKETS_AS_HANDLES
159 #undef fd_set
160 #undef FD_SET
161 #undef FD_CLR
162 #undef FD_ISSET
163 #undef FD_ZERO
164 #define fd_set          Perl_fd_set
165 #define FD_SET(n,p)     PERL_FD_SET(n,p)
166 #define FD_CLR(n,p)     PERL_FD_CLR(n,p)
167 #define FD_ISSET(n,p)   PERL_FD_ISSET(n,p)
168 #define FD_ZERO(p)      PERL_FD_ZERO(p)
169 #endif  /* USE_SOCKETS_AS_HANDLES */
170
171 #endif  /* WIN32SCK_IS_STDSCK */
172
173 #ifdef __cplusplus
174 }
175 #endif
176
177 #endif  // _INC_SYS_SOCKET