From: Michael Wallner Date: Fri, 14 Nov 2014 07:15:18 +0000 (+0100) Subject: use ares_inet_{ntop,pton}; parse AAAA answers X-Git-Tag: RELEASE_0_8_0~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=e4bb10e8424cb45f347e07fa9a095321bb032e96;p=m6w6%2Fext-ares use ares_inet_{ntop,pton}; parse AAAA answers --- diff --git a/config.m4 b/config.m4 index 3b1297a..cab7908 100644 --- a/config.m4 +++ b/config.m4 @@ -106,6 +106,14 @@ if test "$PHP_ARES" != "no"; then [AC_DEFINE([HAVE_ARES_SET_LOCAL_IP6], [1], [ ])], [ ], [$PHP_ARES_LIBADD -L$PHP_ARES_DIR/$PHP_LIBDIR] ) + PHP_CHECK_LIBRARY($PHP_ARES_LIB, ares_inet_ntop, + [AC_DEFINE([HAVE_ARES_INET_NTOP], [1], [ ])], [ ], + [$PHP_ARES_LIBADD -L$PHP_ARES_DIR/$PHP_LIBDIR] + ) + PHP_CHECK_LIBRARY($PHP_ARES_LIB, ares_inet_pton, + [AC_DEFINE([HAVE_ARES_INET_NTOP], [1], [ ])], [ ], + [$PHP_ARES_LIBADD -L$PHP_ARES_DIR/$PHP_LIBDIR] + ) dnl ########## dnl check new c-ares callback API diff --git a/php_ares.c b/php_ares.c index d28288e..08dc1d3 100644 --- a/php_ares.c +++ b/php_ares.c @@ -175,6 +175,18 @@ static const char *php_ares_T_names[] = { #define PHP_ARES_QUERY_BUFFER_LEN 2<<0xf +#ifdef HAVE_ARES_INET_PTON +# define inet_pton ares_inet_pton_wrapper +static inline int ares_inet_pton_wrapper(int af, const void *src, char *dst, socklen_t size) +{ + return dst == ares_inet_pton(af, src, dst, size); +} +#endif + +#ifdef HAVE_ARES_INET_NTOP +# define inet_ntop ares_inet_ntop +#endif + /* {{{ typedefs */ typedef struct _php_ares_options { struct ares_options strct; @@ -574,7 +586,7 @@ local php_ares_options *php_ares_options_ctor(php_ares_options *options, HashTab SUCCESS == zend_hash_get_current_data(Z_ARRVAL_PP(opt), (void *) &entry); zend_hash_move_forward(Z_ARRVAL_PP(opt))) { if (Z_TYPE_PP(entry) == IS_STRING) { - inet_aton(Z_STRVAL_PP(entry), &options->strct.servers[options->strct.nservers++]); + inet_pton(AF_INET, Z_STRVAL_PP(entry), &options->strct.servers[options->strct.nservers++]); } } if (options->strct.nservers) { @@ -710,10 +722,19 @@ local int php_ares_parse(const unsigned char *abuf, int alen, zval *result TSRML #endif switch (type) { case T_A: - spprintf(&name, 0, "%d.%d.%d.%d", pointer[0], pointer[1], pointer[2], pointer[3]); + name = ecalloc(1, 16); + inet_ntop(AF_INET, pointer, name, 16); add_assoc_string(entry, "addr", name, 0); pointer += byte_count; break; +#ifdef T_AAAA + case T_AAAA: + name = ecalloc(1, 48); + inet_ntop(AF_INET6, pointer, name, 48); + add_assoc_string(entry, "addr", name, 0); + pointer += byte_count; + break; +#endif case T_NS: case T_PTR: @@ -796,6 +817,9 @@ local int php_ares_parse(const unsigned char *abuf, int alen, zval *result TSRML break; default: +#ifndef HAVE_INET_PTON + skip: +#endif zval_ptr_dtor(&entry); entry = NULL; pointer += byte_count;