- inet_pton, inet_ntop and inet_aton are always available (VC9 uses the CRT implementation, VC6 our own)
#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 */
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
#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>
# 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)
#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>
#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
#ifdef PHP_WIN32
#include <io.h>
+#include "config.w32.h"
#endif
#ifdef NETWARE
#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>
#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
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()
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") {
--- /dev/null
+#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
--- /dev/null
+#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