summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Joye <pajoye@php.net>2008-08-21 23:37:40 +0000
committerPierre Joye <pajoye@php.net>2008-08-21 23:37:40 +0000
commitadfa214688b0baa9141422770dd2eb91b491335d (patch)
treec33453d1fd0bda151e8bcb7d02343e80c9cdf07c
parentdcb0cc3d2b63e0388b64ccd52ec424e9c3cba385 (diff)
downloadphp-git-adfa214688b0baa9141422770dd2eb91b491335d.tar.gz
- drop bindlib usage on windows
- inet_pton, inet_ntop and inet_aton are always available (VC9 uses the CRT implementation, VC6 our own)
-rw-r--r--ext/ftp/ftp.c1
-rw-r--r--ext/sockets/php_sockets_win.c9
-rw-r--r--ext/sockets/sockets.c15
-rw-r--r--ext/standard/basic_functions.c6
-rw-r--r--ext/standard/dns.c21
-rw-r--r--ext/standard/flock_compat.c1
-rw-r--r--main/network.c5
-rw-r--r--main/php_network.h15
-rw-r--r--win32/build/config.w3217
-rw-r--r--win32/inet.c89
-rw-r--r--win32/inet.h10
11 files changed, 123 insertions, 66 deletions
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
index 30ca6b920a..3a8d835bb6 100644
--- a/ext/ftp/ftp.c
+++ b/ext/ftp/ftp.c
@@ -37,6 +37,7 @@
#include <string.h>
#include <time.h>
#ifdef PHP_WIN32
+#include "win32/inet.h"
#include <winsock2.h>
#elif defined(NETWARE)
#ifdef USE_WINSOCK /* Modified to use Winsock (NOVSOCK2.H), atleast for now */
diff --git a/ext/sockets/php_sockets_win.c b/ext/sockets/php_sockets_win.c
index 70913599e8..807324f2a2 100644
--- a/ext/sockets/php_sockets_win.c
+++ b/ext/sockets/php_sockets_win.c
@@ -72,13 +72,4 @@ int socketpair(int domain, int type, int protocol, SOCKET sock[2]) {
return 0;
}
-int inet_aton(const char *cp, struct in_addr *inp) {
- inp->s_addr = inet_addr(cp);
-
- if (inp->s_addr == INADDR_NONE) {
- return 0;
- }
-
- return 1;
-}
#endif
diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c
index dd0ab79113..5e2b09c548 100644
--- a/ext/sockets/sockets.c
+++ b/ext/sockets/sockets.c
@@ -33,8 +33,15 @@
#include "ext/standard/file.h"
#include "ext/standard/info.h"
#include "php_ini.h"
-
-#ifndef PHP_WIN32
+#ifdef PHP_WIN32
+# include "win32/inet.h"
+# include <winsock2.h>
+# include <windows.h>
+# include <Ws2tcpip.h>
+# include "php_sockets.h"
+# include "php_sockets_win.h"
+# define IS_INVALID_SOCKET(a) (a->bsd_socket == INVALID_SOCKET)
+#else
# include "php_sockets.h"
# include <sys/types.h>
# include <sys/socket.h>
@@ -51,10 +58,6 @@
# include <sys/uio.h>
# define IS_INVALID_SOCKET(a) (a->bsd_socket < 0)
# define set_errno(a) (errno = a)
-#else /* windows */
-# include "php_sockets.h"
-# include "php_sockets_win.h"
-# define IS_INVALID_SOCKET(a) (a->bsd_socket == INVALID_SOCKET)
#endif
ZEND_DECLARE_MODULE_GLOBALS(sockets)
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 113c36bc62..c2a4e15a8c 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -61,7 +61,11 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE;
#include <netinet/in.h>
#endif
-#include <netdb.h>
+#ifndef PHP_WIN32
+# include <netdb.h>
+#else
+#include "win32/inet.h"
+#endif
#if HAVE_ARPA_INET_H
# include <arpa/inet.h>
diff --git a/ext/standard/dns.c b/ext/standard/dns.c
index 652829141a..16aa034bbe 100644
--- a/ext/standard/dns.c
+++ b/ext/standard/dns.c
@@ -29,23 +29,10 @@
#endif
#ifdef PHP_WIN32
-#if HAVE_LIBBIND
-#ifndef WINNT
-#define WINNT 1
-#endif
-/* located in www.php.net/extra/bindlib.zip */
-#if HAVE_ARPA_INET_H
-#include "arpa/inet.h"
-#endif
-#include "netdb.h"
-#if HAVE_ARPA_NAMESERV_H
-#include "arpa/nameser.h"
-#endif
-#if HAVE_RESOLV_H
-#include "resolv.h"
-#endif
-#endif /* HAVE_LIBBIND */
-#include <winsock2.h>
+# include "win32/inet.h"
+# include <winsock2.h>
+# include <windows.h>
+# include <Ws2tcpip.h>
#else /* This holds good for NetWare too, both for Winsock and Berkeley sockets */
#include <netinet/in.h>
#if HAVE_ARPA_INET_H
diff --git a/ext/standard/flock_compat.c b/ext/standard/flock_compat.c
index 9b0bf46d4a..d5b262ef9c 100644
--- a/ext/standard/flock_compat.c
+++ b/ext/standard/flock_compat.c
@@ -30,6 +30,7 @@
#ifdef PHP_WIN32
#include <io.h>
+#include "config.w32.h"
#endif
#ifdef NETWARE
diff --git a/main/network.c b/main/network.c
index 51d76faf6b..1ce446494f 100644
--- a/main/network.c
+++ b/main/network.c
@@ -26,8 +26,9 @@
#include <stddef.h>
#ifdef PHP_WIN32
-#define O_RDONLY _O_RDONLY
-#include "win32/param.h"
+# include "win32/inet.h"
+# define O_RDONLY _O_RDONLY
+# include "win32/param.h"
#elif defined(NETWARE)
#include <sys/timeval.h>
#include <sys/param.h>
diff --git a/main/php_network.h b/main/php_network.h
index f5db18f836..a9a0d56831 100644
--- a/main/php_network.h
+++ b/main/php_network.h
@@ -22,20 +22,7 @@
#define _PHP_NETWORK_H
#ifdef PHP_WIN32
-# ifndef WINNT
-# define WINNT 1
-# endif
-# undef FD_SETSIZE
-# include "arpa/inet.h"
- /* Apache folks decided that strtoul was evil and redefined
- * it to something that breaks the windows headers */
-# undef strtoul
-/* defines socklen_t and some IPV6 stuff */
-# include <ws2tcpip.h>
-# if HAVE_WSPIAPI_H
- /* getaddrinfo */
-# include <wspiapi.h>
-# endif
+# include "win32/inet.h"
#else
# undef closesocket
# define closesocket close
diff --git a/win32/build/config.w32 b/win32/build/config.w32
index 6310c1ccdf..656fe49795 100644
--- a/win32/build/config.w32
+++ b/win32/build/config.w32
@@ -247,17 +247,6 @@ function probe_basic_headers()
php_usual_include_suspects += ";" + PHP_PHP_BUILD + "\\include";
php_usual_lib_suspects += ";" + PHP_PHP_BUILD + "\\lib";
}
-
- p = CHECK_HEADER_ADD_INCLUDE("arpa\\nameser.h", "CFLAGS", php_usual_include_suspects);
-
- // hack to catch common location of libs
- if (typeof(p) == "string") {
- p = p.replace(new RegExp("include$"), "lib");
- ADD_FLAG("LDFLAGS", '/libpath:"' + p + '" ');
- php_usual_lib_suspects += ";" + p;
- } else if (!p) {
- ERROR("We really need that arpa\\nameser.h file - it is part of the bindlib package");
- }
}
function add_extra_dirs()
@@ -292,12 +281,6 @@ function add_extra_dirs()
probe_basic_headers();
add_extra_dirs();
-// We can't probe for libs before this line
-
-if (!(CHECK_LIB("resolv_a.lib") || CHECK_LIB("resolv.lib"))) {
- ERROR("We really need that arpa\\nameser.h file - it is part of the bindlib package");
-}
-
// Do we want static ICU lib
ARG_WITH('static-icu', 'Link against the static version of the ICU library', 'no');
if (PHP_STATIC_ICU == "yes") {
diff --git a/win32/inet.c b/win32/inet.c
new file mode 100644
index 0000000000..117c6d83d1
--- /dev/null
+++ b/win32/inet.c
@@ -0,0 +1,89 @@
+#if _MSC_VER < 1500
+#include "config.w32.h"
+#include "php.h"
+#include <winsock2.h>
+#include <windows.h>
+#include <Ws2tcpip.h>
+
+#include "inet.h"
+
+PHPAPI int
+inet_pton(int af, const char* src, void* dst)
+{
+ int address_length;
+ struct sockaddr_storage sa;
+ struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;
+
+ switch (af) {
+ case AF_INET:
+ address_length = sizeof (struct sockaddr_in);
+ break;
+
+ case AF_INET6:
+ address_length = sizeof (struct sockaddr_in6);
+ break;
+
+ default:
+ return -1;
+ }
+
+ if (WSAStringToAddress ((LPTSTR) src, af, NULL, (LPSOCKADDR) &sa, &address_length) == 0) {
+ switch (af) {
+ case AF_INET:
+ memcpy (dst, &sin->sin_addr, sizeof (struct in_addr));
+ break;
+
+ case AF_INET6:
+ memcpy (dst, &sin6->sin6_addr, sizeof (struct in6_addr));
+ break;
+ }
+ return 1;
+ }
+
+ return 0;
+}
+
+PHPAPI const char* inet_ntop(int af, const void* src, char* dst, size_t size)
+{
+ int address_length;
+ DWORD string_length = size;
+ struct sockaddr_storage sa;
+ struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;
+
+ memset (&sa, 0, sizeof (sa));
+ switch (af) {
+ case AF_INET:
+ address_length = sizeof (struct sockaddr_in);
+ sin->sin_family = af;
+ memcpy (&sin->sin_addr, src, sizeof (struct in_addr));
+ break;
+
+ case AF_INET6:
+ address_length = sizeof (struct sockaddr_in6);
+ sin6->sin6_family = af;
+ memcpy (&sin6->sin6_addr, src, sizeof (struct in6_addr));
+ break;
+
+ default:
+ return NULL;
+ }
+
+ if (WSAAddressToString ((LPSOCKADDR) &sa, address_length, NULL, dst, &string_length) == 0) {
+ return dst;
+ }
+
+ return NULL;
+}
+
+int inet_aton(const char *cp, struct in_addr *inp) {
+ inp->s_addr = inet_addr(cp);
+
+ if (inp->s_addr == INADDR_NONE) {
+ return 0;
+ }
+
+ return 1;
+}
+#endif
diff --git a/win32/inet.h b/win32/inet.h
new file mode 100644
index 0000000000..41a92da272
--- /dev/null
+++ b/win32/inet.h
@@ -0,0 +1,10 @@
+#if _MSC_VER >= 1500
+# include <In6addr.h>
+#endif
+#include <Ws2tcpip.h>
+
+#if _MSC_VER < 1500
+PHPAPI int inet_pton(int af, const char* src, void* dst);
+PHPAPI const char* inet_ntop(int af, const void* src, char* dst, size_t size);
+PHPAPI int inet_aton(const char *cp, struct in_addr *inp);
+#endif