1 /* sys/socket.h */ 2 3 /* djl */ 4 /* Provide UNIX compatibility */ 5 6 #ifndef _INC_SYS_SOCKET 7 #define _INC_SYS_SOCKET 8 9 #define WIN32_LEAN_AND_MEAN 10 #ifdef __GNUC__ 11 # define Win32_Winsock 12 #endif 13 #include <windows.h> 14 15 /* Too late to include winsock2.h if winsock.h has already been loaded */ 16 #ifndef _WINSOCKAPI_ 17 # if defined(UNDER_CE) && UNDER_CE <= 300 18 /* winsock2 only for 4.00+ */ 19 # include <winsock.h> 20 # else 21 # include <winsock2.h> 22 /* We need to include ws2tcpip.h to get the IPv6 definitions. 23 * It will in turn include wspiapi.h. Later versions of that 24 * header in the Windows SDK generate C++ template code that 25 * can't be compiled with VC6 anymore. The _WSPIAPI_COUNTOF 26 * definition below prevents wspiapi.h from generating this 27 * incompatible code. 28 */ 29 # define _WSPIAPI_COUNTOF(_Array) (sizeof(_Array) / sizeof(_Array[0])) 30 # include <ws2tcpip.h> 31 32 # ifndef SIO_GET_INTERFACE_LIST_EX 33 34 # ifndef MSG_WAITALL 35 # define MSG_WAITALL 0x8 36 # endif 37 38 /* The ws2tcpip.h header included in VC6 doesn't define the 39 * sin6_scope_id member of sockaddr_in6. We define our own 40 * version and redefine sockaddr_in6 to point to this one 41 * instead for compiling e.g. Socket.xs. 42 */ 43 44 struct my_sockaddr_in6 { 45 short sin6_family; /* AF_INET6 */ 46 u_short sin6_port; /* Transport level port number */ 47 u_long sin6_flowinfo; /* IPv6 flow information */ 48 struct in_addr6 sin6_addr; /* IPv6 address */ 49 u_long sin6_scope_id; /* set of interfaces for a scope */ 50 }; 51 # define sockaddr_in6 my_sockaddr_in6 52 53 /* Provide implementations of IN6ADDR_SETANY() and IN6ADDR_SETLOOPBACK 54 * that also initialize the sin6_scope_id field. 55 */ 56 # undef IN6ADDR_SETANY 57 # define IN6ADDR_SETANY(x) {\ 58 (x)->sin6_family = AF_INET6; \ 59 (x)->sin6_port = 0; \ 60 (x)->sin6_flowinfo = 0; \ 61 *((u_long *)((x)->sin6_addr.s6_addr) ) = 0; \ 62 *((u_long *)((x)->sin6_addr.s6_addr) + 1) = 0; \ 63 *((u_long *)((x)->sin6_addr.s6_addr) + 2) = 0; \ 64 *((u_long *)((x)->sin6_addr.s6_addr) + 3) = 0; \ 65 (x)->sin6_scope_id = 0; \ 66 } 67 68 # undef IN6ADDR_SETLOOPBACK 69 # define IN6ADDR_SETLOOPBACK(x) {\ 70 (x)->sin6_family = AF_INET6; \ 71 (x)->sin6_port = 0; \ 72 (x)->sin6_flowinfo = 0; \ 73 *((u_long *)((x)->sin6_addr.s6_addr) ) = 0; \ 74 *((u_long *)((x)->sin6_addr.s6_addr) + 1) = 0; \ 75 *((u_long *)((x)->sin6_addr.s6_addr) + 2) = 0; \ 76 *((u_long *)((x)->sin6_addr.s6_addr) + 3) = 1; \ 77 (x)->sin6_scope_id = 0; \ 78 } 79 80 # ifndef IPV6_HDRINCL 81 # define IPV6_HDRINCL 2 82 # endif 83 # ifndef IPV6_UNICAST_HOPS 84 # define IPV6_UNICAST_HOPS 4 85 # endif 86 # ifndef IPV6_MULTICAST_IF 87 # define IPV6_MULTICAST_IF 9 88 # endif 89 # ifndef IPV6_MULTICAST_HOPS 90 # define IPV6_MULTICAST_HOPS 10 91 # endif 92 # ifndef IPV6_MULTICAST_LOOP 93 # define IPV6_MULTICAST_LOOP 11 94 # endif 95 # ifndef IPV6_ADD_MEMBERSHIP 96 # define IPV6_ADD_MEMBERSHIP 12 97 # endif 98 # ifndef IPV6_DROP_MEMBERSHIP 99 # define IPV6_DROP_MEMBERSHIP 13 100 # endif 101 # ifndef IPV6_JOIN_GROUP 102 # define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP 103 # endif 104 # ifndef IPV6_LEAVE_GROUP 105 # define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP 106 # endif 107 # ifndef IPV6_PKTINFO 108 # define IPV6_PKTINFO 19 109 # endif 110 # ifndef IPV6_HOPLIMIT 111 # define IPV6_HOPLIMIT 21 112 # endif 113 # ifndef IPV6_PROTECTION_LEVEL 114 # define IPV6_PROTECTION_LEVEL 23 115 # endif 116 117 /* The ws2tcpip.h header included in MinGW includes ipv6_mreq already */ 118 # ifndef __GNUC__ 119 typedef struct ipv6_mreq { 120 struct in_addr6 ipv6mr_multiaddr; 121 unsigned int ipv6mr_interface; 122 } IPV6_MREQ; 123 # endif 124 125 # ifndef EAI_AGAIN 126 # define EAI_AGAIN WSATRY_AGAIN 127 # endif 128 # ifndef EAI_BADFLAGS 129 # define EAI_BADFLAGS WSAEINVAL 130 # endif 131 # ifndef EAI_FAIL 132 # define EAI_FAIL WSANO_RECOVERY 133 # endif 134 # ifndef EAI_FAMILY 135 # define EAI_FAMILY WSAEAFNOSUPPORT 136 # endif 137 # ifndef EAI_MEMORY 138 # define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY 139 # endif 140 # ifndef EAI_NODATA 141 # define EAI_NODATA WSANO_DATA 142 # endif 143 # ifndef EAI_NONAME 144 # define EAI_NONAME WSAHOST_NOT_FOUND 145 # endif 146 # ifndef EAI_SERVICE 147 # define EAI_SERVICE WSATYPE_NOT_FOUND 148 # endif 149 # ifndef EAI_SOCKTYPE 150 # define EAI_SOCKTYPE WSAESOCKTNOSUPPORT 151 # endif 152 153 # ifndef NI_NOFQDN 154 # define NI_NOFQDN 0x01 155 # endif 156 # ifndef NI_NUMERICHOST 157 # define NI_NUMERICHOST 0x02 158 # endif 159 # ifndef NI_NAMEREQD 160 # define NI_NAMEREQD 0x04 161 # endif 162 # ifndef NI_NUMERICSERV 163 # define NI_NUMERICSERV 0x08 164 # endif 165 # ifndef NI_DGRAM 166 # define NI_DGRAM 0x10 167 # endif 168 169 # endif 170 171 # endif 172 #endif 173 174 /* Early Platform SDKs have an incorrect definition of EAI_NODATA */ 175 #if (EAI_NODATA == EAI_NONAME) 176 # undef EAI_NODATA 177 # define EAI_NODATA WSANO_DATA 178 #endif 179 180 #ifdef __cplusplus 181 extern "C" { 182 #endif 183 184 #include "errno2.h" 185 186 #ifndef PERL_FD_SETSIZE 187 #define PERL_FD_SETSIZE 64 188 #endif 189 190 #define PERL_BITS_PER_BYTE 8 191 #define PERL_NFDBITS (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE) 192 193 typedef int Perl_fd_mask; 194 195 typedef struct Perl_fd_set { 196 Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS]; 197 } Perl_fd_set; 198 199 #define PERL_FD_CLR(n,p) \ 200 ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS))) 201 202 #define PERL_FD_SET(n,p) \ 203 ((p)->bits[(n)/PERL_NFDBITS] |= ((unsigned)1 << ((n)%PERL_NFDBITS))) 204 205 #define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p))) 206 207 #define PERL_FD_ISSET(n,p) \ 208 ((p)->bits[(n)/PERL_NFDBITS] & ((unsigned)1 << ((n)%PERL_NFDBITS))) 209 210 SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen); 211 int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen); 212 int win32_closesocket (SOCKET s); 213 int win32_connect (SOCKET s, const struct sockaddr *name, int namelen); 214 int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp); 215 int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen); 216 int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen); 217 int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen); 218 u_long win32_htonl (u_long hostlong); 219 u_short win32_htons (u_short hostshort); 220 unsigned long win32_inet_addr (const char * cp); 221 char * win32_inet_ntoa (struct in_addr in); 222 int win32_listen (SOCKET s, int backlog); 223 u_long win32_ntohl (u_long netlong); 224 u_short win32_ntohs (u_short netshort); 225 int win32_recv (SOCKET s, char * buf, int len, int flags); 226 int win32_recvfrom (SOCKET s, char * buf, int len, int flags, 227 struct sockaddr *from, int * fromlen); 228 int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds, 229 const struct timeval *timeout); 230 int win32_send (SOCKET s, const char * buf, int len, int flags); 231 int win32_sendto (SOCKET s, const char * buf, int len, int flags, 232 const struct sockaddr *to, int tolen); 233 int win32_setsockopt (SOCKET s, int level, int optname, 234 const char * optval, int optlen); 235 SOCKET win32_socket (int af, int type, int protocol); 236 int win32_shutdown (SOCKET s, int how); 237 238 /* Database function prototypes */ 239 240 struct hostent * win32_gethostbyaddr(const char * addr, int len, int type); 241 struct hostent * win32_gethostbyname(const char * name); 242 int win32_gethostname (char * name, int namelen); 243 struct servent * win32_getservbyport(int port, const char * proto); 244 struct servent * win32_getservbyname(const char * name, const char * proto); 245 struct protoent * win32_getprotobynumber(int proto); 246 struct protoent * win32_getprotobyname(const char * name); 247 struct protoent *win32_getprotoent(void); 248 struct servent *win32_getservent(void); 249 void win32_sethostent(int stayopen); 250 void win32_setnetent(int stayopen); 251 struct netent * win32_getnetent(void); 252 struct netent * win32_getnetbyname(char *name); 253 struct netent * win32_getnetbyaddr(long net, int type); 254 void win32_setprotoent(int stayopen); 255 void win32_setservent(int stayopen); 256 void win32_endhostent(void); 257 void win32_endnetent(void); 258 void win32_endprotoent(void); 259 void win32_endservent(void); 260 261 #ifndef WIN32SCK_IS_STDSCK 262 263 /* direct to our version */ 264 265 #define htonl win32_htonl 266 #define htons win32_htons 267 #define ntohl win32_ntohl 268 #define ntohs win32_ntohs 269 #define inet_addr win32_inet_addr 270 #define inet_ntoa win32_inet_ntoa 271 272 #define socket win32_socket 273 #define bind win32_bind 274 #define listen win32_listen 275 #define accept win32_accept 276 #define connect win32_connect 277 #define send win32_send 278 #define sendto win32_sendto 279 #define recv win32_recv 280 #define recvfrom win32_recvfrom 281 #define shutdown win32_shutdown 282 #define closesocket win32_closesocket 283 #define ioctlsocket win32_ioctlsocket 284 #define setsockopt win32_setsockopt 285 #define getsockopt win32_getsockopt 286 #define getpeername win32_getpeername 287 #define getsockname win32_getsockname 288 #define gethostname win32_gethostname 289 #define gethostbyname win32_gethostbyname 290 #define gethostbyaddr win32_gethostbyaddr 291 #define getprotobyname win32_getprotobyname 292 #define getprotobynumber win32_getprotobynumber 293 #define getservbyname win32_getservbyname 294 #define getservbyport win32_getservbyport 295 #define select win32_select 296 #define endhostent win32_endhostent 297 #define endnetent win32_endnetent 298 #define endprotoent win32_endprotoent 299 #define endservent win32_endservent 300 #define getnetent win32_getnetent 301 #define getnetbyname win32_getnetbyname 302 #define getnetbyaddr win32_getnetbyaddr 303 #define getprotoent win32_getprotoent 304 #define getservent win32_getservent 305 #define sethostent win32_sethostent 306 #define setnetent win32_setnetent 307 #define setprotoent win32_setprotoent 308 #define setservent win32_setservent 309 310 #undef fd_set 311 #undef FD_SET 312 #undef FD_CLR 313 #undef FD_ISSET 314 #undef FD_ZERO 315 #define fd_set Perl_fd_set 316 #define FD_SET(n,p) PERL_FD_SET(n,p) 317 #define FD_CLR(n,p) PERL_FD_CLR(n,p) 318 #define FD_ISSET(n,p) PERL_FD_ISSET(n,p) 319 #define FD_ZERO(p) PERL_FD_ZERO(p) 320 321 #endif /* WIN32SCK_IS_STDSCK */ 322 323 #ifdef __cplusplus 324 } 325 #endif 326 327 #endif /* _INC_SYS_SOCKET */ 328