c-ares: upgrade to 1.9.0

This commit is contained in:
Saúl Ibarra Corretgé 2012-04-25 05:30:47 -07:00 committed by Bert Belder
parent 937d2c93ea
commit 3e425ab9ba
30 changed files with 1213 additions and 1757 deletions

View File

@ -53,8 +53,10 @@ CARES_OBJS += src/ares/ares_options.o
CARES_OBJS += src/ares/ares_parse_a_reply.o
CARES_OBJS += src/ares/ares_parse_aaaa_reply.o
CARES_OBJS += src/ares/ares_parse_mx_reply.o
CARES_OBJS += src/ares/ares_parse_naptr_reply.o
CARES_OBJS += src/ares/ares_parse_ns_reply.o
CARES_OBJS += src/ares/ares_parse_ptr_reply.o
CARES_OBJS += src/ares/ares_parse_soa_reply.o
CARES_OBJS += src/ares/ares_parse_srv_reply.o
CARES_OBJS += src/ares/ares_parse_txt_reply.o
CARES_OBJS += src/ares/ares_process.o

View File

@ -19,6 +19,8 @@
#define ARES__H
#include "ares_version.h" /* c-ares version defines */
#include "ares_build.h" /* c-ares build definitions */
#include "ares_rules.h" /* c-ares rules enforcement */
/*
* Define WIN32 when build target is Win32 API
@ -29,63 +31,14 @@
# define WIN32
#endif
/*************************** libuv patch ***************/
/*
* We want to avoid autoconf altogether since there are a finite number of
* operating systems and simply build c-ares. Therefore we do not want the
* configurations provided by ares_build.h since we are always statically
* linking c-ares into libuv. Having a system dependent ares_build.h forces
* all users of ares.h to include the correct ares_build.h. We do not care
* about the linking checks provided by ares_rules.h. This would complicate
* the libuv build process.
*/
#if defined(WIN32)
/* Configure process defines this to 1 when it finds out that system */
/* header file ws2tcpip.h must be included by the external interface. */
/* #undef CARES_PULL_WS2TCPIP_H */
# include <winsock2.h>
# include <ws2tcpip.h>
# include <windows.h>
#else /* Not Windows */
# include <sys/time.h>
# include <sys/types.h>
# include <sys/socket.h>
#endif
#if 0
/* The size of `long', as computed by sizeof. */
#define CARES_SIZEOF_LONG 4
#endif
/* Integral data type used for ares_socklen_t. */
#define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t
#if 0
/* The size of `ares_socklen_t', as computed by sizeof. */
#define CARES_SIZEOF_ARES_SOCKLEN_T 4
#endif
/* Data type definition of ares_socklen_t. */
typedef int ares_socklen_t;
#if 0 /* libuv disabled */
#include "ares_rules.h" /* c-ares rules enforcement */
#endif
/*********************** end libuv patch ***************/
#include <sys/types.h>
/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
libc5-based Linux systems. Only include it on system that are known to
require it! */
#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \
defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY)
defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \
defined(ANDROID) || defined(__ANDROID__)
#include <sys/select.h>
#endif
#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
@ -513,6 +466,26 @@ struct ares_txt_reply {
size_t length; /* length excludes null termination */
};
struct ares_naptr_reply {
struct ares_naptr_reply *next;
unsigned char *flags;
unsigned char *service;
unsigned char *regexp;
char *replacement;
unsigned short order;
unsigned short preference;
};
struct ares_soa_reply {
char *nsname;
char *hostmaster;
unsigned int serial;
unsigned int refresh;
unsigned int retry;
unsigned int expire;
unsigned int minttl;
};
/*
** Parse the buffer, starting at *abuf and of length alen bytes, previously
** obtained from an ares_search call. Put the results in *host, if nonnull.
@ -556,10 +529,20 @@ CARES_EXTERN int ares_parse_txt_reply(const unsigned char* abuf,
int alen,
struct ares_txt_reply** txt_out);
CARES_EXTERN int ares_parse_naptr_reply(const unsigned char* abuf,
int alen,
struct ares_naptr_reply** naptr_out);
CARES_EXTERN int ares_parse_soa_reply(const unsigned char* abuf,
int alen,
struct ares_soa_reply** soa_out);
CARES_EXTERN void ares_free_string(void *str);
CARES_EXTERN void ares_free_hostent(struct hostent *host);
CARES_EXTERN void ares_free_soa(struct ares_soa_reply *soa);
CARES_EXTERN void ares_free_data(void *dataptr);
CARES_EXTERN const char *ares_strerror(int code);

View File

@ -3,15 +3,15 @@
#define ARES__VERSION_H
/* This is the global package copyright */
#define ARES_COPYRIGHT "2004 - 2010 Daniel Stenberg, <daniel@haxx.se>."
#define ARES_COPYRIGHT "2004 - 2012 Daniel Stenberg, <daniel@haxx.se>."
#define ARES_VERSION_MAJOR 1
#define ARES_VERSION_MINOR 7
#define ARES_VERSION_PATCH 5
#define ARES_VERSION_MINOR 9
#define ARES_VERSION_PATCH 0
#define ARES_VERSION ((ARES_VERSION_MAJOR<<16)|\
(ARES_VERSION_MINOR<<8)|\
(ARES_VERSION_PATCH))
#define ARES_VERSION_STR "1.7.5-DEV"
#define ARES_VERSION_STR "1.9.0-DEV"
#if (ARES_VERSION >= 0x010700)
# define CARES_HAVE_ARES_LIBRARY_INIT 1

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +0,0 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${node_platform}-${cares_arch})
add_definitions(-DHAVE_CONFIG_H=1)
include(CheckLibraryExists)
check_library_exists(socket socket "" HAVE_SOCKET_LIB)
check_library_exists(nsl gethostbyname "" HAVE_NSL_LIB)
file(GLOB lib_sources *.c)
add_library(cares ${lib_sources})
if(${HAVE_SOCKET_LIB})
set(cares_libs ${cares_libs} socket)
endif()
if(${HAVE_NSL_LIB})
set(cares_libs ${cares_libs} nsl)
endif()
if(cares_libs)
target_link_libraries(cares ${cares_libs})
endif()

View File

@ -1,21 +0,0 @@
Library: c-ares, DNS resolver
Version: 1.7.3 (11 June, 2010)
Authors: Greg Hudson, Daniel Stenberg
License: MIT
Notes:
Just use waf instead of the autoconf based configure script. Delete most of
the documentation and other files distributed with it. To upgrade, run
./configure on linux, macintosh, solaris (and other supported platforms) and
copy
- ares_config.h
- ares_setup.h
- ares_build.h
into the appropriate directory.

View File

@ -1,26 +1,16 @@
c-ares version 1.7.5
c-ares version 1.9.0
Changed:
o Added ares_parse_soa_reply
Fixed:
o detection of semicolon comments in resolv.conf
o avoid using system's inet_net_pton affected by the WLB-2008080064 advisory
o replacement ares_inet_net_pton affected by the WLB-2008080064 advisory
o replacement ares_inet_ntop affected by potential out of bounds write
o added install target to Makefile.msvc
o only fall back to AF_INET searches when looking for AF_UNSPEC addresses
o fixed ares_parse_*_reply memory leaks
o Use correct sizeof in ares_getnameinfo()
o IPv6-on-windows: find DNS servers correctly
o man pages: docs for the c-ares utility programs
o getservbyport replacement for Win CE
o config_sortlist: (win32) missing else
o advance_tcp_send_queue: avoid NULL ptr dereference
o configure: fix a bashism
o ares_expand_name: Fix encoded length for indirect root
o libcares.pc generation for static MingW* cross builds
o ares_dup: UDP and TCP port byte order in saved options
Thanks go to these friendly people for their efforts and contributions:
Yang Tse, Jakub Hrozek, Gisle Vanem, Tom Hughes, David Stuart, Dima Tisnek,
Peter Pentchev, Stefan Buhler
Yang Tse, Nick Alcock, Marko Kreen
Have fun!

View File

@ -1,5 +1,5 @@
/* Copyright 1998, 2010 by the Massachusetts Institute of Technology.
/* Copyright 1998, 2011 by the Massachusetts Institute of Technology.
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
@ -31,6 +31,7 @@
#include "ares.h"
#include "inet_net_pton.h"
#include "ares_nowarn.h"
#include "ares_private.h"
int ares__get_hostent(FILE *fp, int family, struct hostent **host)
@ -219,8 +220,8 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
break;
/* Copy actual network address family and length. */
hostent->h_addrtype = addr.family;
hostent->h_length = (int)addrlen;
hostent->h_addrtype = aresx_sitoss(addr.family);
hostent->h_length = aresx_uztoss(addrlen);
/* Free line buffer. */
free(line);

View File

@ -1,5 +1,5 @@
/* Copyright (C) 2009-2010 by Daniel Stenberg
/* Copyright (C) 2009-2012 by Daniel Stenberg
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
@ -92,6 +92,27 @@ void ares_free_data(void *dataptr)
ares_free_data(ptr->data.addr_node.next);
break;
case ARES_DATATYPE_NAPTR_REPLY:
if (ptr->data.naptr_reply.next)
ares_free_data(ptr->data.naptr_reply.next);
if (ptr->data.naptr_reply.flags)
free(ptr->data.naptr_reply.flags);
if (ptr->data.naptr_reply.service)
free(ptr->data.naptr_reply.service);
if (ptr->data.naptr_reply.regexp)
free(ptr->data.naptr_reply.regexp);
if (ptr->data.naptr_reply.replacement)
free(ptr->data.naptr_reply.replacement);
break;
case ARES_DATATYPE_SOA_REPLY:
if (ptr->data.soa_reply.nsname)
free(ptr->data.soa_reply.nsname);
if (ptr->data.soa_reply.hostmaster)
free(ptr->data.soa_reply.hostmaster);
break;
default:
return;
}
@ -138,7 +159,7 @@ void *ares_malloc_data(ares_datatype type)
case ARES_DATATYPE_TXT_REPLY:
ptr->data.txt_reply.next = NULL;
ptr->data.txt_reply.txt = NULL;
ptr->data.txt_reply.length = 0;
ptr->data.txt_reply.length = 0;
break;
case ARES_DATATYPE_ADDR_NODE:
@ -148,6 +169,26 @@ void *ares_malloc_data(ares_datatype type)
sizeof(ptr->data.addr_node.addrV6));
break;
case ARES_DATATYPE_NAPTR_REPLY:
ptr->data.naptr_reply.next = NULL;
ptr->data.naptr_reply.flags = NULL;
ptr->data.naptr_reply.service = NULL;
ptr->data.naptr_reply.regexp = NULL;
ptr->data.naptr_reply.replacement = NULL;
ptr->data.naptr_reply.order = 0;
ptr->data.naptr_reply.preference = 0;
break;
case ARES_DATATYPE_SOA_REPLY:
ptr->data.soa_reply.nsname = NULL;
ptr->data.soa_reply.hostmaster = NULL;
ptr->data.soa_reply.serial = 0;
ptr->data.soa_reply.refresh = 0;
ptr->data.soa_reply.retry = 0;
ptr->data.soa_reply.expire = 0;
ptr->data.soa_reply.minttl = 0;
break;
default:
free(ptr);
return NULL;

View File

@ -1,5 +1,5 @@
/* Copyright (C) 2009-2010 by Daniel Stenberg
/* Copyright (C) 2009-2012 by Daniel Stenberg
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
@ -20,6 +20,8 @@ typedef enum {
ARES_DATATYPE_TXT_REPLY, /* struct ares_txt_reply - introduced in 1.7.0 */
ARES_DATATYPE_ADDR_NODE, /* struct ares_addr_node - introduced in 1.7.1 */
ARES_DATATYPE_MX_REPLY, /* struct ares_mx_reply - introduced in 1.7.2 */
ARES_DATATYPE_NAPTR_REPLY,/* struct ares_naptr_reply - introduced in 1.7.6 */
ARES_DATATYPE_SOA_REPLY, /* struct ares_soa_reply - introduced in 1.9.0 */
#if 0
ARES_DATATYPE_ADDR6TTL, /* struct ares_addrttl */
ARES_DATATYPE_ADDRTTL, /* struct ares_addr6ttl */
@ -53,10 +55,12 @@ struct ares_data {
ares_datatype type; /* Actual data type identifier. */
unsigned int mark; /* Private ares_data signature. */
union {
struct ares_txt_reply txt_reply;
struct ares_srv_reply srv_reply;
struct ares_addr_node addr_node;
struct ares_mx_reply mx_reply;
struct ares_txt_reply txt_reply;
struct ares_srv_reply srv_reply;
struct ares_addr_node addr_node;
struct ares_mx_reply mx_reply;
struct ares_naptr_reply naptr_reply;
struct ares_soa_reply soa_reply;
} data;
};

View File

@ -1,6 +1,6 @@
/* Copyright 1998 by the Massachusetts Institute of Technology.
* Copyright (C) 2004-2010 by Daniel Stenberg
* Copyright (C) 2004-2011 by Daniel Stenberg
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
@ -29,10 +29,12 @@ void ares_destroy_options(struct ares_options *options)
free(options->servers);
for (i = 0; i < options->ndomains; i++)
free(options->domains[i]);
free(options->domains);
if(options->domains)
free(options->domains);
if(options->sortlist)
free(options->sortlist);
free(options->lookups);
if(options->lookups)
free(options->lookups);
}
void ares_destroy(ares_channel channel)

View File

@ -1,5 +1,7 @@
#ifndef HEADER_CARES_DNS_H
#define HEADER_CARES_DNS_H
/* Copyright 1998 by the Massachusetts Institute of Technology.
/* Copyright 1998, 2011 by the Massachusetts Institute of Technology.
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
@ -14,12 +16,23 @@
* without express or implied warranty.
*/
#ifndef ARES__DNS_H
#define ARES__DNS_H
/*
* Macro DNS__16BIT reads a network short (16 bit) given in network
* byte order, and returns its value as an unsigned short.
*/
#define DNS__16BIT(p) ((unsigned short)((unsigned int) 0xffff & \
(((unsigned int)((unsigned char)(p)[0]) << 8U) | \
((unsigned int)((unsigned char)(p)[1])))))
#define DNS__16BIT(p) (((p)[0] << 8) | (p)[1])
#define DNS__32BIT(p) (((p)[0] << 24) | ((p)[1] << 16) | \
((p)[2] << 8) | (p)[3])
/*
* Macro DNS__32BIT reads a network long (32 bit) given in network
* byte order, and returns its value as an unsigned int.
*/
#define DNS__32BIT(p) ((unsigned int) \
(((unsigned int)((unsigned char)(p)[0]) << 24U) | \
((unsigned int)((unsigned char)(p)[1]) << 16U) | \
((unsigned int)((unsigned char)(p)[2]) << 8U) | \
((unsigned int)((unsigned char)(p)[3]))))
#define DNS__SET16BIT(p, v) (((p)[0] = (unsigned char)(((v) >> 8) & 0xff)), \
((p)[1] = (unsigned char)((v) & 0xff)))
@ -87,4 +100,4 @@
#define DNS_RR_SET_TTL(r) DNS__SET32BIT((r) + 4, v)
#define DNS_RR_SET_LEN(r) DNS__SET16BIT((r) + 8, v)
#endif /* ARES__DNS_H */
#endif /* HEADER_CARES_DNS_H */

View File

@ -1,5 +1,5 @@
/* Copyright 1998 by the Massachusetts Institute of Technology.
/* Copyright 1998, 2011 by the Massachusetts Institute of Technology.
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
@ -33,6 +33,7 @@
#include <stdlib.h>
#include "ares.h"
#include "ares_nowarn.h"
#include "ares_private.h" /* for the memdebug */
static int name_length(const unsigned char *encoded, const unsigned char *abuf,
@ -91,9 +92,9 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
/* indirect root label (like 0xc0 0x0c) is 2 bytes long (stupid, but
valid) */
if ((*encoded & INDIR_MASK) == INDIR_MASK)
*enclen = 2;
*enclen = 2L;
else
*enclen = 1; /* the caller should move one byte to get past this */
*enclen = 1L; /* the caller should move one byte to get past this */
return ARES_SUCCESS;
}
@ -106,7 +107,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
{
if (!indir)
{
*enclen = p + 2 - encoded;
*enclen = aresx_uztosl(p + 2U - encoded);
indir = 1;
}
p = abuf + ((*p & ~INDIR_MASK) << 8 | *(p + 1));
@ -126,7 +127,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
}
}
if (!indir)
*enclen = p + 1 - encoded;
*enclen = aresx_uztosl(p + 1U - encoded);
/* Nuke the trailing period if we wrote one. */
if (q > *s)

View File

@ -1,5 +1,5 @@
/* Copyright 1998 by the Massachusetts Institute of Technology.
/* Copyright 1998, 2011 by the Massachusetts Institute of Technology.
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
@ -49,6 +49,7 @@
#include "inet_net_pton.h"
#include "bitncmp.h"
#include "ares_platform.h"
#include "ares_nowarn.h"
#include "ares_private.h"
#ifdef WATT32
@ -300,7 +301,7 @@ static int fake_hostent(const char *name, int family,
/* Fill in the rest of the host structure and terminate the query. */
addrs[1] = NULL;
hostent.h_aliases = aliases;
hostent.h_addrtype = family;
hostent.h_addrtype = aresx_sitoss(family);
hostent.h_addr_list = addrs;
callback(arg, ARES_SUCCESS, 0, &hostent);

View File

@ -188,7 +188,7 @@ void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa,
if (sa->sa_family == AF_INET)
{
niquery->family = AF_INET;
memcpy(&niquery->addr.addr4, addr, sizeof(struct in_addr));
memcpy(&niquery->addr.addr4, addr, sizeof(niquery->addr.addr4));
ares_gethostbyaddr(channel, &addr->sin_addr,
sizeof(struct in_addr), AF_INET,
nameinfo_callback, niquery);
@ -196,7 +196,7 @@ void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa,
else
{
niquery->family = AF_INET6;
memcpy(&niquery->addr.addr6, addr6, sizeof(struct ares_in6_addr));
memcpy(&niquery->addr.addr6, addr6, sizeof(niquery->addr.addr6));
ares_gethostbyaddr(channel, &addr6->sin6_addr,
sizeof(struct ares_in6_addr), AF_INET6,
nameinfo_callback, niquery);

File diff suppressed because it is too large Load Diff

View File

@ -23,7 +23,7 @@
#ifdef USE_WINSOCK
#include <iphlpapi.h>
#include "ares_iphlpapi.h"
#include <ares_iphlpapi.h>
typedef DWORD (WINAPI *fpGetNetworkParams_t) (FIXED_INFO*, DWORD*);
typedef BOOLEAN (APIENTRY *fpSystemFunction036_t) (void*, ULONG);

View File

@ -1,5 +1,5 @@
/* Copyright (C) 2010-2011 by Daniel Stenberg
/* Copyright (C) 2010-2012 by Daniel Stenberg
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
@ -39,6 +39,19 @@
#include "ares_nowarn.h"
#if (SIZEOF_SHORT == 2)
# define CARES_MASK_SSHORT 0x7FFF
# define CARES_MASK_USHORT 0xFFFF
#elif (SIZEOF_SHORT == 4)
# define CARES_MASK_SSHORT 0x7FFFFFFF
# define CARES_MASK_USHORT 0xFFFFFFFF
#elif (SIZEOF_SHORT == 8)
# define CARES_MASK_SSHORT 0x7FFFFFFFFFFFFFFF
# define CARES_MASK_USHORT 0xFFFFFFFFFFFFFFFF
#else
# error "SIZEOF_SHORT not defined"
#endif
#if (SIZEOF_INT == 2)
# define CARES_MASK_SINT 0x7FFF
# define CARES_MASK_UINT 0xFFFF
@ -51,8 +64,44 @@
#elif (SIZEOF_INT == 16)
# define CARES_MASK_SINT 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
# define CARES_MASK_UINT 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
#else
# error "SIZEOF_INT not defined"
#endif
#if (CARES_SIZEOF_LONG == 2)
# define CARES_MASK_SLONG 0x7FFFL
# define CARES_MASK_ULONG 0xFFFFUL
#elif (CARES_SIZEOF_LONG == 4)
# define CARES_MASK_SLONG 0x7FFFFFFFL
# define CARES_MASK_ULONG 0xFFFFFFFFUL
#elif (CARES_SIZEOF_LONG == 8)
# define CARES_MASK_SLONG 0x7FFFFFFFFFFFFFFFL
# define CARES_MASK_ULONG 0xFFFFFFFFFFFFFFFFUL
#elif (CARES_SIZEOF_LONG == 16)
# define CARES_MASK_SLONG 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFL
# define CARES_MASK_ULONG 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFUL
#else
# error "CARES_SIZEOF_LONG not defined"
#endif
/*
** unsigned size_t to signed long
*/
long aresx_uztosl(size_t uznum)
{
#ifdef __INTEL_COMPILER
# pragma warning(push)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif
return (long)(uznum & (size_t) CARES_MASK_SLONG);
#ifdef __INTEL_COMPILER
# pragma warning(pop)
#endif
}
/*
** unsigned size_t to signed int
*/
@ -71,6 +120,43 @@ int aresx_uztosi(size_t uznum)
#endif
}
/*
** unsigned size_t to signed short
*/
short aresx_uztoss(size_t uznum)
{
#ifdef __INTEL_COMPILER
# pragma warning(push)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif
return (short)(uznum & (size_t) CARES_MASK_SSHORT);
#ifdef __INTEL_COMPILER
# pragma warning(pop)
#endif
}
/*
** signed int to signed short
*/
short aresx_sitoss(int sinum)
{
#ifdef __INTEL_COMPILER
# pragma warning(push)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif
DEBUGASSERT(sinum >= 0);
return (short)(sinum & (int) CARES_MASK_SSHORT);
#ifdef __INTEL_COMPILER
# pragma warning(pop)
#endif
}
/*
** signed long to signed int
*/
@ -128,6 +214,25 @@ unsigned int aresx_sztoui(ssize_t sznum)
#endif
}
/*
** signed int to unsigned short
*/
unsigned short aresx_sitous(int sinum)
{
#ifdef __INTEL_COMPILER
# pragma warning(push)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif
DEBUGASSERT(sinum >= 0);
return (unsigned short)(sinum & (int) CARES_MASK_USHORT);
#ifdef __INTEL_COMPILER
# pragma warning(pop)
#endif
}
#if defined(__INTEL_COMPILER) && defined(__unix__)
int aresx_FD_ISSET(int fd, fd_set *fdset)

View File

@ -2,7 +2,7 @@
#define HEADER_CARES_NOWARN_H
/* Copyright (C) 2010-2011 by Daniel Stenberg
/* Copyright (C) 2010-2012 by Daniel Stenberg
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
@ -17,7 +17,11 @@
* without express or implied warranty.
*/
int aresx_uztosi(size_t uznum);
long aresx_uztosl(size_t uznum);
int aresx_uztosi(size_t uznum);
short aresx_uztoss(size_t uznum);
short aresx_sitoss(int sinum);
int aresx_sltosi(long slnum);
@ -25,6 +29,8 @@ int aresx_sztosi(ssize_t sznum);
unsigned int aresx_sztoui(ssize_t sznum);
unsigned short aresx_sitous(int sinum);
#if defined(__INTEL_COMPILER) && defined(__unix__)
int aresx_FD_ISSET(int fd, fd_set *fdset);

View File

@ -204,7 +204,9 @@ int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
}
}
if (status == ARES_SUCCESS && naddrs == 0)
/* the check for naliases to be zero is to make sure CNAME responses
don't get caught here */
if (status == ARES_SUCCESS && naddrs == 0 && naliases == 0)
status = ARES_ENODATA;
if (status == ARES_SUCCESS)
{

View File

@ -0,0 +1,188 @@
/* Copyright 1998 by the Massachusetts Institute of Technology.
* Copyright (C) 2009 by Jakub Hrozek <jhrozek@redhat.com>
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting
* documentation, and that the name of M.I.T. not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is"
* without express or implied warranty.
*/
#include "ares_setup.h"
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#ifdef HAVE_ARPA_NAMESER_H
# include <arpa/nameser.h>
#else
# include "nameser.h"
#endif
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
# include <arpa/nameser_compat.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "ares.h"
#include "ares_dns.h"
#include "ares_data.h"
#include "ares_private.h"
/* AIX portability check */
#ifndef T_NAPTR
#define T_NAPTR 35 /* naming authority pointer */
#endif
int
ares_parse_naptr_reply (const unsigned char *abuf, int alen,
struct ares_naptr_reply **naptr_out)
{
unsigned int qdcount, ancount, i;
const unsigned char *aptr, *vptr;
int status, rr_type, rr_class, rr_len;
long len;
char *hostname = NULL, *rr_name = NULL;
struct ares_naptr_reply *naptr_head = NULL;
struct ares_naptr_reply *naptr_last = NULL;
struct ares_naptr_reply *naptr_curr;
/* Set *naptr_out to NULL for all failure cases. */
*naptr_out = NULL;
/* Give up if abuf doesn't have room for a header. */
if (alen < HFIXEDSZ)
return ARES_EBADRESP;
/* Fetch the question and answer count from the header. */
qdcount = DNS_HEADER_QDCOUNT (abuf);
ancount = DNS_HEADER_ANCOUNT (abuf);
if (qdcount != 1)
return ARES_EBADRESP;
if (ancount == 0)
return ARES_ENODATA;
/* Expand the name from the question, and skip past the question. */
aptr = abuf + HFIXEDSZ;
status = ares_expand_name (aptr, abuf, alen, &hostname, &len);
if (status != ARES_SUCCESS)
return status;
if (aptr + len + QFIXEDSZ > abuf + alen)
{
free (hostname);
return ARES_EBADRESP;
}
aptr += len + QFIXEDSZ;
/* Examine each answer resource record (RR) in turn. */
for (i = 0; i < ancount; i++)
{
/* Decode the RR up to the data field. */
status = ares_expand_name (aptr, abuf, alen, &rr_name, &len);
if (status != ARES_SUCCESS)
{
break;
}
aptr += len;
if (aptr + RRFIXEDSZ > abuf + alen)
{
status = ARES_EBADRESP;
break;
}
rr_type = DNS_RR_TYPE (aptr);
rr_class = DNS_RR_CLASS (aptr);
rr_len = DNS_RR_LEN (aptr);
aptr += RRFIXEDSZ;
/* Check if we are really looking at a NAPTR record */
if (rr_class == C_IN && rr_type == T_NAPTR)
{
/* parse the NAPTR record itself */
/* Allocate storage for this NAPTR answer appending it to the list */
naptr_curr = ares_malloc_data(ARES_DATATYPE_NAPTR_REPLY);
if (!naptr_curr)
{
status = ARES_ENOMEM;
break;
}
if (naptr_last)
{
naptr_last->next = naptr_curr;
}
else
{
naptr_head = naptr_curr;
}
naptr_last = naptr_curr;
vptr = aptr;
naptr_curr->order = DNS__16BIT(vptr);
vptr += sizeof(unsigned short);
naptr_curr->preference = DNS__16BIT(vptr);
vptr += sizeof(unsigned short);
status = ares_expand_string(vptr, abuf, alen, &naptr_curr->flags, &len);
if (status != ARES_SUCCESS)
break;
vptr += len;
status = ares_expand_string(vptr, abuf, alen, &naptr_curr->service, &len);
if (status != ARES_SUCCESS)
break;
vptr += len;
status = ares_expand_string(vptr, abuf, alen, &naptr_curr->regexp, &len);
if (status != ARES_SUCCESS)
break;
vptr += len;
status = ares_expand_name(vptr, abuf, alen, &naptr_curr->replacement, &len);
if (status != ARES_SUCCESS)
break;
}
/* Don't lose memory in the next iteration */
free (rr_name);
rr_name = NULL;
/* Move on to the next record */
aptr += rr_len;
}
if (hostname)
free (hostname);
if (rr_name)
free (rr_name);
/* clean up on error */
if (status != ARES_SUCCESS)
{
if (naptr_head)
ares_free_data (naptr_head);
return status;
}
/* everything looks fine, return the data */
*naptr_out = naptr_head;
return ARES_SUCCESS;
}

View File

@ -42,6 +42,7 @@
#include <string.h>
#include "ares.h"
#include "ares_dns.h"
#include "ares_nowarn.h"
#include "ares_private.h"
int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
@ -189,8 +190,8 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
for (i=0 ; i<aliascnt ; i++)
hostent->h_aliases[i] = aliases[i];
hostent->h_aliases[aliascnt] = NULL;
hostent->h_addrtype = family;
hostent->h_length = addrlen;
hostent->h_addrtype = aresx_sitoss(family);
hostent->h_length = aresx_sitoss(addrlen);
memcpy(hostent->h_addr_list[0], addr, addrlen);
hostent->h_addr_list[1] = NULL;
*host = hostent;

View File

@ -0,0 +1,135 @@
/* Copyright 1998 by the Massachusetts Institute of Technology.
* Copyright (C) 2012 Marko Kreen <markokr@gmail.com>
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting
* documentation, and that the name of M.I.T. not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is"
* without express or implied warranty.
*/
#include "ares_setup.h"
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#ifdef HAVE_ARPA_NAMESER_H
# include <arpa/nameser.h>
#else
# include "nameser.h"
#endif
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
# include <arpa/nameser_compat.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "ares.h"
#include "ares_dns.h"
#include "ares_data.h"
#include "ares_private.h"
int
ares_parse_soa_reply(const unsigned char *abuf, int alen,
struct ares_soa_reply **soa_out)
{
const unsigned char *aptr;
long len;
char *qname = NULL, *rr_name = NULL;
struct ares_soa_reply *soa = NULL;
int qdcount, ancount;
int status;
if (alen < HFIXEDSZ)
return ARES_EBADRESP;
/* parse message header */
qdcount = DNS_HEADER_QDCOUNT(abuf);
ancount = DNS_HEADER_ANCOUNT(abuf);
if (qdcount != 1 || ancount != 1)
return ARES_EBADRESP;
aptr = abuf + HFIXEDSZ;
/* query name */
status = ares__expand_name_for_response(aptr, abuf, alen, &qname, &len);
if (status != ARES_SUCCESS)
goto failed_stat;
aptr += len;
/* skip qtype & qclass */
if (aptr + QFIXEDSZ > abuf + alen)
goto failed;
aptr += QFIXEDSZ;
/* rr_name */
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len);
if (status != ARES_SUCCESS)
goto failed_stat;
aptr += len;
/* skip rr_type, rr_class, rr_ttl, rr_rdlen */
if (aptr + RRFIXEDSZ > abuf + alen)
goto failed;
aptr += RRFIXEDSZ;
/* allocate result struct */
soa = ares_malloc_data(ARES_DATATYPE_SOA_REPLY);
if (!soa)
return ARES_ENOMEM;
/* nsname */
status = ares__expand_name_for_response(aptr, abuf, alen, &soa->nsname, &len);
if (status != ARES_SUCCESS)
goto failed_stat;
aptr += len;
/* hostmaster */
status = ares__expand_name_for_response(aptr, abuf, alen, &soa->hostmaster, &len);
if (status != ARES_SUCCESS)
goto failed_stat;
aptr += len;
/* integer fields */
if (aptr + 5 * 4 > abuf + alen)
goto failed;
soa->serial = DNS__32BIT(aptr + 0 * 4);
soa->refresh = DNS__32BIT(aptr + 1 * 4);
soa->retry = DNS__32BIT(aptr + 2 * 4);
soa->expire = DNS__32BIT(aptr + 3 * 4);
soa->minttl = DNS__32BIT(aptr + 4 * 4);
free(qname);
free(rr_name);
*soa_out = soa;
return ARES_SUCCESS;
failed:
status = ARES_EBADRESP;
failed_stat:
ares_free_data(soa);
if (qname)
free(qname);
if (rr_name)
free(rr_name);
return status;
}

View File

@ -342,7 +342,7 @@ long ares__tvdiff(struct timeval t1, struct timeval t2);
do { \
if ((c)->sock_state_cb) \
(c)->sock_state_cb((c)->sock_state_cb_data, (s), (r), (w)); \
} while (0)
} WHILE_FALSE
#ifdef CURLDEBUG
/* This is low-level hard-hacking memory leak tracking and similar. Using the

View File

@ -1,6 +1,6 @@
/* Copyright 1998 by the Massachusetts Institute of Technology.
* Copyright (C) 2004-2010 by Daniel Stenberg
* Copyright (C) 2004-2012 by Daniel Stenberg
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
@ -837,30 +837,29 @@ static int setsocknonblock(ares_socket_t sockfd, /* operate on this */
#elif defined(HAVE_IOCTL_FIONBIO)
/* older unix versions */
int flags;
flags = nonblock;
int flags = nonblock ? 1 : 0;
return ioctl(sockfd, FIONBIO, &flags);
#elif defined(HAVE_IOCTLSOCKET_FIONBIO)
#ifdef WATT32
char flags;
char flags = nonblock ? 1 : 0;
#else
/* Windows */
unsigned long flags;
unsigned long flags = nonblock ? 1UL : 0UL;
#endif
flags = nonblock;
return ioctlsocket(sockfd, FIONBIO, &flags);
#elif defined(HAVE_IOCTLSOCKET_CAMEL_FIONBIO)
/* Amiga */
return IoctlSocket(sockfd, FIONBIO, (long)nonblock);
long flags = nonblock ? 1L : 0L;
return IoctlSocket(sockfd, FIONBIO, flags);
#elif defined(HAVE_SETSOCKOPT_SO_NONBLOCK)
/* BeOS */
long b = nonblock ? 1 : 0;
long b = nonblock ? 1L : 0L;
return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
#else
@ -947,7 +946,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
salen = sizeof(saddr.sa4);
memset(sa, 0, salen);
saddr.sa4.sin_family = AF_INET;
saddr.sa4.sin_port = (unsigned short)(channel->tcp_port & 0xffff);
saddr.sa4.sin_port = aresx_sitous(channel->tcp_port);
memcpy(&saddr.sa4.sin_addr, &server->addr.addrV4,
sizeof(server->addr.addrV4));
break;
@ -956,7 +955,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
salen = sizeof(saddr.sa6);
memset(sa, 0, salen);
saddr.sa6.sin6_family = AF_INET6;
saddr.sa6.sin6_port = (unsigned short)(channel->tcp_port & 0xffff);
saddr.sa6.sin6_port = aresx_sitous(channel->tcp_port);
memcpy(&saddr.sa6.sin6_addr, &server->addr.addrV6,
sizeof(server->addr.addrV6));
break;
@ -1039,7 +1038,7 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
salen = sizeof(saddr.sa4);
memset(sa, 0, salen);
saddr.sa4.sin_family = AF_INET;
saddr.sa4.sin_port = (unsigned short)(channel->udp_port & 0xffff);
saddr.sa4.sin_port = aresx_sitous(channel->udp_port);
memcpy(&saddr.sa4.sin_addr, &server->addr.addrV4,
sizeof(server->addr.addrV4));
break;
@ -1048,7 +1047,7 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
salen = sizeof(saddr.sa6);
memset(sa, 0, salen);
saddr.sa6.sin6_family = AF_INET6;
saddr.sa6.sin6_port = (unsigned short)(channel->udp_port & 0xffff);
saddr.sa6.sin6_port = aresx_sitous(channel->udp_port);
memcpy(&saddr.sa6.sin6_addr, &server->addr.addrV6,
sizeof(server->addr.addrV6));
break;

View File

@ -77,7 +77,7 @@ void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
}
/* Compute the query ID. Start with no timeout. */
query->qid = (unsigned short)DNS_HEADER_QID(qbuf);
query->qid = DNS_HEADER_QID(qbuf);
query->timeout.tv_sec = 0;
query->timeout.tv_usec = 0;

View File

@ -2,7 +2,7 @@
#define HEADER_CARES_SETUP_H
/* Copyright (C) 2004 - 2009 by Daniel Stenberg et al
/* Copyright (C) 2004 - 2012 by Daniel Stenberg et al
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
@ -75,7 +75,6 @@
/* please, do it beyond the point further indicated in this file. */
/* ================================================================ */
#if 0 /* libuv hack */
/*
* c-ares external interface definitions are also used internally,
* and might also include required system header files to define them.
@ -88,7 +87,6 @@
*/
#include <ares_rules.h>
#endif /* libuv hack */
/* ================================================================= */
/* No system header file shall be included in this file before this */
@ -159,12 +157,32 @@
#endif /* HAVE_CONFIG_H */
/*
* Arg 2 type for gethostname in case it hasn't been defined in config file.
*/
#ifndef GETHOSTNAME_TYPE_ARG2
# ifdef USE_WINSOCK
# define GETHOSTNAME_TYPE_ARG2 int
# else
# define GETHOSTNAME_TYPE_ARG2 size_t
# endif
#endif
#ifdef __POCC__
# include <sys/types.h>
# include <unistd.h>
# define ESRCH 3
#endif
/*
* Android does have the arpa/nameser.h header which is detected by configure
* but it appears to be empty with recent NDK r7b / r7c, so we undefine here.
*/
#if (defined(ANDROID) || defined(__ANDROID__)) && defined(HAVE_ARPA_NAMESER_H)
# undef HAVE_ARPA_NAMESER_H
#endif
/*
* Recent autoconf versions define these symbols in ares_config.h. We don't
* want them (since they collide with the libcurl ones when we build

View File

@ -62,19 +62,20 @@ struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
min_offset = offset;
}
if(min_offset != -1) {
nextstop.tv_sec = min_offset/1000;
nextstop.tv_usec = (min_offset%1000)*1000;
}
/* If we found a minimum timeout and it's sooner than the one specified in
* maxtv (if any), return it. Otherwise go with maxtv.
*/
if (min_offset != -1 && (!maxtv || ares__timedout(maxtv, &nextstop)))
if (min_offset != -1)
{
*tvbuf = nextstop;
return tvbuf;
nextstop.tv_sec = min_offset/1000;
nextstop.tv_usec = (min_offset%1000)*1000;
if (!maxtv || ares__timedout(maxtv, &nextstop))
{
*tvbuf = nextstop;
return tvbuf;
}
}
else
return maxtv;
return maxtv;
}

View File

@ -2,7 +2,7 @@
#define __SETUP_ONCE_H
/* Copyright (C) 2004 - 2011 by Daniel Stenberg et al
/* Copyright (C) 2004 - 2012 by Daniel Stenberg et al
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
@ -72,7 +72,7 @@
#include <fcntl.h>
#endif
#ifdef HAVE_STDBOOL_H
#if defined(HAVE_STDBOOL_H) && defined(HAVE_BOOL_T)
#include <stdbool.h>
#endif
@ -299,6 +299,27 @@ struct timeval {
#endif
/*
* Macro WHILE_FALSE may be used to build single-iteration do-while loops,
* avoiding compiler warnings. Mostly intended for other macro definitions.
*/
#define WHILE_FALSE while(0)
#if defined(_MSC_VER) && !defined(__POCC__)
# undef WHILE_FALSE
# if (_MSC_VER < 1500)
# define WHILE_FALSE while(1, 0)
# else
# define WHILE_FALSE \
__pragma(warning(push)) \
__pragma(warning(disable:4127)) \
while(0) \
__pragma(warning(pop))
# endif
#endif
/*
* Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
*/
@ -336,7 +357,7 @@ typedef int sig_atomic_t;
#ifdef DEBUGBUILD
#define DEBUGF(x) x
#else
#define DEBUGF(x) do { } while (0)
#define DEBUGF(x) do { } WHILE_FALSE
#endif
@ -347,7 +368,7 @@ typedef int sig_atomic_t;
#if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
#define DEBUGASSERT(x) assert(x)
#else
#define DEBUGASSERT(x) do { } while (0)
#define DEBUGASSERT(x) do { } WHILE_FALSE
#endif
@ -459,18 +480,6 @@ typedef int sig_atomic_t;
#endif
/*
* System error codes for Windows CE
*/
#if defined(WIN32) && !defined(HAVE_ERRNO_H)
#define ENOENT ERROR_FILE_NOT_FOUND
#define ESRCH ERROR_PATH_NOT_FOUND
#define ENOMEM ERROR_NOT_ENOUGH_MEMORY
#define ENOSPC ERROR_INVALID_PARAMETER
#endif
/*
* Actually use __32_getpwuid() on 64-bit VMS builds for getpwuid()
*/
@ -501,4 +510,3 @@ typedef int sig_atomic_t;
#endif /* __SETUP_ONCE_H */

2
uv.gyp
View File

@ -85,8 +85,10 @@
'src/ares/ares_parse_aaaa_reply.c',
'src/ares/ares_parse_a_reply.c',
'src/ares/ares_parse_mx_reply.c',
'src/ares/ares_parse_naptr_reply.c',
'src/ares/ares_parse_ns_reply.c',
'src/ares/ares_parse_ptr_reply.c',
'src/ares/ares_parse_soa_reply.c',
'src/ares/ares_parse_srv_reply.c',
'src/ares/ares_parse_txt_reply.c',
'src/ares/ares_platform.h',