Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
5.8 KiB

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