diff options
-rw-r--r-- | ext/sockets/php_sockets_win.c | 9 | ||||
-rw-r--r-- | ext/sockets/sockets.c | 15 | ||||
-rw-r--r-- | ext/standard/basic_functions.c | 6 | ||||
-rw-r--r-- | ext/standard/dns.c | 21 | ||||
-rw-r--r-- | ext/standard/flock_compat.c | 9 | ||||
-rw-r--r-- | ext/standard/flock_compat.h | 1 | ||||
-rw-r--r-- | main/network.c | 5 | ||||
-rw-r--r-- | main/php_network.h | 15 | ||||
-rw-r--r-- | win32/build/config.w32 | 15 | ||||
-rw-r--r-- | win32/glob.h | 9 | ||||
-rw-r--r-- | win32/inet.c | 89 | ||||
-rw-r--r-- | win32/inet.h | 10 |
12 files changed, 134 insertions, 70 deletions
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 93283ec4f0..b131a41ce7 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 5d35174545..0fc77d4cdf 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -63,7 +63,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 f559f79572..39412adc86 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 9bbb507d79..d561945533 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 @@ -44,7 +45,7 @@ PHPAPI int flock(int fd, int operation) #endif /* !defined(HAVE_FLOCK) */ PHPAPI int php_flock(int fd, int operation) -#if HAVE_STRUCT_FLOCK +#if HAVE_STRUCT_FLOCK /* {{{ */ { struct flock flck; int ret; @@ -73,7 +74,8 @@ PHPAPI int php_flock(int fd, int operation) return ret; } -#elif defined(PHP_WIN32) +/* }}} */ +#elif defined(PHP_WIN32) /* {{{ */ /* * Program: Unix compatibility routines * @@ -152,6 +154,7 @@ PHPAPI int php_flock(int fd, int operation) #endif return -1; } +/* }}} */ #else #warning no proper flock support for your site { @@ -160,6 +163,7 @@ PHPAPI int php_flock(int fd, int operation) } #endif +#ifndef PHP_WIN32 #if !(HAVE_INET_ATON) /* {{{ inet_aton * Check whether "cp" is a valid ascii representation @@ -223,6 +227,7 @@ int inet_aton(const char *cp, struct in_addr *ap) } /* }}} */ #endif /* !HAVE_INET_ATON */ +#endif /* * Local variables: diff --git a/ext/standard/flock_compat.h b/ext/standard/flock_compat.h index 3e0fcd7c33..76912ff529 100644 --- a/ext/standard/flock_compat.h +++ b/ext/standard/flock_compat.h @@ -49,7 +49,6 @@ PHPAPI int flock(int fd, int operation); #include <arpa/inet.h> #endif -extern int inet_aton(const char *, struct in_addr *); #endif #endif /* FLOCK_COMPAT_H */ diff --git a/main/network.c b/main/network.c index 782224eda8..d8824fd81e 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 e4d3145cd0..54b940049c 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() @@ -291,9 +280,6 @@ function add_extra_dirs() probe_basic_headers(); add_extra_dirs(); -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"); -} //DEFINE("PHP_BUILD", PHP_PHP_BUILD); @@ -317,6 +303,7 @@ ADD_SOURCES("main", "main.c snprintf.c spprintf.c safe_mode.c getopt.c fopen_wra php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \ strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c network.c \ php_open_temporary_file.c php_logos.c output.c internal_functions.c php_sprintf.c"); +ADD_SOURCES("win32", "inet.c"); ADD_SOURCES("main/streams", "streams.c cast.c memory.c filter.c plain_wrapper.c \ userspace.c transports.c xp_socket.c mmap.c glob_wrapper.c"); diff --git a/win32/glob.h b/win32/glob.h index 4e842a5cee..dabf095763 100644 --- a/win32/glob.h +++ b/win32/glob.h @@ -43,7 +43,9 @@ #ifndef _GLOB_H_ #define _GLOB_H_ -#include <sys/cdefs.h> +#ifndef PHP_WIN32 +# include <sys/cdefs.h> +#endif struct stat; typedef struct { @@ -93,9 +95,8 @@ typedef struct { #define GLOB_NOSYS (-4) /* Function not supported. */ #define GLOB_ABEND GLOB_ABORTED -__BEGIN_DECLS +BEGIN_EXTERN_C() int glob(const char *, int, int (*)(const char *, int), glob_t *); void globfree(glob_t *); -__END_DECLS - +END_EXTERN_C() #endif /* !_GLOB_H_ */ diff --git a/win32/inet.c b/win32/inet.c new file mode 100644 index 0000000000..02d00ca474 --- /dev/null +++ b/win32/inet.c @@ -0,0 +1,89 @@ +#include "config.w32.h" +#if (_WIN32_WINNT < 0x0600) /* Vita/2k8 have these functions */ +#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..7b3821c71b --- /dev/null +++ b/win32/inet.h @@ -0,0 +1,10 @@ +#if _MSC_VER >= 1500 +# include <In6addr.h> +#endif +#include <Ws2tcpip.h> + +#if (_WIN32_WINNT <= 0x500) +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 |