Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 91 lines (71 sloc) 1.902 kB
adfa214 @pierrejoye - drop bindlib usage on windows
pierrejoye authored
1 #include "config.w32.h"
2 #include "php.h"
3 #include <winsock2.h>
4 #include <windows.h>
5 #include <Ws2tcpip.h>
6
7 #include "inet.h"
9499410 @pierrejoye - bump minimum version, no more XP/2003
pierrejoye authored
8 #if (_WIN32_WINNT < 0x0600) /* Vista/2k8 have these functions */
9
adfa214 @pierrejoye - drop bindlib usage on windows
pierrejoye authored
10
81f5248 @KalleZ Fix typo
KalleZ authored
11 PHPAPI int inet_pton(int af, const char* src, void* dst)
adfa214 @pierrejoye - drop bindlib usage on windows
pierrejoye authored
12 {
13 int address_length;
14 struct sockaddr_storage sa;
15 struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
16 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;
17
18 switch (af) {
19 case AF_INET:
20 address_length = sizeof (struct sockaddr_in);
21 break;
22
23 case AF_INET6:
24 address_length = sizeof (struct sockaddr_in6);
25 break;
26
27 default:
28 return -1;
29 }
30
31 if (WSAStringToAddress ((LPTSTR) src, af, NULL, (LPSOCKADDR) &sa, &address_length) == 0) {
32 switch (af) {
33 case AF_INET:
34 memcpy (dst, &sin->sin_addr, sizeof (struct in_addr));
35 break;
36
37 case AF_INET6:
38 memcpy (dst, &sin6->sin6_addr, sizeof (struct in6_addr));
39 break;
40 }
41 return 1;
42 }
43
44 return 0;
45 }
46
47 PHPAPI const char* inet_ntop(int af, const void* src, char* dst, size_t size)
48 {
49 int address_length;
50 DWORD string_length = size;
51 struct sockaddr_storage sa;
52 struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
53 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;
54
55 memset (&sa, 0, sizeof (sa));
56 switch (af) {
57 case AF_INET:
58 address_length = sizeof (struct sockaddr_in);
59 sin->sin_family = af;
60 memcpy (&sin->sin_addr, src, sizeof (struct in_addr));
61 break;
62
63 case AF_INET6:
64 address_length = sizeof (struct sockaddr_in6);
65 sin6->sin6_family = af;
66 memcpy (&sin6->sin6_addr, src, sizeof (struct in6_addr));
67 break;
68
69 default:
70 return NULL;
71 }
72
73 if (WSAAddressToString ((LPSOCKADDR) &sa, address_length, NULL, dst, &string_length) == 0) {
74 return dst;
75 }
76
77 return NULL;
78 }
79
9499410 @pierrejoye - bump minimum version, no more XP/2003
pierrejoye authored
80 #endif
81
adfa214 @pierrejoye - drop bindlib usage on windows
pierrejoye authored
82 int inet_aton(const char *cp, struct in_addr *inp) {
83 inp->s_addr = inet_addr(cp);
84
85 if (inp->s_addr == INADDR_NONE) {
86 return 0;
87 }
88
89 return 1;
90 }
Something went wrong with that request. Please try again.