Commit 645729e9 authored by Dominick Meglio's avatar Dominick Meglio
Browse files

Added ares_getnameinfo which mimics the getnameinfo API

parent f425a25c
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
  Changelog for the c-ares project

* May 16

- Added ares_getnameinfo which mimics the getnameinfo API (another feature
  that could use testing).

* May 14

- Added an inet_ntop function from BIND for systems that do not have it.
+11 −10
Original line number Diff line number Diff line
@@ -4,14 +4,15 @@ ares_gethostbyaddr.c ares_send.c ares__read_line.c ares_gethostbyname.c \
ares_strerror.c ares_cancel.c ares_init.c ares_timeout.c ares_destroy.c	    \
ares_mkquery.c ares_version.c ares_expand_name.c ares_parse_a_reply.c	    \
windows_port.c ares_expand_string.c ares_parse_ptr_reply.c                  \
ares_parse_aaaa_reply.c inet_net_pton.c bitncmp.c inet_ntop.c
ares_parse_aaaa_reply.c ares_getnameinfo.c inet_net_pton.c bitncmp.c        \
inet_ntop.c

HHEADERS = ares.h ares_private.h setup.h ares_dns.h ares_version.h nameser.h \
           inet_net_pton.h ares_ipv6.h bitncmp.h
HHEADERS = ares.h ares_private.h setup.h ares_dns.h ares_version.h          \
           nameser.h inet_net_pton.h inet_ntop.h ares_ipv6.h bitncmp.h

MANPAGES= ares_destroy.3 ares_expand_name.3 ares_expand_string.3 ares_fds.3 \
 ares_free_hostent.3 ares_free_string.3 ares_gethostbyaddr.3		    \
 ares_gethostbyname.3 ares_init.3 ares_init_options.3 ares_mkquery.3	    \
 ares_parse_a_reply.3 ares_parse_ptr_reply.3 ares_process.3		    \
 ares_query.3 ares_search.3 ares_send.3 ares_strerror.3 ares_timeout.3	    \
 ares_version.3 ares_cancel.3 ares_parse_aaaa_reply.3
 ares_version.3 ares_cancel.3 ares_parse_aaaa_reply.3 ares_getnameinfo.3
+168 −148
Original line number Diff line number Diff line
@@ -119,6 +119,26 @@ AC_DEFUN([CARES_CHECK_STRUCT], [
  fi
])

dnl This macro determins if the specified struct contains a specific member.
dnl Syntax:
dnl CARES_CHECK_STRUCT_MEMBER(headers, struct name, member name, if found, [if not found])

AC_DEFUN([CARES_CHECK_STRUCT_MEMBER], [
  AC_MSG_CHECKING([if struct $2 has member $3])
  AC_TRY_COMPILE([$1], 
    [
      struct $2 struct_instance;
      struct_instance.$3 = 0;
    ], ac_struct="yes", ac_found="no")
  if test "$ac_struct" = "yes" ; then
    AC_MSG_RESULT(yes)
    $4
  else
    AC_MSG_RESULT(no)
    $5
  fi
])

dnl This macro determines if the specified constant exists in the specified file
dnl Syntax:
dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])
+29 −1
Original line number Diff line number Diff line
@@ -29,12 +29,14 @@

#if defined(WATT32)
  #include <netinet/in.h>
  #include <sys/socket.h>
  #include <tcp.h>
#elif defined(WIN32)
  #include <winsock.h>
  #include <windows.h>
#else
  #include <netinet/in.h>
  #include <sys/socket.h>
#endif

#ifdef  __cplusplus
@@ -64,6 +66,9 @@ extern "C" {
#define ARES_EDESTRUCTION       16
#define ARES_EBADSTR            17

/* ares_getnameinfo error codes */
#define ARES_EBADFLAGS		18

/* Flag values */
#define ARES_FLAG_USEVC         (1 << 0)
#define ARES_FLAG_PRIMARY       (1 << 1)
@@ -85,6 +90,24 @@ extern "C" {
#define ARES_OPT_DOMAINS        (1 << 7)
#define ARES_OPT_LOOKUPS        (1 << 8)

/* Nameinfo flag values */
#define ARES_NI_NOFQDN			(1 << 0)
#define ARES_NI_NUMERICHOST		(1 << 1)
#define ARES_NI_NAMEREQD		(1 << 2)
#define ARES_NI_NUMERICSERV		(1 << 3)
#define ARES_NI_DGRAM			(1 << 4)
#define ARES_NI_TCP			0
#define ARES_NI_UDP			ARES_NI_DGRAM
#define ARES_NI_SCTP			(1 << 5)
#define ARES_NI_DCCP			(1 << 6)
#define ARES_NI_NUMERICSCOPE		(1 << 7)
#define ARES_NI_LOOKUPHOST		(1 << 8)
#define ARES_NI_LOOKUPSERVICE		(1 << 9)
/* Reserved for future use */
#define ARES_NI_IDN			(1 << 10)
#define ARES_NI_ALLOW_UNASSIGNED	(1 << 11)
#define ARES_NI_USE_STD3_ASCII_RULES 	(1 << 12)

struct ares_options {
  int flags;
  int timeout;
@@ -101,12 +124,15 @@ struct ares_options {

struct hostent;
struct timeval;
struct sockaddr;
struct ares_channeldata;
typedef struct ares_channeldata *ares_channel;
typedef void (*ares_callback)(void *arg, int status, unsigned char *abuf,
                              int alen);
typedef void (*ares_host_callback)(void *arg, int status,
                                   struct hostent *hostent);
typedef void (*ares_nameinfo_callback)(void *arg, int status,
                                       char *node, char *service);

int ares_init(ares_channel *channelptr);
int ares_init_options(ares_channel *channelptr, struct ares_options *options,
@@ -123,7 +149,9 @@ void ares_gethostbyname(ares_channel channel, const char *name, int family,
                        ares_host_callback callback, void *arg);
void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
                        int family, ares_host_callback callback, void *arg);

void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa,
                      socklen_t salen, int flags, ares_nameinfo_callback callback, 
                      void *arg);
int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
                             struct timeval *tv);
+145 −0
Original line number Diff line number Diff line
.\" $Id$
.\"
.\" Copyright 2005 by Dominick Meglio.
.\"
.\" 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.
.\"
.TH ARES_GETNAMEINFO 3 "16 May 2005"
.SH NAME
ares_getnameinfo \- Address-to-nodename translation in protocol-independent manner
.SH SYNOPSIS
.nf
.B #include <ares.h>
.PP
.B typedef void (*ares_nameinfo_callback)(void *\fIarg\fP, int \fIstatus\fP,
.B	char *\fInode\fP, char *\fIservice\fP)
.PP
.B void ares_getnameinfo(ares_channel \fIchannel\fP, const struct sockaddr *\fIsa\fP,
.B 	socklen_t \fIsalen\fP, int \fIflags\fP, ares_nameinfo_callback \fIcallback\fP,
.B 	void *\fIarg\fP)
.fi
.SH DESCRIPTION
The
.B ares_getnameinfo
function is defined for protocol-independent address translation. The function
is a combination of \fIares_gethostbyaddr(3)\fP and \fIgetservbyport(3)\fP. The function will
translate the address either by executing a host query on the name service channel
identified by
.IR channel 
or it will attempt to resolve it locally if possible.
The parameters
.I sa
and
.I len
give the address as a sockaddr structure, and
.I flags
gives the options that the function will use.  Valid flags are listed below:
.TP 19
.B ARES_NI_NOFQDN
Only the nodename portion of the FQDN is returned for local hosts.
.TP 19
.B ARES_NI_NUMERICHOST
The numeric form of the hostname is returned rather than the name.
.TP 19
.B ARES_NI_NAMEREQD
An error is returned if the hostname cannot be found in the DNS.
.TP 19
.B ARES_NI_NUMERICSERV
The numeric form of the service is returned rather than the name.
.TP 19
.B ARES_NI_TCP
The service name is to be looked up for the TCP protocol.
.TP 19
.B ARES_NI_UDP
The service name is to be looked up for the UDP protocol.
.TP 19
.B ARES_NI_SCTP
The service name is to be looked up for the SCTP protocol.
.TP 19
.B ARES_NI_DCCP
The service name is to be looked up for the DCCP protocol.
.TP 19
.B ARES_NI_NUMERICSCOPE
The numeric form of the scope ID is returned rather than the name.
.TP 19
.B ARES_NI_LOOKUPHOST
A hostname lookup is being requested.
.TP 19
.B ARES_NI_LOOKUPSERVICE
A service name lookup is being requested.
.PP
When the query
is complete or has 
failed, the ares library will invoke \fIcallback\fP.  Completion or failure of 
the query may happen immediately, or may happen during a later call to
\fIares_process(3)\fP, \fIares_destroy(3)\fP or \fIares_cancel(3)\fP.
.PP
The callback argument
.I arg
is copied from the
.B ares_getnameinfo
argument
.IR arg .
The callback argument
.I status
indicates whether the query succeeded and, if not, how it failed.  It
may have any of the following values:
.TP 19
.B ARES_SUCCESS
The host lookup completed successfully.
.TP 19
.B ARES_ENOTIMP
The ares library does not know how to look up addresses of type
.IR family .
.TP 19
.B ARES_ENOTFOUND
The address
.I addr
was not found.
.TP 19
.B ARES_ENOMEM
Memory was exhausted.
.TP 19
.B ARES_EDESTRUCTION
The name service channel
.I channel
is being destroyed; the query will not be completed.
.TP 19
.B ARES_EBADFLAGS
The
.I flags
parameter contains an illegal value.
.PP
On successful completion of the query, the callback argument
.I node
contains a string representing the hostname (assuming 
.B ARES_NI_LOOKUPHOST
was specified). Additionally, 
.I service
contains a string representing the service name (assuming
.B ARES_NI_LOOKUPSERVICE
was specified).
If the query did not complete successfully, or one of the values
was not requested, 
.I node
or
.I service
will be 
.BR NULL .
.SH SEE ALSO
.BR ares_process (3),
.BR ares_getaddrinfo (3)
.SH AUTHOR
Dominick Meglio
.br
Copyright 2005 by Dominick Meglio.
Loading