home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _bcec8520a46d9daa6edf130f97dd7144 < prev    next >
Text File  |  2004-06-01  |  6KB  |  180 lines

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