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