mirror of
https://github.com/curl/curl.git
synced 2025-04-12 16:20:35 +08:00
remove the ares subtree
c-ares is now hosted entirely separate from the curl project see http://c-ares.haxx.se/ for all details concerning c-ares, its source repository and more.
This commit is contained in:
parent
4b351d018e
commit
4259d2df7d
@ -1,35 +0,0 @@
|
||||
*.html
|
||||
*.lo
|
||||
*.pdf
|
||||
.deps
|
||||
.libs
|
||||
MSVC*
|
||||
Makefile
|
||||
Makefile.in
|
||||
aclocal.m4
|
||||
acountry
|
||||
adig
|
||||
ahost
|
||||
ares_build.h
|
||||
ares_config.h
|
||||
ares_config.h.in
|
||||
ares_version.h.dist
|
||||
autom4te.cache
|
||||
compile
|
||||
config.guess
|
||||
config.h
|
||||
config.h.in
|
||||
config.log
|
||||
config.lt
|
||||
config.status
|
||||
config.sub
|
||||
configure
|
||||
depcomp
|
||||
libcares.la
|
||||
libcares.pc
|
||||
libtool
|
||||
ltmain.sh
|
||||
man3
|
||||
missing
|
||||
msvc*
|
||||
stamp-h*
|
9
ares/.gitignore
vendored
9
ares/.gitignore
vendored
@ -1,9 +0,0 @@
|
||||
acountry
|
||||
adig
|
||||
ahost
|
||||
ares_build.h
|
||||
ares_config.h
|
||||
ares_config.h.in
|
||||
libcares.pc
|
||||
stamp-h1
|
||||
stamp-h2
|
37
ares/AUTHORS
37
ares/AUTHORS
@ -1,37 +0,0 @@
|
||||
c-ares is based on ares, and these are the people that have worked on it since
|
||||
the fork was made:
|
||||
|
||||
Alexander Lazic
|
||||
Alexey Simak
|
||||
Andreas Rieke
|
||||
Ashish Sharma
|
||||
Brad House
|
||||
Brad Spencer
|
||||
Bram Matthys
|
||||
Dan Fandrich
|
||||
Daniel Stenberg
|
||||
Dirk Manske
|
||||
Dominick Meglio
|
||||
Doug Goldstein
|
||||
Duncan Wilcox
|
||||
Eino Tuominen
|
||||
Erik Kline
|
||||
George Neill
|
||||
Gisle Vanem
|
||||
Guilherme Balena Versiani
|
||||
Gunter Knauf
|
||||
Henrik Stoerner
|
||||
James Bursa
|
||||
Michael Wallner
|
||||
Nick Mathewson
|
||||
Phil Blundell
|
||||
Ravi Pratap
|
||||
Robin Cornelius
|
||||
Sebastian at basti79.de
|
||||
Shmulik Regev
|
||||
Steinar H. Gunderson
|
||||
Tofu Linden
|
||||
Vlad Dinulescu
|
||||
William Ahern
|
||||
Yang Tse
|
||||
liren at vivisimo.com
|
1151
ares/CHANGES
1151
ares/CHANGES
File diff suppressed because it is too large
Load Diff
@ -1,7 +0,0 @@
|
||||
|
||||
CVS-INFO
|
||||
|
||||
This file is only present in the CVS - never in release archives. It is used
|
||||
as a sentinel file in buildconf.bat in order to differentiate a CVS checkout
|
||||
from release and daily snapshot archives.
|
||||
|
171
ares/Makefile.am
171
ares/Makefile.am
@ -1,171 +0,0 @@
|
||||
AUTOMAKE_OPTIONS = foreign nostdinc
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
# Specify our include paths here, and do it relative to $(top_srcdir) and
|
||||
# $(top_builddir), to ensure that these paths which belong to the library
|
||||
# being currently built and tested are searched before the library which
|
||||
# might possibly already be installed in the system.
|
||||
#
|
||||
# When using the low-level hard-hacking memory leak tracking code from
|
||||
# libcurl the generated curl/curlbuild.h file must also be reachable.
|
||||
# Using the libcurl lowlevel code from within c-ares library is ugly and
|
||||
# only works when c-ares is built and linked with a similarly debug-build
|
||||
# libcurl, but we do this anyway for convenience.
|
||||
#
|
||||
# $(top_builddir)/../include/curl for generated curlbuild.h included from curl.h
|
||||
# $(top_builddir)/../include is for libcurl's generated curl/curlbuild.h file
|
||||
# $(top_srcdir)/../include is for libcurl's external include files
|
||||
# $(top_builddir)/../lib is for libcurl's generated lib/curl_config.h file
|
||||
# $(top_srcdir)/../lib is for libcurl's lib/setup.h and other "private" files
|
||||
# $(top_builddir) is for c-ares's generated ares_config.h file
|
||||
# $(top_srcdir) is for c-ares's ares_setup.h and other "c-ares-private" files
|
||||
|
||||
if CURLDEBUG
|
||||
INCLUDES = -I$(top_builddir)/../include/curl \
|
||||
-I$(top_builddir)/../include \
|
||||
-I$(top_srcdir)/../include \
|
||||
-I$(top_builddir)/../lib \
|
||||
-I$(top_srcdir)/../lib \
|
||||
-I$(top_builddir) \
|
||||
-I$(top_srcdir)
|
||||
else
|
||||
INCLUDES = -I$(top_builddir) \
|
||||
-I$(top_srcdir)
|
||||
endif
|
||||
|
||||
lib_LTLIBRARIES = libcares.la
|
||||
|
||||
man_MANS = $(MANPAGES)
|
||||
|
||||
MSVCFILES = vc/vc6aws.dsw vc/acountry/vc6acountry.dsp vc/adig/vc6adig.dsp \
|
||||
vc/ahost/vc6ahost.dsp vc/cares/vc6cares.dsp vc/cares/vc6cares.dsw
|
||||
|
||||
if CURLDEBUG
|
||||
PROGS =
|
||||
else
|
||||
PROGS = ahost adig acountry
|
||||
endif
|
||||
|
||||
noinst_PROGRAMS =$(PROGS)
|
||||
|
||||
# adig and ahost are just sample programs and thus not mentioned with the
|
||||
# regular sources and headers
|
||||
EXTRA_DIST = AUTHORS CHANGES README.cares Makefile.inc Makefile.dj \
|
||||
Makefile.m32 Makefile.netware Makefile.msvc $(man_MANS) $(MSVCFILES) \
|
||||
config-win32.h RELEASE-NOTES libcares.pc.in buildconf get_ver.awk maketgz \
|
||||
TODO ares_build.h.in $(PDFPAGES) cares.rc README.msvc
|
||||
|
||||
CLEANFILES = $(PDFPAGES) $(HTMLPAGES)
|
||||
|
||||
DISTCLEANFILES = ares_build.h
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = libcares.pc
|
||||
|
||||
VER=-version-info 2:0:0
|
||||
# This flag accepts an argument of the form current[:revision[:age]]. So,
|
||||
# passing -version-info 3:12:1 sets current to 3, revision to 12, and age to
|
||||
# 1.
|
||||
#
|
||||
# If either revision or age are omitted, they default to 0. Also note that age
|
||||
# must be less than or equal to the current interface number.
|
||||
#
|
||||
# Here are a set of rules to help you update your library version information:
|
||||
#
|
||||
# 1.Start with version information of 0:0:0 for each libtool library.
|
||||
#
|
||||
# 2.Update the version information only immediately before a public release of
|
||||
# your software. More frequent updates are unnecessary, and only guarantee
|
||||
# that the current interface number gets larger faster.
|
||||
#
|
||||
# 3.If the library source code has changed at all since the last update, then
|
||||
# increment revision (c:r+1:a)
|
||||
#
|
||||
# 4.If any interfaces have been added, removed, or changed since the last
|
||||
# update, increment current, and set revision to 0. (c+1:r=0:a)
|
||||
#
|
||||
# 5.If any interfaces have been added since the last public release, then
|
||||
# increment age. (c:r:a+1)
|
||||
#
|
||||
# 6.If any interfaces have been removed since the last public release, then
|
||||
# set age to 0. (c:r:a=0)
|
||||
#
|
||||
|
||||
if NO_UNDEFINED
|
||||
# The -no-undefined flag is crucial for this to build fine on some platforms
|
||||
UNDEF = -no-undefined
|
||||
endif
|
||||
|
||||
libcares_la_LDFLAGS = $(UNDEF) $(VER)
|
||||
|
||||
# Makefile.inc provides the CSOURCES and HHEADERS defines
|
||||
include Makefile.inc
|
||||
|
||||
libcares_la_SOURCES = $(CSOURCES) $(HHEADERS)
|
||||
|
||||
# where to install the c-ares headers
|
||||
libcares_ladir = $(includedir)
|
||||
# what headers to install on 'make install':
|
||||
libcares_la_HEADERS = ares.h ares_version.h ares_dns.h \
|
||||
ares_build.h ares_rules.h
|
||||
|
||||
ahost_SOURCES = ahost.c $(SAMPLESOURCES) $(SAMPLEHEADERS)
|
||||
ahost_LDADD = $(top_builddir)/libcares.la
|
||||
ahost_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
adig_SOURCES = adig.c $(SAMPLESOURCES) $(SAMPLEHEADERS)
|
||||
adig_LDADD = $(top_builddir)/libcares.la
|
||||
adig_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
acountry_SOURCES = acountry.c $(SAMPLESOURCES) $(SAMPLEHEADERS)
|
||||
acountry_LDADD = $(top_builddir)/libcares.la
|
||||
acountry_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
SOURCEDMANDIR = man3
|
||||
SOURCEDMANPAGES = ares_init.3
|
||||
|
||||
clean-local: clean-sourced-manpages
|
||||
|
||||
clean-sourced-manpages:
|
||||
@srcdmandir='$(SOURCEDMANDIR)'; \
|
||||
echo "rm -rf $(top_builddir)/$$srcdmandir"; \
|
||||
rm -rf $(top_builddir)/$$srcdmandir
|
||||
|
||||
sourced-manpages: clean-sourced-manpages
|
||||
@srcdmandir='$(SOURCEDMANDIR)'; \
|
||||
srcdmanfiles='$(SOURCEDMANPAGES)'; \
|
||||
mkdir $(top_builddir)/$$srcdmandir; \
|
||||
for file in $$srcdmanfiles; do \
|
||||
if test -f $(top_srcdir)/$$file; then \
|
||||
echo "cp $(top_srcdir)/$$file $(top_builddir)/$$srcdmandir/$$file"; \
|
||||
cp $(top_srcdir)/$$file $(top_builddir)/$$srcdmandir/$$file; \
|
||||
fi; \
|
||||
done
|
||||
|
||||
MAN2HTML = roffit --mandir=. < $< >$@
|
||||
|
||||
SUFFIXES = .3 .html
|
||||
|
||||
html: sourced-manpages $(HTMLPAGES)
|
||||
|
||||
.3.html:
|
||||
$(MAN2HTML)
|
||||
|
||||
pdf: sourced-manpages $(PDFPAGES)
|
||||
|
||||
.3.pdf:
|
||||
@(foo=`echo $@ | sed -e 's/\.[0-9]$$//g'`; \
|
||||
groff -Tps -man $< >$$foo.ps; \
|
||||
ps2pdf $$foo.ps $@; \
|
||||
rm $$foo.ps; \
|
||||
echo "converted $< to $@")
|
||||
|
||||
# Make files named *.dist replace the file without .dist extension
|
||||
dist-hook:
|
||||
find $(distdir) -name "*.dist" -exec rm {} \;
|
||||
(distit=`find $(srcdir) -name "*.dist"`; \
|
||||
for file in $$distit; do \
|
||||
strip=`echo $$file | sed -e s/^$(srcdir)// -e s/\.dist//`; \
|
||||
cp $$file $(distdir)$$strip; \
|
||||
done)
|
@ -1,86 +0,0 @@
|
||||
#
|
||||
# c-ares Makefile for djgpp/gcc/Watt-32.
|
||||
# By Gisle Vanem <gvanem@broadpark.no> 2004.
|
||||
#
|
||||
# $Id$
|
||||
|
||||
|
||||
TOPDIR = ..
|
||||
|
||||
DEPEND_PREREQ = ares_config.h
|
||||
|
||||
include ../packages/DOS/common.dj
|
||||
include Makefile.inc
|
||||
|
||||
CFLAGS += -DWATT32 -Dselect=select_s
|
||||
|
||||
LDFLAGS = -s
|
||||
|
||||
ifeq ($(USE_CURLDEBUG),1)
|
||||
EX_LIBS = ../lib/libcurl.a
|
||||
OBJ_HACK = $(OBJECTS)
|
||||
else
|
||||
OBJ_HACK = libcares.a
|
||||
endif
|
||||
|
||||
ifeq ($(USE_SSL),1)
|
||||
EX_LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a
|
||||
endif
|
||||
|
||||
ifeq ($(USE_ZLIB),1)
|
||||
EX_LIBS += $(ZLIB_ROOT)/libz.a
|
||||
endif
|
||||
|
||||
ifeq ($(USE_IDNA),1)
|
||||
EX_LIBS += $(LIBIDN_ROOT)/lib/dj_obj/libidn.a -liconv
|
||||
endif
|
||||
|
||||
EX_LIBS += $(WATT32_ROOT)/lib/libwatt.a
|
||||
|
||||
OBJECTS = $(addprefix $(OBJ_DIR)/, $(CSOURCES:.c=.o))
|
||||
|
||||
all: $(OBJ_DIR) ares_config.h libcares.a ahost.exe adig.exe acountry.exe
|
||||
@echo Welcome to c-ares.
|
||||
|
||||
libcares.a: $(OBJECTS)
|
||||
ar rs $@ $?
|
||||
|
||||
ares_config.h: config.dos
|
||||
$(COPY) $^ $@
|
||||
|
||||
ahost.exe: ahost.c $(OBJ_DIR)/ares_getopt.o $(OBJ_HACK)
|
||||
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(EX_LIBS)
|
||||
|
||||
adig.exe: adig.c $(OBJ_DIR)/ares_getopt.o $(OBJ_HACK)
|
||||
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(EX_LIBS)
|
||||
|
||||
acountry.exe: acountry.c $(OBJ_DIR)/ares_getopt.o $(OBJ_HACK)
|
||||
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(EX_LIBS)
|
||||
|
||||
# clean generated files
|
||||
#
|
||||
genclean:
|
||||
- $(DELETE) ares_config.h
|
||||
|
||||
# clean object files and subdir
|
||||
#
|
||||
objclean: genclean
|
||||
- $(DELETE) $(OBJ_DIR)$(DS)*.o
|
||||
- $(RMDIR) $(OBJ_DIR)
|
||||
|
||||
# clean without removing built library and programs
|
||||
#
|
||||
clean: objclean
|
||||
- $(DELETE) depend.dj
|
||||
|
||||
# clean everything
|
||||
#
|
||||
realclean vclean: clean
|
||||
- $(DELETE) libcares.a
|
||||
- $(DELETE) acountry.exe
|
||||
- $(DELETE) adig.exe
|
||||
- $(DELETE) ahost.exe
|
||||
- $(DELETE) libcares.a
|
||||
|
||||
-include depend.dj
|
||||
|
@ -1,188 +0,0 @@
|
||||
|
||||
CSOURCES = ares__close_sockets.c \
|
||||
ares__get_hostent.c \
|
||||
ares__read_line.c \
|
||||
ares__timeval.c \
|
||||
ares_cancel.c \
|
||||
ares_data.c \
|
||||
ares_destroy.c \
|
||||
ares_expand_name.c \
|
||||
ares_expand_string.c \
|
||||
ares_fds.c \
|
||||
ares_free_hostent.c \
|
||||
ares_free_string.c \
|
||||
ares_gethostbyaddr.c \
|
||||
ares_gethostbyname.c \
|
||||
ares_getnameinfo.c \
|
||||
ares_getsock.c \
|
||||
ares_init.c \
|
||||
ares_library_init.c \
|
||||
ares_llist.c \
|
||||
ares_mkquery.c \
|
||||
ares_nowarn.c \
|
||||
ares_options.c \
|
||||
ares_parse_a_reply.c \
|
||||
ares_parse_aaaa_reply.c \
|
||||
ares_parse_ns_reply.c \
|
||||
ares_parse_ptr_reply.c \
|
||||
ares_parse_srv_reply.c \
|
||||
ares_parse_txt_reply.c \
|
||||
ares_process.c \
|
||||
ares_query.c \
|
||||
ares_search.c \
|
||||
ares_send.c \
|
||||
ares_strcasecmp.c \
|
||||
ares_strdup.c \
|
||||
ares_strerror.c \
|
||||
ares_timeout.c \
|
||||
ares_version.c \
|
||||
ares_writev.c \
|
||||
bitncmp.c \
|
||||
inet_net_pton.c \
|
||||
inet_ntop.c \
|
||||
windows_port.c
|
||||
|
||||
HHEADERS = ares.h \
|
||||
ares_build.h \
|
||||
ares_data.h \
|
||||
ares_dns.h \
|
||||
ares_ipv6.h \
|
||||
ares_library_init.h \
|
||||
ares_llist.h \
|
||||
ares_nowarn.h \
|
||||
ares_private.h \
|
||||
ares_rules.h \
|
||||
ares_strcasecmp.h \
|
||||
ares_strdup.h \
|
||||
ares_version.h \
|
||||
ares_writev.h \
|
||||
bitncmp.h \
|
||||
inet_net_pton.h \
|
||||
inet_ntop.h \
|
||||
nameser.h \
|
||||
ares_setup.h \
|
||||
setup_once.h
|
||||
|
||||
MANPAGES = ares_cancel.3 \
|
||||
ares_destroy.3 \
|
||||
ares_destroy_options.3 \
|
||||
ares_dup.3 \
|
||||
ares_expand_name.3 \
|
||||
ares_expand_string.3 \
|
||||
ares_fds.3 \
|
||||
ares_free_data.3 \
|
||||
ares_free_hostent.3 \
|
||||
ares_free_string.3 \
|
||||
ares_get_servers.3 \
|
||||
ares_gethostbyaddr.3 \
|
||||
ares_gethostbyname.3 \
|
||||
ares_gethostbyname_file.3 \
|
||||
ares_getnameinfo.3 \
|
||||
ares_getsock.3 \
|
||||
ares_init.3 \
|
||||
ares_init_options.3 \
|
||||
ares_library_cleanup.3 \
|
||||
ares_library_init.3 \
|
||||
ares_mkquery.3 \
|
||||
ares_parse_a_reply.3 \
|
||||
ares_parse_aaaa_reply.3 \
|
||||
ares_parse_ns_reply.3 \
|
||||
ares_parse_ptr_reply.3 \
|
||||
ares_parse_srv_reply.3 \
|
||||
ares_parse_txt_reply.3 \
|
||||
ares_process.3 \
|
||||
ares_query.3 \
|
||||
ares_save_options.3 \
|
||||
ares_search.3 \
|
||||
ares_send.3 \
|
||||
ares_set_servers.3 \
|
||||
ares_set_socket_callback.3 \
|
||||
ares_strerror.3 \
|
||||
ares_timeout.3 \
|
||||
ares_version.3
|
||||
|
||||
HTMLPAGES = ares_cancel.html \
|
||||
ares_destroy.html \
|
||||
ares_destroy_options.html \
|
||||
ares_dup.html \
|
||||
ares_expand_name.html \
|
||||
ares_expand_string.html \
|
||||
ares_fds.html \
|
||||
ares_free_data.html \
|
||||
ares_free_hostent.html \
|
||||
ares_free_string.html \
|
||||
ares_get_servers.html \
|
||||
ares_gethostbyaddr.html \
|
||||
ares_gethostbyname.html \
|
||||
ares_gethostbyname_file.html \
|
||||
ares_getnameinfo.html \
|
||||
ares_getsock.html \
|
||||
ares_init.html \
|
||||
ares_init_options.html \
|
||||
ares_library_cleanup.html \
|
||||
ares_library_init.html \
|
||||
ares_mkquery.html \
|
||||
ares_parse_a_reply.html \
|
||||
ares_parse_aaaa_reply.html \
|
||||
ares_parse_ns_reply.html \
|
||||
ares_parse_ptr_reply.html \
|
||||
ares_parse_srv_reply.html \
|
||||
ares_parse_txt_reply.html \
|
||||
ares_process.html \
|
||||
ares_query.html \
|
||||
ares_save_options.html \
|
||||
ares_search.html \
|
||||
ares_send.html \
|
||||
ares_set_servers.html \
|
||||
ares_set_socket_callback.html \
|
||||
ares_strerror.html \
|
||||
ares_timeout.html \
|
||||
ares_version.html
|
||||
|
||||
PDFPAGES = ares_cancel.pdf \
|
||||
ares_destroy.pdf \
|
||||
ares_destroy_options.pdf \
|
||||
ares_dup.pdf \
|
||||
ares_expand_name.pdf \
|
||||
ares_expand_string.pdf \
|
||||
ares_fds.pdf \
|
||||
ares_free_data.pdf \
|
||||
ares_free_hostent.pdf \
|
||||
ares_free_string.pdf \
|
||||
ares_get_servers.pdf \
|
||||
ares_gethostbyaddr.pdf \
|
||||
ares_gethostbyname.pdf \
|
||||
ares_gethostbyname_file.pdf \
|
||||
ares_getnameinfo.pdf \
|
||||
ares_getsock.pdf \
|
||||
ares_init.pdf \
|
||||
ares_init_options.pdf \
|
||||
ares_library_cleanup.pdf \
|
||||
ares_library_init.pdf \
|
||||
ares_mkquery.pdf \
|
||||
ares_parse_a_reply.pdf \
|
||||
ares_parse_aaaa_reply.pdf \
|
||||
ares_parse_ns_reply.pdf \
|
||||
ares_parse_ptr_reply.pdf \
|
||||
ares_parse_srv_reply.pdf \
|
||||
ares_parse_txt_reply.pdf \
|
||||
ares_process.pdf \
|
||||
ares_query.pdf \
|
||||
ares_save_options.pdf \
|
||||
ares_search.pdf \
|
||||
ares_send.pdf \
|
||||
ares_set_servers.pdf \
|
||||
ares_set_socket_callback.pdf \
|
||||
ares_strerror.pdf \
|
||||
ares_timeout.pdf \
|
||||
ares_version.pdf
|
||||
|
||||
SAMPLESOURCES = ares_getopt.c \
|
||||
ares_strcasecmp.c \
|
||||
inet_net_pton.c \
|
||||
inet_ntop.c
|
||||
|
||||
SAMPLEHEADERS = ares_getopt.h \
|
||||
ares_strcasecmp.h \
|
||||
inet_net_pton.h \
|
||||
inet_ntop.h
|
@ -1,69 +0,0 @@
|
||||
#############################################################
|
||||
# $Id$
|
||||
#
|
||||
## Makefile for building libcares.a with MingW32 (GCC-3.2)
|
||||
## Use: make -f Makefile.m32 [demos]
|
||||
##
|
||||
## Quick hack by Guenter; comments to: /dev/nul
|
||||
#
|
||||
########################################################
|
||||
## Nothing more to do below this line!
|
||||
|
||||
LIB = libcares.a
|
||||
|
||||
CC = gcc
|
||||
LD = gcc
|
||||
RANLIB = ranlib
|
||||
#RM = rm -f
|
||||
|
||||
CFLAGS = -O2 -Wall
|
||||
LDFLAGS = -s
|
||||
LIBS = -lwsock32
|
||||
|
||||
# Makefile.inc provides the CSOURCES and HHEADERS defines
|
||||
include Makefile.inc
|
||||
|
||||
OBJLIB := $(patsubst %.c,%.o,$(strip $(CSOURCES)))
|
||||
|
||||
|
||||
$(LIB): $(OBJLIB)
|
||||
ar cru $@ $^
|
||||
$(RANLIB) $@
|
||||
|
||||
all: $(LIB) demos
|
||||
|
||||
demos: adig.exe ahost.exe acountry.exe
|
||||
|
||||
tags:
|
||||
etags *.[ch]
|
||||
|
||||
%.exe: %.o ares_getopt.o $(LIB)
|
||||
$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||
|
||||
$(OBJLIB): ares.h ares_dns.h ares_private.h ares_build.h ares_rules.h
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
check:
|
||||
|
||||
install:
|
||||
${top_srcdir}/mkinstalldirs ${DESTDIR}${libdir}
|
||||
${top_srcdir}/mkinstalldirs ${DESTDIR}${includedir}
|
||||
${top_srcdir}/mkinstalldirs ${DESTDIR}${mandir}/man3
|
||||
${INSTALL} -m 644 $(LIB) ${DESTDIR}${libdir}
|
||||
${RANLIB} ${DESTDIR}${libdir}/$(LIB)
|
||||
chmod u-w ${DESTDIR}${libdir}/$(LIB)
|
||||
${INSTALL} -m 444 ${srcdir}/ares.h ${DESTDIR}${includedir}
|
||||
${INSTALL} -m 444 ${srcdir}/ares_build.h ${DESTDIR}${includedir}
|
||||
${INSTALL} -m 444 ${srcdir}/ares_rules.h ${DESTDIR}${includedir}
|
||||
(for man in $(MANPAGES); do \
|
||||
${INSTALL} -m 444 ${srcdir}/$${man} ${DESTDIR}${mandir}/man3; \
|
||||
done)
|
||||
|
||||
clean:
|
||||
$(RM) ares_getopt.o $(OBJLIB) $(LIB) adig.exe ahost.exe acountry.exe
|
||||
|
||||
distclean: clean
|
||||
$(RM) config.cache config.log config.status Makefile
|
||||
|
@ -1,475 +0,0 @@
|
||||
# $Id$
|
||||
|
||||
# Copyright (C) 2009-2010 by Daniel Stenberg
|
||||
#
|
||||
# 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.
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile for building c-ares libraries and sample programs with MSVC.
|
||||
#
|
||||
# Usage: nmake /f makefile.msvc CFG=<config> <target>
|
||||
#
|
||||
# <config> must be one of: [ lib-release | lib-debug | dll-release | dll-debug }
|
||||
# <target> must be one of: [ ALL | c-ares | acountry | adig | ahost | clean }
|
||||
#
|
||||
# If a <target> other than ALL or clean is given, <config> becomes mandatory.
|
||||
#
|
||||
# If neither <config> nor <target> are specified this results in
|
||||
# all targets being built for all <config> c-ares library types.
|
||||
#
|
||||
# This makefile must be processed from the subdir where it is located.
|
||||
#
|
||||
# All results are generated below a subdirectory named msvcXXX.
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
NAME = cares
|
||||
|
||||
# ------------------------------------------------
|
||||
# c-ares static and dynamic libraries common base
|
||||
# file names for release and debug configurations
|
||||
# ------------------------------------------------
|
||||
|
||||
STA_LIB_REL = lib$(NAME)
|
||||
DYN_LIB_REL = $(NAME)
|
||||
STA_LIB_DBG = $(STA_LIB_REL)d
|
||||
DYN_LIB_DBG = $(DYN_LIB_REL)d
|
||||
|
||||
# -------------------------------------------
|
||||
# Base names for c-ares DLL import libraries
|
||||
# -------------------------------------------
|
||||
|
||||
IMP_LIB_REL = $(DYN_LIB_REL)
|
||||
IMP_LIB_DBG = $(DYN_LIB_DBG)
|
||||
|
||||
# --------------------------
|
||||
# Runtime library selection
|
||||
# --------------------------
|
||||
|
||||
RTLIB = /MD
|
||||
RTLIBD = /MDd
|
||||
|
||||
!IF "$(RTLIBCFG)" == "static"
|
||||
RTLIB = /MT
|
||||
RTLIBD = /MTd
|
||||
!ENDIF
|
||||
|
||||
# --------------------------------------------------------
|
||||
# Define USE_WATT32 to 1 to use the Watt-32 tcp/ip stack,
|
||||
# otherwise Winsock tcp/ip stack will be used as default.
|
||||
# --------------------------------------------------------
|
||||
|
||||
USE_WATT32 = 0
|
||||
|
||||
# -------------------------------------------
|
||||
# Detect NMAKE version deducing MSVC version
|
||||
# -------------------------------------------
|
||||
|
||||
!IFNDEF _NMAKE_VER
|
||||
! MESSAGE Macro _NMAKE_VER not defined.
|
||||
! MESSAGE Use MSVC's NMAKE to process this makefile.
|
||||
! ERROR See previous message.
|
||||
!ENDIF
|
||||
|
||||
!IF "$(_NMAKE_VER)" == "6.00.8168.0"
|
||||
CC_VERS_NUM = 60
|
||||
!ELSEIF "$(_NMAKE_VER)" == "6.00.9782.0"
|
||||
CC_VERS_NUM = 60
|
||||
!ELSEIF "$(_NMAKE_VER)" == "7.00.9466"
|
||||
CC_VERS_NUM = 70
|
||||
!ELSEIF "$(_NMAKE_VER)" == "7.00.9955"
|
||||
CC_VERS_NUM = 70
|
||||
!ELSEIF "$(_NMAKE_VER)" == "7.10.3077"
|
||||
CC_VERS_NUM = 71
|
||||
!ELSEIF "$(_NMAKE_VER)" == "8.00.40607.16"
|
||||
CC_VERS_NUM = 80
|
||||
!ELSEIF "$(_NMAKE_VER)" == "8.00.50727.42"
|
||||
CC_VERS_NUM = 80
|
||||
!ELSEIF "$(_NMAKE_VER)" == "8.00.50727.762"
|
||||
CC_VERS_NUM = 80
|
||||
!ELSEIF "$(_NMAKE_VER)" == "9.00.21022.08"
|
||||
CC_VERS_NUM = 90
|
||||
!ELSEIF "$(_NMAKE_VER)" == "9.00.30729.01"
|
||||
CC_VERS_NUM = 90
|
||||
!ELSEIF "$(_NMAKE_VER)" == "10.00.20506.01"
|
||||
CC_VERS_NUM = 100
|
||||
!ELSEIF "$(_NMAKE_VER)" == "10.00.21003.01"
|
||||
CC_VERS_NUM = 100
|
||||
!ELSE
|
||||
! MESSAGE Unknown value for _NMAKE_VER macro: "$(_NMAKE_VER)"
|
||||
! MESSAGE Please, report this condition on the c-ares development
|
||||
! MESSAGE mailing list: http://cool.haxx.se/mailman/listinfo/c-ares/
|
||||
! ERROR See previous message.
|
||||
!ENDIF
|
||||
|
||||
CC_VERS_STR = msvc$(CC_VERS_NUM)
|
||||
|
||||
# ----------------------------------------------------
|
||||
# Verify that current subdir is the c-ares source one
|
||||
# ----------------------------------------------------
|
||||
|
||||
!IF ! EXIST(.\ares_init.c)
|
||||
! MESSAGE Can not process Makefile.msvc from outside of c-ares source subdirectory.
|
||||
! MESSAGE Change to the subdirectory where Makefile.msvc is found, and try again.
|
||||
! ERROR See previous message.
|
||||
!ENDIF
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Base subdir is the common root from which other subdirs will hang,
|
||||
# the name depends on MSVC version being used when building c-ares.
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
BASE_DIR = .\$(CC_VERS_STR)
|
||||
|
||||
# ----------------------------------------
|
||||
# Subdir holding sources for all projects
|
||||
# ----------------------------------------
|
||||
|
||||
SRCDIR = .
|
||||
|
||||
# -------------------------
|
||||
# Configuration validation
|
||||
# -------------------------
|
||||
|
||||
VALID_CFGSET = FALSE
|
||||
!IF "$(CFG)" == "lib-release" || "$(CFG)" == "lib-debug" || \
|
||||
"$(CFG)" == "dll-release" || "$(CFG)" == "dll-debug"
|
||||
VALID_CFGSET = TRUE
|
||||
!ENDIF
|
||||
|
||||
!IF "$(VALID_CFGSET)" == "FALSE" && "$(CFG)" != ""
|
||||
! MESSAGE MSVC c-ares makefile
|
||||
! MESSAGE
|
||||
! MESSAGE Usage: nmake /f makefile.msvc CFG=<config> <target>
|
||||
! MESSAGE
|
||||
! MESSAGE <config> must be one of: [ lib-release | lib-debug | dll-release | dll-debug }
|
||||
! MESSAGE <target> must be one of: [ ALL | c-ares | acountry | adig | ahost | clean }
|
||||
! MESSAGE
|
||||
! MESSAGE If a <target> other than ALL or clean is given, <config> becomes mandatory.
|
||||
! MESSAGE
|
||||
! MESSAGE If neither <config> nor <target> are specified this results in
|
||||
! MESSAGE all targets being built for all <config> c-ares library types.
|
||||
! MESSAGE
|
||||
! ERROR Choose a valid configuration.
|
||||
!ENDIF
|
||||
|
||||
# --------------------------------------------------------
|
||||
# Project subdirs independent of configuration being used
|
||||
# --------------------------------------------------------
|
||||
|
||||
CARES_DIR = $(BASE_DIR)\cares
|
||||
PROG1_DIR = $(BASE_DIR)\acountry
|
||||
PROG2_DIR = $(BASE_DIR)\adig
|
||||
PROG3_DIR = $(BASE_DIR)\ahost
|
||||
|
||||
# ---------------------------------------------------
|
||||
# Subdirs which are configuration dependent are only
|
||||
# defined when a valid configuration has been given.
|
||||
# ---------------------------------------------------
|
||||
|
||||
!IF "$(VALID_CFGSET)" == "TRUE"
|
||||
CARES_OUTDIR = $(CARES_DIR)\$(CFG)
|
||||
PROG1_OUTDIR = $(PROG1_DIR)\$(CFG)
|
||||
PROG2_OUTDIR = $(PROG2_DIR)\$(CFG)
|
||||
PROG3_OUTDIR = $(PROG3_DIR)\$(CFG)
|
||||
CARES_OBJDIR = $(CARES_OUTDIR)\obj
|
||||
PROG1_OBJDIR = $(PROG1_OUTDIR)\obj
|
||||
PROG2_OBJDIR = $(PROG2_OUTDIR)\obj
|
||||
PROG3_OBJDIR = $(PROG3_OUTDIR)\obj
|
||||
!ELSE
|
||||
!UNDEF CARES_OUTDIR
|
||||
!UNDEF PROG1_OUTDIR
|
||||
!UNDEF PROG2_OUTDIR
|
||||
!UNDEF PROG3_OUTDIR
|
||||
!UNDEF CARES_OBJDIR
|
||||
!UNDEF PROG1_OBJDIR
|
||||
!UNDEF PROG2_OBJDIR
|
||||
!UNDEF PROG3_OBJDIR
|
||||
!ENDIF
|
||||
|
||||
# -------------------------------------
|
||||
# Settings that depend on tcp/ip stack
|
||||
# -------------------------------------
|
||||
|
||||
!IF "$(USE_WATT32)" == "1"
|
||||
CFLAGS = /UWIN32 /DWATT32 /I$(WATT_ROOT)\inc
|
||||
EX_LIBS_REL = $(WATT_ROOT)\lib\wattcpvc_imp.lib
|
||||
EX_LIBS_DBG = $(WATT_ROOT)\lib\wattcpvc_imp_d.lib
|
||||
!ELSE
|
||||
CFLAGS = /DWIN32
|
||||
EX_LIBS_REL = ws2_32.lib advapi32.lib kernel32.lib
|
||||
EX_LIBS_DBG = ws2_32.lib advapi32.lib kernel32.lib
|
||||
!ENDIF
|
||||
|
||||
# -----------------------------------------
|
||||
# Switches that depend on compiler version
|
||||
# -----------------------------------------
|
||||
|
||||
!IF $(CC_VERS_NUM) == 60
|
||||
PDB_NONE = /pdb:none
|
||||
PDBTYPE_CONSOLIDATE = /pdbtype:consolidate
|
||||
!ELSE
|
||||
!UNDEF PDB_NONE
|
||||
!UNDEF PDBTYPE_CONSOLIDATE
|
||||
!ENDIF
|
||||
|
||||
!IF $(CC_VERS_NUM) <= 70
|
||||
RT_ERROR_CHECKING = /GZ
|
||||
!ELSE
|
||||
RT_ERROR_CHECKING = /RTCsu
|
||||
!ENDIF
|
||||
|
||||
# ----------------------------
|
||||
# Assorted commands and flags
|
||||
# ----------------------------
|
||||
|
||||
CC_CMD_REL = cl.exe /nologo $(RTLIB) /DNDEBUG /O2
|
||||
CC_CMD_DBG = cl.exe /nologo $(RTLIBD) /D_DEBUG /Od /Zi $(RT_ERROR_CHECKING)
|
||||
CC_CFLAGS = $(CFLAGS) /I. /W3 /EHsc /FD
|
||||
|
||||
RC_CMD_REL = rc.exe /l 0x409 /d "NDEBUG"
|
||||
RC_CMD_DBG = rc.exe /l 0x409 /d "_DEBUG"
|
||||
|
||||
LINK_CMD_LIB = link.exe /lib /nologo
|
||||
LINK_CMD_DLL = link.exe /dll /nologo /incremental:no /fixed:no
|
||||
LINK_CMD_EXE = link.exe /nologo /incremental:no /fixed:no /subsystem:console
|
||||
|
||||
LINK_CMD_EXE_REL = $(LINK_CMD_EXE) /release $(PDB_NONE)
|
||||
LINK_CMD_EXE_DBG = $(LINK_CMD_EXE) /debug $(PDBTYPE_CONSOLIDATE)
|
||||
|
||||
# ---------------------------------
|
||||
# Configuration dependent settings
|
||||
# ---------------------------------
|
||||
|
||||
!IF "$(CFG)" == "lib-release"
|
||||
CARES_TARGET = $(STA_LIB_REL).lib
|
||||
CARES_CFLAGS = /DCARES_BUILDING_LIBRARY /DCARES_STATICLIB
|
||||
CARES_LFLAGS =
|
||||
SPROG_CFLAGS = /DCARES_STATICLIB
|
||||
SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_REL) $(STA_LIB_REL).lib
|
||||
CARES_LINK = $(LINK_CMD_LIB)
|
||||
SPROG_LINK = $(LINK_CMD_EXE_REL)
|
||||
CC_CMD = $(CC_CMD_REL)
|
||||
!ENDIF
|
||||
|
||||
!IF "$(CFG)" == "lib-debug"
|
||||
CARES_TARGET = $(STA_LIB_DBG).lib
|
||||
CARES_CFLAGS = /DCARES_BUILDING_LIBRARY /DCARES_STATICLIB /DDEBUGBUILD
|
||||
CARES_LFLAGS =
|
||||
SPROG_CFLAGS = /DCARES_STATICLIB
|
||||
SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_DBG) $(STA_LIB_DBG).lib
|
||||
CARES_LINK = $(LINK_CMD_LIB)
|
||||
SPROG_LINK = $(LINK_CMD_EXE_DBG)
|
||||
CC_CMD = $(CC_CMD_DBG)
|
||||
!ENDIF
|
||||
|
||||
!IF "$(CFG)" == "dll-release"
|
||||
CARES_TARGET = $(DYN_LIB_REL).dll
|
||||
CARES_CFLAGS = /DCARES_BUILDING_LIBRARY
|
||||
CARES_LFLAGS = /release $(EX_LIBS_REL) /implib:$(CARES_OUTDIR)\$(IMP_LIB_REL).lib $(PDB_NONE)
|
||||
SPROG_CFLAGS =
|
||||
SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_REL) $(IMP_LIB_REL).lib
|
||||
CARES_LINK = $(LINK_CMD_DLL)
|
||||
SPROG_LINK = $(LINK_CMD_EXE_REL)
|
||||
CC_CMD = $(CC_CMD_REL)
|
||||
USE_RES_FILE = TRUE
|
||||
RC_CMD = $(RC_CMD_REL)
|
||||
!ENDIF
|
||||
|
||||
!IF "$(CFG)" == "dll-debug"
|
||||
CARES_TARGET = $(DYN_LIB_DBG).dll
|
||||
CARES_CFLAGS = /DCARES_BUILDING_LIBRARY /DDEBUGBUILD
|
||||
CARES_LFLAGS = /debug $(EX_LIBS_DBG) /implib:$(CARES_OUTDIR)\$(IMP_LIB_DBG).lib /pdb:$(CARES_OUTDIR)\$(DYN_LIB_DBG).pdb $(PDBTYPE_CONSOLIDATE)
|
||||
SPROG_CFLAGS =
|
||||
SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_DBG) $(IMP_LIB_DBG).lib
|
||||
CARES_LINK = $(LINK_CMD_DLL)
|
||||
SPROG_LINK = $(LINK_CMD_EXE_DBG)
|
||||
CC_CMD = $(CC_CMD_DBG)
|
||||
USE_RES_FILE = TRUE
|
||||
RC_CMD = $(RC_CMD_DBG)
|
||||
!ENDIF
|
||||
|
||||
# --------------------------------------------
|
||||
# Makefile.inc provides lists of source files
|
||||
# --------------------------------------------
|
||||
|
||||
!INCLUDE .\Makefile.inc
|
||||
|
||||
# ----------------------------
|
||||
# Build lists of object files
|
||||
# ----------------------------
|
||||
|
||||
!IF "$(VALID_CFGSET)" == "TRUE"
|
||||
|
||||
!IF [ECHO CARES_OBJS=^$(CARES_OBJDIR)\$(CSOURCES: = $(CARES_OBJDIR^)\) > .\cares_objs.inc] == 0
|
||||
!INCLUDE .\cares_objs.inc
|
||||
!IF [DEL .\cares_objs.inc]
|
||||
!ENDIF
|
||||
!ELSE
|
||||
!ERROR Problem generating CARES_OBJS list.
|
||||
!ENDIF
|
||||
CARES_OBJS = $(CARES_OBJS:.c=.obj)
|
||||
!IF "$(USE_RES_FILE)" == "TRUE"
|
||||
CARES_OBJS = $(CARES_OBJS) $(CARES_OBJDIR)\cares.res
|
||||
!ENDIF
|
||||
|
||||
!IF [ECHO PROG1_OBJS=^$(PROG1_OBJDIR)\$(SAMPLESOURCES: = $(PROG1_OBJDIR^)\) > .\prog1_objs.inc] == 0
|
||||
!INCLUDE .\prog1_objs.inc
|
||||
!IF [DEL .\prog1_objs.inc]
|
||||
!ENDIF
|
||||
!ELSE
|
||||
!ERROR Problem generating PROG1_OBJS list.
|
||||
!ENDIF
|
||||
PROG1_OBJS = $(PROG1_OBJS:.c=.obj)
|
||||
PROG1_OBJS = $(PROG1_OBJS) $(PROG1_OBJDIR)\acountry.obj
|
||||
|
||||
!IF [ECHO PROG2_OBJS=^$(PROG2_OBJDIR)\$(SAMPLESOURCES: = $(PROG2_OBJDIR^)\) > .\prog2_objs.inc] == 0
|
||||
!INCLUDE .\prog2_objs.inc
|
||||
!IF [DEL .\prog2_objs.inc]
|
||||
!ENDIF
|
||||
!ELSE
|
||||
!ERROR Problem generating PROG2_OBJS list.
|
||||
!ENDIF
|
||||
PROG2_OBJS = $(PROG2_OBJS:.c=.obj)
|
||||
PROG2_OBJS = $(PROG2_OBJS) $(PROG2_OBJDIR)\adig.obj
|
||||
|
||||
!IF [ECHO PROG3_OBJS=^$(PROG3_OBJDIR)\$(SAMPLESOURCES: = $(PROG3_OBJDIR^)\) > .\prog3_objs.inc] == 0
|
||||
!INCLUDE .\prog3_objs.inc
|
||||
!IF [DEL .\prog3_objs.inc]
|
||||
!ENDIF
|
||||
!ELSE
|
||||
!ERROR Problem generating PROG3_OBJS list.
|
||||
!ENDIF
|
||||
PROG3_OBJS = $(PROG3_OBJS:.c=.obj)
|
||||
PROG3_OBJS = $(PROG3_OBJS) $(PROG3_OBJDIR)\ahost.obj
|
||||
|
||||
!ENDIF
|
||||
|
||||
# --------------------------------
|
||||
# Only our custom inference rules
|
||||
# --------------------------------
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .rc
|
||||
|
||||
{$(SRCDIR)}.rc{$(CARES_OBJDIR)}.res:
|
||||
$(RC_CMD) /Fo $@ $<
|
||||
|
||||
{$(SRCDIR)}.c{$(CARES_OBJDIR)}.obj:
|
||||
$(CC_CMD) $(CC_CFLAGS) $(CARES_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
|
||||
|
||||
{$(SRCDIR)}.c{$(PROG1_OBJDIR)}.obj:
|
||||
$(CC_CMD) $(CC_CFLAGS) $(SPROG_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
|
||||
|
||||
{$(SRCDIR)}.c{$(PROG2_OBJDIR)}.obj:
|
||||
$(CC_CMD) $(CC_CFLAGS) $(SPROG_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
|
||||
|
||||
{$(SRCDIR)}.c{$(PROG3_OBJDIR)}.obj:
|
||||
$(CC_CMD) $(CC_CFLAGS) $(SPROG_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
|
||||
|
||||
# ------------------------------------------------------------- #
|
||||
# ------------------------------------------------------------- #
|
||||
# Default target when no CFG library type has been specified, #
|
||||
# results in building target ALL for all c-ares library types. #
|
||||
# ------------------------------------------------------------- #
|
||||
# ------------------------------------------------------------- #
|
||||
|
||||
!IF "$(VALID_CFGSET)" == "FALSE"
|
||||
|
||||
ALL:
|
||||
$(MAKE) /f .\Makefile.msvc CFG=lib-release ALL
|
||||
$(MAKE) /f .\Makefile.msvc CFG=lib-debug ALL
|
||||
$(MAKE) /f .\Makefile.msvc CFG=dll-release ALL
|
||||
$(MAKE) /f .\Makefile.msvc CFG=dll-debug ALL
|
||||
|
||||
clean:
|
||||
@-RMDIR /S /Q $(BASE_DIR) >NUL 2>&1
|
||||
|
||||
!ENDIF
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# Targets only available when a proper CFG library type has been given
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
!IF "$(VALID_CFGSET)" == "TRUE"
|
||||
|
||||
ALL: c-ares acountry adig ahost
|
||||
@
|
||||
|
||||
c-ares: $(HHEADERS) $(CSOURCES) $(CARES_OBJDIR) $(CARES_OBJS) $(CARES_OUTDIR)
|
||||
$(CARES_LINK) $(CARES_LFLAGS) /out:$(CARES_OUTDIR)\$(CARES_TARGET) $(CARES_OBJS)
|
||||
! IF "$(USE_RES_FILE)" == "TRUE"
|
||||
@if exist $(CARES_OUTDIR)\$(CARES_TARGET).manifest mt -nologo -manifest $(CARES_OUTDIR)\$(CARES_TARGET).manifest -outputresource:$(CARES_OUTDIR)\$(CARES_TARGET);2
|
||||
! ENDIF
|
||||
|
||||
acountry: c-ares acountry.c $(SAMPLESOURCES) $(SAMPLEHEADERS) $(PROG1_OBJDIR) $(PROG1_OBJS) $(PROG1_OUTDIR)
|
||||
$(SPROG_LINK) $(SPROG_LFLAGS) /out:$(PROG1_OUTDIR)\acountry.exe $(PROG1_OBJS)
|
||||
@if exist $(PROG1_OUTDIR)\acountry.exe.manifest mt -nologo -manifest $(PROG1_OUTDIR)\acountry.exe.manifest -outputresource:$(PROG1_OUTDIR)\acountry.exe;1
|
||||
|
||||
adig: c-ares adig.c $(SAMPLESOURCES) $(SAMPLEHEADERS) $(PROG2_OBJDIR) $(PROG2_OBJS) $(PROG2_OUTDIR)
|
||||
$(SPROG_LINK) $(SPROG_LFLAGS) /out:$(PROG2_OUTDIR)\adig.exe $(PROG2_OBJS)
|
||||
@if exist $(PROG2_OUTDIR)\adig.exe.manifest mt -nologo -manifest $(PROG2_OUTDIR)\adig.exe.manifest -outputresource:$(PROG2_OUTDIR)\adig.exe;1
|
||||
|
||||
ahost: c-ares ahost.c $(SAMPLESOURCES) $(SAMPLEHEADERS) $(PROG3_OBJDIR) $(PROG3_OBJS) $(PROG3_OUTDIR)
|
||||
$(SPROG_LINK) $(SPROG_LFLAGS) /out:$(PROG3_OUTDIR)\ahost.exe $(PROG3_OBJS)
|
||||
@if exist $(PROG3_OUTDIR)\ahost.exe.manifest mt -nologo -manifest $(PROG3_OUTDIR)\ahost.exe.manifest -outputresource:$(PROG3_OUTDIR)\ahost.exe;1
|
||||
|
||||
$(CARES_OUTDIR): $(CARES_DIR)
|
||||
@if not exist $(CARES_OUTDIR) mkdir $(CARES_OUTDIR)
|
||||
|
||||
$(PROG1_OUTDIR): $(PROG1_DIR)
|
||||
@if not exist $(PROG1_OUTDIR) mkdir $(PROG1_OUTDIR)
|
||||
|
||||
$(PROG2_OUTDIR): $(PROG2_DIR)
|
||||
@if not exist $(PROG2_OUTDIR) mkdir $(PROG2_OUTDIR)
|
||||
|
||||
$(PROG3_OUTDIR): $(PROG3_DIR)
|
||||
@if not exist $(PROG3_OUTDIR) mkdir $(PROG3_OUTDIR)
|
||||
|
||||
$(CARES_OBJDIR): $(CARES_OUTDIR)
|
||||
@if not exist $(CARES_OBJDIR) mkdir $(CARES_OBJDIR)
|
||||
|
||||
$(PROG1_OBJDIR): $(PROG1_OUTDIR)
|
||||
@if not exist $(PROG1_OBJDIR) mkdir $(PROG1_OBJDIR)
|
||||
|
||||
$(PROG2_OBJDIR): $(PROG2_OUTDIR)
|
||||
@if not exist $(PROG2_OBJDIR) mkdir $(PROG2_OBJDIR)
|
||||
|
||||
$(PROG3_OBJDIR): $(PROG3_OUTDIR)
|
||||
@if not exist $(PROG3_OBJDIR) mkdir $(PROG3_OBJDIR)
|
||||
|
||||
clean:
|
||||
@-RMDIR /S /Q $(CARES_OUTDIR) >NUL 2>&1
|
||||
@-RMDIR /S /Q $(PROG1_OUTDIR) >NUL 2>&1
|
||||
@-RMDIR /S /Q $(PROG2_OUTDIR) >NUL 2>&1
|
||||
@-RMDIR /S /Q $(PROG3_OUTDIR) >NUL 2>&1
|
||||
|
||||
!ENDIF
|
||||
|
||||
$(BASE_DIR):
|
||||
@if not exist $(BASE_DIR) mkdir $(BASE_DIR)
|
||||
|
||||
$(CARES_DIR): $(BASE_DIR)
|
||||
@if not exist $(CARES_DIR) mkdir $(CARES_DIR)
|
||||
|
||||
$(PROG1_DIR): $(BASE_DIR)
|
||||
@if not exist $(PROG1_DIR) mkdir $(PROG1_DIR)
|
||||
|
||||
$(PROG2_DIR): $(BASE_DIR)
|
||||
@if not exist $(PROG2_DIR) mkdir $(PROG2_DIR)
|
||||
|
||||
$(PROG3_DIR): $(BASE_DIR)
|
||||
@if not exist $(PROG3_DIR) mkdir $(PROG3_DIR)
|
||||
|
||||
# End of Makefile.msvc
|
@ -1,430 +0,0 @@
|
||||
#################################################################
|
||||
# $Id$
|
||||
#
|
||||
## Makefile for building libcares (NetWare version - gnu make)
|
||||
## Use: make -f Makefile.netware
|
||||
##
|
||||
## Comments to: Guenter Knauf http://www.gknw.de/phpbb
|
||||
#
|
||||
#################################################################
|
||||
|
||||
# Edit the path below to point to the base of your Novell NDK.
|
||||
ifndef NDKBASE
|
||||
NDKBASE = c:/novell
|
||||
endif
|
||||
|
||||
ifndef INSTDIR
|
||||
INSTDIR = ../ares-$(LIBCARES_VERSION_STR)-bin-nw
|
||||
endif
|
||||
|
||||
# Edit the vars below to change NLM target settings.
|
||||
TARGETS = adig.nlm ahost.nlm acountry.nlm
|
||||
LTARGET = libcares.$(LIBEXT)
|
||||
VERSION = $(LIBCARES_VERSION)
|
||||
COPYR = Copyright (C) 1996 - 2008, Daniel Stenberg, <daniel@haxx.se>
|
||||
DESCR = cURL $(subst .def,,$(notdir $@)) $(LIBCARES_VERSION_STR) - http://curl.haxx.se
|
||||
MTSAFE = YES
|
||||
STACK = 64000
|
||||
SCREEN = none
|
||||
#EXPORTS =
|
||||
# Comment the line below if you dont want to load protected automatically.
|
||||
#LDRING = 3
|
||||
|
||||
# Edit the var below to point to your lib architecture.
|
||||
ifndef LIBARCH
|
||||
LIBARCH = LIBC
|
||||
endif
|
||||
|
||||
# must be equal to NDEBUG or DEBUG, CURLDEBUG
|
||||
ifndef DB
|
||||
DB = NDEBUG
|
||||
endif
|
||||
# Optimization: -O<n> or debugging: -g
|
||||
ifeq ($(DB),NDEBUG)
|
||||
OPT = -O2
|
||||
OBJDIR = release
|
||||
else
|
||||
OPT = -g
|
||||
OBJDIR = debug
|
||||
endif
|
||||
|
||||
# Include the version info retrieved from curlver.h
|
||||
-include $(OBJDIR)/version.inc
|
||||
|
||||
# The following lines defines your compiler.
|
||||
ifdef CWFolder
|
||||
METROWERKS = $(CWFolder)
|
||||
endif
|
||||
ifdef METROWERKS
|
||||
# MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support
|
||||
MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support/Metrowerks Support
|
||||
CC = mwccnlm
|
||||
else
|
||||
CC = gcc
|
||||
endif
|
||||
# a native win32 awk can be downloaded from here:
|
||||
# http://www.gknw.net/development/prgtools/awk-20070501.zip
|
||||
AWK = awk
|
||||
YACC = bison -y
|
||||
CP = cp -afv
|
||||
MKDIR = mkdir
|
||||
# RM = rm -f
|
||||
# if you want to mark the target as MTSAFE you will need a tool for
|
||||
# generating the xdc data for the linker; here's a minimal tool:
|
||||
# http://www.gknw.net/development/prgtools/mkxdc.zip
|
||||
MPKXDC = mkxdc
|
||||
|
||||
# Global flags for all compilers
|
||||
CFLAGS += $(OPT) -D$(DB) -DNETWARE -DHAVE_CONFIG_H -nostdinc
|
||||
|
||||
ifeq ($(CC),mwccnlm)
|
||||
LD = mwldnlm
|
||||
LDFLAGS = -nostdlib $(PRELUDE) $(OBJEXE) $(<:.def=.o) -o $@ -commandfile
|
||||
AR = mwldnlm
|
||||
ARFLAGS = -nostdlib -type library -o
|
||||
LIBEXT = lib
|
||||
#RANLIB =
|
||||
CFLAGS += -msgstyle gcc -gccinc -inline off -opt nointrinsics -proc 586
|
||||
CFLAGS += -relax_pointers
|
||||
#CFLAGS += -w on
|
||||
ifeq ($(LIBARCH),LIBC)
|
||||
PRELUDE = $(SDK_LIBC)/imports/libcpre.o
|
||||
CFLAGS += -align 4
|
||||
else
|
||||
# PRELUDE = $(SDK_CLIB)/imports/clibpre.o
|
||||
# to avoid the __init_* / __deinit_* whoes dont use prelude from NDK
|
||||
PRELUDE = "$(MWCW_PATH)/libraries/runtime/prelude.obj"
|
||||
# CFLAGS += -include "$(MWCW_PATH)/headers/nlm_clib_prefix.h"
|
||||
CFLAGS += -align 1
|
||||
endif
|
||||
else
|
||||
LD = nlmconv
|
||||
LDFLAGS = -T
|
||||
AR = ar
|
||||
ARFLAGS = -cq
|
||||
LIBEXT = a
|
||||
RANLIB = ranlib
|
||||
CFLAGS += -fno-builtin -fpcc-struct-return -fno-strict-aliasing
|
||||
CFLAGS += -Wall -Wno-format -Wno-uninitialized # -pedantic
|
||||
ifeq ($(LIBARCH),LIBC)
|
||||
PRELUDE = $(SDK_LIBC)/imports/libcpre.gcc.o
|
||||
else
|
||||
# PRELUDE = $(SDK_CLIB)/imports/clibpre.gcc.o
|
||||
# to avoid the __init_* / __deinit_* whoes dont use prelude from NDK
|
||||
# http://www.gknw.net/development/mk_nlm/gcc_pre.zip
|
||||
PRELUDE = $(NDK_ROOT)/pre/prelude.o
|
||||
CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h
|
||||
endif
|
||||
endif
|
||||
|
||||
NDK_ROOT = $(NDKBASE)/ndk
|
||||
SDK_CLIB = $(NDK_ROOT)/nwsdk
|
||||
SDK_LIBC = $(NDK_ROOT)/libc
|
||||
|
||||
ifeq ($(LIBARCH),LIBC)
|
||||
INCLUDES += -I$(SDK_LIBC)/include
|
||||
# INCLUDES += -I$(SDK_LIBC)/include/nks
|
||||
# INCLUDES += -I$(SDK_LIBC)/include/winsock
|
||||
CFLAGS += -D_POSIX_SOURCE
|
||||
else
|
||||
INCLUDES += -I$(SDK_CLIB)/include/nlm
|
||||
# INCLUDES += -I$(SDK_CLIB)/include/nlm/obsolete
|
||||
# INCLUDES += -I$(SDK_CLIB)/include
|
||||
endif
|
||||
ifeq ($(DB),CURLDEBUG)
|
||||
INCLUDES += -I../include
|
||||
endif
|
||||
CFLAGS += -I. $(INCLUDES)
|
||||
|
||||
ifeq ($(MTSAFE),YES)
|
||||
XDCOPT = -n
|
||||
endif
|
||||
ifeq ($(MTSAFE),NO)
|
||||
XDCOPT = -u
|
||||
endif
|
||||
|
||||
ifeq ($(findstring linux,$(OSTYPE)),linux)
|
||||
DL = '
|
||||
#-include $(NDKBASE)/nlmconv/ncpfs.inc
|
||||
endif
|
||||
|
||||
# Makefile.inc provides the CSOURCES and HHEADERS defines
|
||||
include Makefile.inc
|
||||
|
||||
OBJLIB := $(patsubst %.c,$(OBJDIR)/%.o,$(strip $(CSOURCES)))
|
||||
OBJEXE = $(OBJLIB) $(OBJDIR)/ares_getopt.o
|
||||
|
||||
.PHONY: lib nlm prebuild dist install clean
|
||||
|
||||
lib: prebuild $(LTARGET)
|
||||
|
||||
nlm: prebuild $(TARGETS)
|
||||
|
||||
prebuild: $(OBJDIR) ares_build.h $(OBJDIR)/version.inc ares_config.h
|
||||
|
||||
install: $(INSTDIR) all
|
||||
@$(CP) *.nlm $(INSTDIR)
|
||||
@$(CP) ../CHANGES $(INSTDIR)
|
||||
@$(CP) ../COPYING $(INSTDIR)
|
||||
@$(CP) ../README $(INSTDIR)
|
||||
@$(CP) ../RELEASE-NOTES $(INSTDIR)
|
||||
|
||||
clean:
|
||||
-$(RM) $(LTARGET) $(TARGETS) ares_config.h
|
||||
-$(RM) -r $(OBJDIR)
|
||||
-$(RM) -r arpa
|
||||
|
||||
%.$(LIBEXT): $(OBJLIB)
|
||||
@echo Creating $@
|
||||
@-$(RM) $@
|
||||
@$(AR) $(ARFLAGS) $@ $^
|
||||
ifdef RANLIB
|
||||
@$(RANLIB) $@
|
||||
endif
|
||||
|
||||
%.nlm: $(OBJDIR)/%.def $(OBJDIR)/%.o $(OBJDIR)/%.xdc $(OBJEXE)
|
||||
@echo Linking $@
|
||||
@-$(RM) $@
|
||||
@$(LD) $(LDFLAGS) $<
|
||||
|
||||
$(OBJDIR) $(INSTDIR):
|
||||
@$(MKDIR) $@
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
# @echo Compiling $<
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/version.inc: ares_version.h $(OBJDIR)
|
||||
@echo Creating $@
|
||||
@$(AWK) -f get_ver.awk $< > $@
|
||||
|
||||
$(OBJDIR)/%.xdc: Makefile.netware
|
||||
@echo Creating $@
|
||||
@$(MPKXDC) $(XDCOPT) $@
|
||||
|
||||
$(OBJDIR)/%.def: Makefile.netware
|
||||
@echo Creating $@
|
||||
@echo $(DL)# DEF file for linking with $(LD)$(DL) > $@
|
||||
@echo $(DL)# Do not edit this file - it is created by make!$(DL) >> $@
|
||||
@echo $(DL)# All your changes will be lost!!$(DL) >> $@
|
||||
@echo $(DL)#$(DL) >> $@
|
||||
@echo $(DL)copyright "$(COPYR)"$(DL) >> $@
|
||||
@echo $(DL)description "$(DESCR)"$(DL) >> $@
|
||||
@echo $(DL)version $(VERSION)$(DL) >> $@
|
||||
ifdef NLMTYPE
|
||||
@echo $(DL)type $(NLMTYPE)$(DL) >> $@
|
||||
endif
|
||||
ifdef STACK
|
||||
@echo $(DL)stack $(STACK)$(DL) >> $@
|
||||
endif
|
||||
ifdef SCREEN
|
||||
@echo $(DL)screenname "$(SCREEN)"$(DL) >> $@
|
||||
else
|
||||
@echo $(DL)screenname "DEFAULT"$(DL) >> $@
|
||||
endif
|
||||
ifeq ($(DB),DEBUG)
|
||||
@echo $(DL)debug$(DL) >> $@
|
||||
endif
|
||||
@echo $(DL)threadname "$^"$(DL) >> $@
|
||||
ifdef XDCOPT
|
||||
@echo $(DL)xdcdata $(@:.def=.xdc)$(DL) >> $@
|
||||
endif
|
||||
ifeq ($(LDRING),0)
|
||||
@echo $(DL)flag_on 16$(DL) >> $@
|
||||
endif
|
||||
ifeq ($(LDRING),3)
|
||||
@echo $(DL)flag_on 512$(DL) >> $@
|
||||
endif
|
||||
ifeq ($(LIBARCH),CLIB)
|
||||
@echo $(DL)start _Prelude$(DL) >> $@
|
||||
@echo $(DL)exit _Stop$(DL) >> $@
|
||||
@echo $(DL)import @$(SDK_CLIB)/imports/clib.imp$(DL) >> $@
|
||||
@echo $(DL)import @$(SDK_CLIB)/imports/threads.imp$(DL) >> $@
|
||||
@echo $(DL)import @$(SDK_CLIB)/imports/nlmlib.imp$(DL) >> $@
|
||||
@echo $(DL)import @$(SDK_CLIB)/imports/socklib.imp$(DL) >> $@
|
||||
@echo $(DL)module clib$(DL) >> $@
|
||||
else
|
||||
@echo $(DL)flag_on 64$(DL) >> $@
|
||||
@echo $(DL)pseudopreemption$(DL) >> $@
|
||||
@echo $(DL)start _LibCPrelude$(DL) >> $@
|
||||
@echo $(DL)exit _LibCPostlude$(DL) >> $@
|
||||
@echo $(DL)check _LibCCheckUnload$(DL) >> $@
|
||||
@echo $(DL)import @$(SDK_LIBC)/imports/libc.imp$(DL) >> $@
|
||||
@echo $(DL)import @$(SDK_LIBC)/imports/netware.imp$(DL) >> $@
|
||||
@echo $(DL)module libc$(DL) >> $@
|
||||
endif
|
||||
ifdef MODULES
|
||||
@echo $(DL)module $(MODULES)$(DL) >> $@
|
||||
endif
|
||||
ifdef EXPORTS
|
||||
@echo $(DL)export $(EXPORTS)$(DL) >> $@
|
||||
endif
|
||||
ifdef IMPORTS
|
||||
@echo $(DL)import $(IMPORTS)$(DL) >> $@
|
||||
endif
|
||||
ifeq ($(LD),nlmconv)
|
||||
@echo $(DL)input $(PRELUDE)$(DL) >> $@
|
||||
@echo $(DL)input $(OBJEXE)$(DL) >> $@
|
||||
@echo $(DL)input $(@:.def=.o)$(DL) >> $@
|
||||
@echo $(DL)output $(notdir $(@:.def=.nlm))$(DL) >> $@
|
||||
endif
|
||||
|
||||
ares_config.h: Makefile.netware
|
||||
@echo Creating $@
|
||||
@echo $(DL)/* $@ for NetWare target.$(DL) > $@
|
||||
@echo $(DL)** Do not edit this file - it is created by make!$(DL) >> $@
|
||||
@echo $(DL)** All your changes will be lost!!$(DL) >> $@
|
||||
@echo $(DL)*/$(DL) >> $@
|
||||
@echo $(DL)#ifndef NETWARE$(DL) >> $@
|
||||
@echo $(DL)#error This $(notdir $@) is created for NetWare platform!$(DL) >> $@
|
||||
@echo $(DL)#endif$(DL) >> $@
|
||||
@echo $(DL)#define VERSION "$(LIBCARES_VERSION_STR)"$(DL) >> $@
|
||||
@echo $(DL)#define PACKAGE_BUGREPORT "a suitable curl mailing list => http://curl.haxx.se/mail/"$(DL) >> $@
|
||||
ifeq ($(LIBARCH),CLIB)
|
||||
@echo $(DL)#define OS "i586-pc-clib-NetWare"$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRICMP 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRNICMP 1$(DL) >> $@
|
||||
@echo $(DL)#define NETDB_USE_INTERNET 1$(DL) >> $@
|
||||
@echo $(DL)#define RECV_TYPE_ARG1 int$(DL) >> $@
|
||||
@echo $(DL)#define RECV_TYPE_ARG2 char *$(DL) >> $@
|
||||
@echo $(DL)#define RECV_TYPE_ARG3 int$(DL) >> $@
|
||||
@echo $(DL)#define RECV_TYPE_ARG4 int$(DL) >> $@
|
||||
@echo $(DL)#define RECV_TYPE_RETV int$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_ARG1 int$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_ARG2 char$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_ARG3 int$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_ARG4 int$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_ARG5 struct sockaddr$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_ARG6 int$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_RETV int$(DL) >> $@
|
||||
@echo $(DL)#define SEND_QUAL_ARG2$(DL) >> $@
|
||||
@echo $(DL)#define SEND_TYPE_ARG1 int$(DL) >> $@
|
||||
@echo $(DL)#define SEND_TYPE_ARG2 char *$(DL) >> $@
|
||||
@echo $(DL)#define SEND_TYPE_ARG3 int$(DL) >> $@
|
||||
@echo $(DL)#define SEND_TYPE_ARG4 int$(DL) >> $@
|
||||
@echo $(DL)#define SEND_TYPE_RETV int$(DL) >> $@
|
||||
else
|
||||
@echo $(DL)#define OS "i586-pc-libc-NetWare"$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_DLFCN_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_DLOPEN 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_FTRUNCATE 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_GETTIMEOFDAY 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_INTTYPES_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_LONGLONG 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STDINT_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRCASECMP 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRLCAT 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRLCPY 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRTOLL 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SYS_PARAM_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SYS_SELECT_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_TERMIOS_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_AF_INET6 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_PF_INET6 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_FREEADDRINFO 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_GETADDRINFO 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRUCT_IN6_ADDR 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRUCT_SOCKADDR_IN6 1$(DL) >> $@
|
||||
@echo $(DL)#define RECV_TYPE_ARG1 int$(DL) >> $@
|
||||
@echo $(DL)#define RECV_TYPE_ARG2 void *$(DL) >> $@
|
||||
@echo $(DL)#define RECV_TYPE_ARG3 size_t$(DL) >> $@
|
||||
@echo $(DL)#define RECV_TYPE_ARG4 int$(DL) >> $@
|
||||
@echo $(DL)#define RECV_TYPE_RETV ssize_t$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_ARG1 int$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_ARG2 void$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_ARG3 size_t$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_ARG4 int$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_ARG5 struct sockaddr$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_ARG6 size_t$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_RETV ssize_t$(DL) >> $@
|
||||
@echo $(DL)#define RECVFROM_TYPE_ARG2_IS_VOID 1$(DL) >> $@
|
||||
@echo $(DL)#define SEND_QUAL_ARG2$(DL) >> $@
|
||||
@echo $(DL)#define SEND_TYPE_ARG1 int$(DL) >> $@
|
||||
@echo $(DL)#define SEND_TYPE_ARG2 void *$(DL) >> $@
|
||||
@echo $(DL)#define SEND_TYPE_ARG3 size_t$(DL) >> $@
|
||||
@echo $(DL)#define SEND_TYPE_ARG4 int$(DL) >> $@
|
||||
@echo $(DL)#define SEND_TYPE_RETV ssize_t$(DL) >> $@
|
||||
@echo $(DL)#define SIZEOF_STRUCT_IN6_ADDR 16$(DL) >> $@
|
||||
endif
|
||||
@echo $(DL)#define HAVE_ARPA_INET_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_ASSERT_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_ERR_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_FCNTL_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_GETHOSTBYADDR 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_GETHOSTBYNAME 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_GETHOSTNAME 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_GETPROTOBYNAME 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_GMTIME_R 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_INET_ADDR 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_IOCTL 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_IOCTL_FIONBIO 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_LIMITS_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_LL 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_LOCALTIME_R 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_MALLOC_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_NETINET_IN_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_RECV 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_RECVFROM 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SELECT 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SEND 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SETJMP_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SIGNAL 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SIGNAL_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SIG_ATOMIC_T 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SOCKET 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STDLIB_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRDUP 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRFTIME 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRING_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRSTR 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRUCT_ADDRINFO 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_STRUCT_TIMEVAL 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SYS_IOCTL_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SYS_STAT_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SYS_TIME_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_TIME_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_UNAME 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_UNISTD_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_UTIME 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_UTIME_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_WRITEV 1$(DL) >> $@
|
||||
@echo $(DL)#define RETSIGTYPE void$(DL) >> $@
|
||||
@echo $(DL)#define SIZEOF_INT 4$(DL) >> $@
|
||||
@echo $(DL)#define SIZEOF_STRUCT_IN_ADDR 4$(DL) >> $@
|
||||
@echo $(DL)#define STDC_HEADERS 1$(DL) >> $@
|
||||
@echo $(DL)#define TIME_WITH_SYS_TIME 1$(DL) >> $@
|
||||
ifdef NW_WINSOCK
|
||||
@echo $(DL)#define HAVE_CLOSESOCKET 1$(DL) >> $@
|
||||
else
|
||||
@echo $(DL)#define HAVE_SYS_TYPES_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SYS_SOCKET_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_SYS_SOCKIO_H 1$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_NETDB_H 1$(DL) >> $@
|
||||
endif
|
||||
@echo $(DL)#ifdef __GNUC__$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_VARIADIC_MACROS_GCC 1$(DL) >> $@
|
||||
@echo $(DL)#else$(DL) >> $@
|
||||
@echo $(DL)#define HAVE_VARIADIC_MACROS_C99 1$(DL) >> $@
|
||||
@echo $(DL)#endif$(DL) >> $@
|
||||
|
||||
FORCE: ;
|
||||
|
||||
ares_build.h: Makefile.netware FORCE
|
||||
@echo Creating $@
|
||||
@echo $(DL)/* $@ intended for NetWare target.$(DL) > $@
|
||||
@echo $(DL)** Do not edit this file - it is created by make!$(DL) >> $@
|
||||
@echo $(DL)** All your changes will be lost!!$(DL) >> $@
|
||||
@echo $(DL)*/$(DL) >> $@
|
||||
@echo $(DL)#ifndef __CARES_BUILD_H$(DL) >> $@
|
||||
@echo $(DL)#define __CARES_BUILD_H$(DL) >> $@
|
||||
ifeq ($(LIBARCH),CLIB)
|
||||
@echo $(DL)#define CARES_TYPEOF_ARES_SOCKLEN_T int$(DL) >> $@
|
||||
@echo $(DL)#define CARES_SIZEOF_ARES_SOCKLEN_T 4$(DL) >> $@
|
||||
else
|
||||
@echo $(DL)#define CARES_TYPEOF_ARES_SOCKLEN_T unsigned int$(DL) >> $@
|
||||
@echo $(DL)#define CARES_SIZEOF_ARES_SOCKLEN_T 4$(DL) >> $@
|
||||
endif
|
||||
@echo $(DL)#define CARES_SIZEOF_LONG 4$(DL) >> $@
|
||||
@echo $(DL)typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;$(DL) >> $@
|
||||
@echo $(DL)#endif /* __CARES_BUILD_H */$(DL) >> $@
|
21
ares/NEWS
21
ares/NEWS
@ -1,21 +0,0 @@
|
||||
Major changes since:
|
||||
* see the CHANGES file
|
||||
|
||||
Major changes in release 1.1.1:
|
||||
* ares should now compile as C++ code (no longer uses reserved word
|
||||
"class").
|
||||
* Added SRV support to adig test program.
|
||||
* Fixed a few error handling bugs in query processing.
|
||||
|
||||
Major changes in release 1.1.0:
|
||||
* Added ares_free_string() function so that memory can be freed in the
|
||||
same layer as it is allocated, a desirable feature in some
|
||||
environments.
|
||||
* A few of the ares_dns.h macros are fixed to use the proper bitwise
|
||||
operator.
|
||||
* Fixed a couple of fenceposts fixed in ares_expand_name()'s
|
||||
bounds-checking.
|
||||
* In process_timeouts(), extract query->next before calling
|
||||
next_server() and possibly freeing the query structure.
|
||||
* Casted arguments to ctype macros casted to unsigned char, since not
|
||||
all char values are valid inputs to those macros according to ANSI.
|
46
ares/README
46
ares/README
@ -1,46 +0,0 @@
|
||||
This is c-ares, a forked version of the original ares. The original ares
|
||||
README follows below, the c-ares specific details are in README.cares
|
||||
|
||||
====================================================================
|
||||
|
||||
This is ares, an asynchronous resolver library. It is intended for
|
||||
applications which need to perform DNS queries without blocking, or
|
||||
need to perform multiple DNS queries in parallel. The primary
|
||||
examples of such applications are servers which communicate with
|
||||
multiple clients and programs with graphical user interfaces.
|
||||
|
||||
This library implementation is not especially portable to crufty old
|
||||
systems like SunOS 4. It assumes a compiler which can handle ANSI C
|
||||
syntax, a system malloc which properly handles realloc(NULL, foo) and
|
||||
free(NULL), and a reasonably up-to-date <arpa/nameser.h>.
|
||||
|
||||
I have attempted to preserve the externally visible behavior of the
|
||||
BIND resolver in nearly all respects. The API of the library is, of
|
||||
course, very different from the synchronous BIND API; instead of
|
||||
invoking a function like res_send() and getting a return value back
|
||||
indicating the number of bytes in the response, you invoke a function
|
||||
like ares_send() and give it a callback function to invoke when the
|
||||
response arrives. You then have to select() on the file descriptors
|
||||
indicated by ares_fds(), with a timeout given by ares_timeout(). You
|
||||
call ares_process() when select() returns.
|
||||
|
||||
Some features are missing from the current version of ares, relative
|
||||
to the BIND resolver:
|
||||
|
||||
* There is no IPV6 support. [not true for c-ares]
|
||||
* There is no hostname verification.
|
||||
* There is no logging of unexpected events.
|
||||
* There is no debugging-oriented logging.
|
||||
* There is no YP support.
|
||||
|
||||
libares requires an ANSI compiler to compile and use. To build the
|
||||
library, just run "./configure" and "make". To install it, run "make
|
||||
install". Run "./configure --help" to see a list of options you can
|
||||
provide to configure to change how the library builds. libares has no
|
||||
data files, so you can move the include file and library around freely
|
||||
without leaving behind any dependencies on old paths. Building the
|
||||
library will also build the "adig" program, a little toy for trying
|
||||
out the library. It doesn't get installed.
|
||||
|
||||
libares is distributed at athena-dist.mit.edu:pub/ATHENA/ares. Please
|
||||
send bug reports and comments to ghudson@mit.edu.
|
@ -1,63 +0,0 @@
|
||||
c-ares
|
||||
======
|
||||
|
||||
This package is based on ares 1.1.1 (written by Greg Hudson). I decided to
|
||||
fork and release a separate project since the ares author didn't want the
|
||||
improvements that were vital for our use of it.
|
||||
|
||||
This package is dubbed 'c-ares' since I (Daniel Stenberg) wanted this for use
|
||||
within the curl project (hence the letter C) and it makes a nice pun. Also,
|
||||
c-ares is not API compatible with ares: a new name makes that more obvious to
|
||||
the public.
|
||||
|
||||
The full source code is available in the 'c-ares' release archives, and in the
|
||||
'ares' subdir of the curl CVS source repository.
|
||||
|
||||
If you find bugs, correct flaws, have questions or have comments in general in
|
||||
regard to c-ares (or by all means the original ares too), get in touch with us
|
||||
on the c-ares mailing list: http://cool.haxx.se/mailman/listinfo/c-ares
|
||||
|
||||
c-ares is of course distributed under the same MIT-style license as the
|
||||
original ares.
|
||||
|
||||
You'll find all c-ares details and news here:
|
||||
|
||||
http://c-ares.haxx.se/
|
||||
|
||||
|
||||
NOTES FOR C-ARES HACKERS
|
||||
|
||||
The following notes apply to c-ares version 1.7.0 and later.
|
||||
|
||||
* The distributed ares_build.h file is only intended to be used on systems
|
||||
which can not run the also distributed configure script.
|
||||
|
||||
* The distributed ares_build.h file is generated as a copy of ares_build.h.dist
|
||||
when the c-ares source code distribution archive file is originally created.
|
||||
|
||||
* If you check out from CVS on a non-configure platform, you must run the
|
||||
appropriate buildconf* script to set up ares_build.h and other local files
|
||||
before being able of compiling the library.
|
||||
|
||||
* On systems capable of running the configure script, the configure process
|
||||
will overwrite the distributed ares_build.h file with one that is suitable
|
||||
and specific to the library being configured and built, this new file is
|
||||
generated from the ares_build.h.in template file.
|
||||
|
||||
* If you intend to distribute an already compiled c-ares library you _MUST_
|
||||
also distribute along with it the generated ares_build.h which has been
|
||||
used to compile it. Otherwise the library will be of no use for the users of
|
||||
the library that you have built. It is _your_ responsability to provide this
|
||||
file. No one at the c-ares project can know how you have built the library.
|
||||
|
||||
* File ares_build.h includes platform and configuration dependent info,
|
||||
and must not be modified by anyone. Configure script generates it for you.
|
||||
|
||||
* We cannot assume anything else but very basic compiler features being
|
||||
present. While c-ares requires an ANSI C compiler to build, some of the
|
||||
earlier ANSI compilers clearly can't deal with some preprocessor operators.
|
||||
|
||||
* Newlines must remain unix-style for older compilers' sake.
|
||||
|
||||
* Comments must be written in the old-style /* unnested C-fashion */
|
||||
|
119
ares/README.msvc
119
ares/README.msvc
@ -1,119 +0,0 @@
|
||||
$Id$
|
||||
|
||||
|
||||
___ __ _ _ __ ___ ___
|
||||
/ __| ___ / _` | '__/ _ \/ __|
|
||||
| (_ |___| (_| | | | __/\__ \
|
||||
\___| \__,_|_| \___||___/
|
||||
|
||||
|
||||
How to build c-ares using MSVC or Visual Studio
|
||||
=================================================
|
||||
|
||||
|
||||
|
||||
How to build using MSVC from the command line
|
||||
---------------------------------------------
|
||||
|
||||
Open a command prompt window and ensure that the environment is properly
|
||||
set up in order to use MSVC or Visual Studio compiler tools.
|
||||
|
||||
Change to c-ares source folder where Makefile.msvc file is located and run:
|
||||
|
||||
> nmake -f Makefile.msvc
|
||||
|
||||
This will build all c-ares libraries as well as three sample programs.
|
||||
|
||||
Once the above command has finished a new folder named MSVCXX will exist
|
||||
below the folder where makefile.msvc is found. The name of the folder
|
||||
depends on the MSVC compiler version being used to build c-ares.
|
||||
|
||||
Below the MSVCXX folder there will exist four folders named 'cares',
|
||||
'ahost', 'acountry', and 'adig'. The 'cares' folder is the one that
|
||||
holds the c-ares libraries you have just generated, the other three
|
||||
hold sample programs that use the libraries.
|
||||
|
||||
The above command builds four versions of the c-ares library, dynamic
|
||||
and static versions and each one in release and debug flavours. Each
|
||||
of these is found in folders named dll-release, dll-debug, lib-release,
|
||||
and lib-debug, which hang from the 'cares' folder mentioned above. Each
|
||||
sample program also has folders with the same names to reflect which
|
||||
library version it is using.
|
||||
|
||||
|
||||
How to build using Visual Studio 6 IDE
|
||||
--------------------------------------
|
||||
|
||||
A VC++ 6.0 reference workspace (vc6aws.dsw) is available within the 'vc'
|
||||
folder to allow proper building of the library and sample programs.
|
||||
|
||||
1) Open the vc6aws.dsw workspace with MSVC6's IDE.
|
||||
2) Select 'Build' from top menu.
|
||||
3) Select 'Batch Build' from dropdown menu.
|
||||
4) Make sure that the sixteen project configurations are 'checked'.
|
||||
5) Click on the 'Build' button.
|
||||
6) Once the sixteen project configurations are built you are done.
|
||||
|
||||
Dynamic and static c-ares libraries are built in debug and release flavours,
|
||||
and can be located each one in its own subdirectory, dll-debug, dll-release,
|
||||
lib-debug and lib-release, all of them below the 'vc\cares' subdirectory.
|
||||
|
||||
In the same way four executable versions of each sample program are built,
|
||||
each using its respective library. The resulting sample executables are
|
||||
located in its own subdirectory, dll-debug, dll-release, lib-debug and
|
||||
lib-release, below the 'vc\acountry', 'vc\adig' and 'vc\ahost'folders.
|
||||
|
||||
These reference VC++ 6.0 configurations are generated using the dynamic CRT.
|
||||
|
||||
|
||||
How to build using Visual Studio 2003 or newer IDE
|
||||
--------------------------------------------------
|
||||
|
||||
First you have to convert the VC++ 6.0 reference workspace and project files
|
||||
to the Visual Studio IDE version you are using, following next steps:
|
||||
|
||||
1) Open vc\vc6aws.dsw with VS20XX.
|
||||
2) Allow VS20XX to update all projects and workspaces.
|
||||
3) Save ALL and close VS20XX.
|
||||
4) Open vc\vc6aws.sln with VS20XX.
|
||||
5) Select batch build, check 'all' projects and click 'build' button.
|
||||
|
||||
Same comments relative to generated files and folders as done above for
|
||||
Visual Studio 6 IDE apply here.
|
||||
|
||||
|
||||
Relationship between c-ares library file names and versions
|
||||
-----------------------------------------------------------
|
||||
|
||||
c-ares static release library version files:
|
||||
|
||||
libcares.lib -> static release library
|
||||
|
||||
c-ares static debug library version files:
|
||||
|
||||
libcaresd.lib -> static debug library
|
||||
|
||||
c-ares dynamic release library version files:
|
||||
|
||||
cares.dll -> dynamic release library
|
||||
cares.lib -> import library for the dynamic release library
|
||||
cares.exp -> export file for the dynamic release library
|
||||
|
||||
c-ares dynamic debug library version files:
|
||||
|
||||
caresd.dll -> dynamic debug library
|
||||
caresd.lib -> import library for the dynamic debug library
|
||||
caresd.exp -> export file for the dynamic debug library
|
||||
caresd.pdb -> debug symbol file for the dynamic debug library
|
||||
|
||||
|
||||
How to use c-ares static libraries
|
||||
----------------------------------
|
||||
|
||||
When using the c-ares static library in your program, you will have to
|
||||
define preprocessor symbol CARES_STATICLIB while building your program,
|
||||
otherwise you will get errors at linkage stage.
|
||||
|
||||
|
||||
Have Fun!
|
||||
|
@ -1,18 +0,0 @@
|
||||
This is what's new and changed in the c-ares 1.7.1 release:
|
||||
|
||||
Changed:
|
||||
|
||||
o added IPv6 name servers support
|
||||
|
||||
Fixed:
|
||||
|
||||
o closing of sockets on Windows systems
|
||||
o MSVC deprecated compiler options warnings
|
||||
o ares_process_fd() didn't check broken connections
|
||||
|
||||
Thanks go to these friendly people for their efforts and contributions:
|
||||
|
||||
Ingmar Runge, Laszlo Tamas Szabo, Yang Tse, Tommie Gannert, Gregor Jasny,
|
||||
Phil Blundell, Cedric Bail, Jakub Hrozek
|
||||
|
||||
Have fun!
|
23
ares/TODO
23
ares/TODO
@ -1,23 +0,0 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
ares_reinit()
|
||||
|
||||
- To allow an app to force a re-read of /etc/resolv.conf etc, pretty much
|
||||
like the res_init() resolver function offers
|
||||
|
||||
ares_gethostbyname
|
||||
|
||||
- When built to support IPv6, it needs to also support PF_UNSPEC or similar,
|
||||
so that an application can ask for any protocol and then c-ares would return
|
||||
all known resolves and not just explicitly IPv4 _or_ IPv6 resolves.
|
||||
|
||||
ares_process
|
||||
|
||||
- Upon next ABI breakage ares_process() should be changed to return 'int'
|
||||
and return ARES_ENOTINITIALIZED if ares_library_init() has not been called.
|
||||
|
||||
ares_process_fd
|
||||
|
||||
- Upon next ABI breakage ares_process_fd() should be changed to return
|
||||
'int' and return ARES_ENOTINITIALIZED if library has not been initialized.
|
1925
ares/acinclude.m4
1925
ares/acinclude.m4
File diff suppressed because it is too large
Load Diff
628
ares/acountry.c
628
ares/acountry.c
@ -1,628 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* IP-address/hostname to country converter.
|
||||
*
|
||||
* Problem; you want to know where IP a.b.c.d is located.
|
||||
*
|
||||
* Use ares_gethostbyname ("d.c.b.a.zz.countries.nerd.dk")
|
||||
* and get the CNAME (host->h_name). Result will be:
|
||||
* CNAME = zz<CC>.countries.nerd.dk with address 127.0.x.y (ver 1) or
|
||||
* CNAME = <a.b.c.d>.zz.countries.nerd.dk with address 127.0.x.y (ver 2)
|
||||
*
|
||||
* The 2 letter country code is in <CC> and the ISO-3166 country
|
||||
* number is in x.y (number = x*256 + y). Version 2 of the protocol is missing
|
||||
* the <CC> number.
|
||||
*
|
||||
* Ref: http://countries.nerd.dk/more.html
|
||||
*
|
||||
* Written by G. Vanem <gvanem@broadpark.no> 2006, 2007
|
||||
*
|
||||
* NB! This program may not be big-endian aware.
|
||||
*
|
||||
* 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"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) && !defined(WATT32)
|
||||
#include <winsock.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_getopt.h"
|
||||
#include "inet_net_pton.h"
|
||||
#include "inet_ntop.h"
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
# include "ares_strdup.h"
|
||||
# define strdup(ptr) ares_strdup(ptr)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRCASECMP
|
||||
# include "ares_strcasecmp.h"
|
||||
# define strcasecmp(p1,p2) ares_strcasecmp(p1,p2)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRNCASECMP
|
||||
# include "ares_strcasecmp.h"
|
||||
# define strncasecmp(p1,p2,n) ares_strncasecmp(p1,p2,n)
|
||||
#endif
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE 0xffffffff
|
||||
#endif
|
||||
|
||||
static const char *usage = "acountry [-vh?] {host|addr} ...\n";
|
||||
static const char nerd_fmt[] = "%u.%u.%u.%u.zz.countries.nerd.dk";
|
||||
static const char *nerd_ver1 = nerd_fmt + 14;
|
||||
static const char *nerd_ver2 = nerd_fmt + 11;
|
||||
static int verbose = 0;
|
||||
|
||||
#define TRACE(fmt) do { \
|
||||
if (verbose > 0) \
|
||||
printf fmt ; \
|
||||
} while (0)
|
||||
|
||||
static void wait_ares(ares_channel channel);
|
||||
static void callback(void *arg, int status, int timeouts, struct hostent *host);
|
||||
static void callback2(void *arg, int status, int timeouts, struct hostent *host);
|
||||
static void find_country_from_cname(const char *cname, struct in_addr addr);
|
||||
|
||||
static void Abort(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ares_channel channel;
|
||||
int ch, status;
|
||||
|
||||
#if defined(WIN32) && !defined(WATT32)
|
||||
WORD wVersionRequested = MAKEWORD(USE_WINSOCK,USE_WINSOCK);
|
||||
WSADATA wsaData;
|
||||
WSAStartup(wVersionRequested, &wsaData);
|
||||
#endif
|
||||
|
||||
status = ares_library_init(ARES_LIB_INIT_ALL);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status));
|
||||
return 1;
|
||||
}
|
||||
|
||||
while ((ch = ares_getopt(argc, argv, "dvh?")) != -1)
|
||||
switch (ch)
|
||||
{
|
||||
case 'd':
|
||||
#ifdef WATT32
|
||||
dbug_init();
|
||||
#endif
|
||||
break;
|
||||
case 'v':
|
||||
verbose++;
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
default:
|
||||
Abort(usage);
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc < 1)
|
||||
Abort(usage);
|
||||
|
||||
status = ares_init(&channel);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "ares_init: %s\n", ares_strerror(status));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Initiate the queries, one per command-line argument. */
|
||||
for ( ; *argv; argv++)
|
||||
{
|
||||
struct in_addr addr;
|
||||
char buf[100];
|
||||
|
||||
/* If this fails, assume '*argv' is a host-name that
|
||||
* must be resolved first
|
||||
*/
|
||||
if (ares_inet_pton(AF_INET, *argv, &addr) != 1)
|
||||
{
|
||||
ares_gethostbyname(channel, *argv, AF_INET, callback2, &addr);
|
||||
wait_ares(channel);
|
||||
if (addr.s_addr == INADDR_NONE)
|
||||
{
|
||||
printf("Failed to lookup %s\n", *argv);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(buf, nerd_fmt,
|
||||
(unsigned int)(addr.s_addr >> 24),
|
||||
(unsigned int)((addr.s_addr >> 16) & 255),
|
||||
(unsigned int)((addr.s_addr >> 8) & 255),
|
||||
(unsigned int)(addr.s_addr & 255));
|
||||
TRACE(("Looking up %s...", buf));
|
||||
fflush(stdout);
|
||||
ares_gethostbyname(channel, buf, AF_INET, callback, buf);
|
||||
}
|
||||
|
||||
wait_ares(channel);
|
||||
ares_destroy(channel);
|
||||
|
||||
ares_library_cleanup();
|
||||
|
||||
#if defined(WIN32) && !defined(WATT32)
|
||||
WSACleanup();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for the queries to complete.
|
||||
*/
|
||||
static void wait_ares(ares_channel channel)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
struct timeval *tvp, tv;
|
||||
fd_set read_fds, write_fds;
|
||||
int nfds;
|
||||
|
||||
FD_ZERO(&read_fds);
|
||||
FD_ZERO(&write_fds);
|
||||
nfds = ares_fds(channel, &read_fds, &write_fds);
|
||||
if (nfds == 0)
|
||||
break;
|
||||
tvp = ares_timeout(channel, NULL, &tv);
|
||||
select(nfds, &read_fds, &write_fds, NULL, tvp);
|
||||
ares_process(channel, &read_fds, &write_fds);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the callback used when we have the IP-address of interest.
|
||||
* Extract the CNAME and figure out the country-code from it.
|
||||
*/
|
||||
static void callback(void *arg, int status, int timeouts, struct hostent *host)
|
||||
{
|
||||
const char *name = (const char*)arg;
|
||||
const char *cname;
|
||||
char buf[20];
|
||||
|
||||
(void)timeouts;
|
||||
|
||||
if (!host || status != ARES_SUCCESS)
|
||||
{
|
||||
printf("Failed to lookup %s: %s\n", name, ares_strerror(status));
|
||||
return;
|
||||
}
|
||||
|
||||
TRACE(("\nFound address %s, name %s\n",
|
||||
ares_inet_ntop(AF_INET,(const char*)host->h_addr,buf,sizeof(buf)),
|
||||
host->h_name));
|
||||
|
||||
cname = host->h_name; /* CNAME gets put here */
|
||||
if (!cname)
|
||||
printf("Failed to get CNAME for %s\n", name);
|
||||
else
|
||||
find_country_from_cname(cname, *(struct in_addr*)host->h_addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the callback used to obtain the IP-address of the host of interest.
|
||||
*/
|
||||
static void callback2(void *arg, int status, int timeouts, struct hostent *host)
|
||||
{
|
||||
struct in_addr *addr = (struct in_addr*) arg;
|
||||
|
||||
(void)timeouts;
|
||||
if (!host || status != ARES_SUCCESS)
|
||||
memset(addr, INADDR_NONE, sizeof(*addr));
|
||||
else
|
||||
memcpy(addr, host->h_addr, sizeof(*addr));
|
||||
}
|
||||
|
||||
struct search_list {
|
||||
int country_number; /* ISO-3166 country number */
|
||||
char short_name[3]; /* A2 short country code */
|
||||
const char *long_name; /* normal country name */
|
||||
};
|
||||
|
||||
static const struct search_list *list_lookup(int number, const struct search_list *list, int num)
|
||||
{
|
||||
while (num > 0 && list->long_name)
|
||||
{
|
||||
if (list->country_number == number)
|
||||
return (list);
|
||||
num--;
|
||||
list++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ref: ftp://ftp.ripe.net/iso3166-countrycodes.txt
|
||||
*/
|
||||
static const struct search_list country_list[] = {
|
||||
{ 4, "af", "Afghanistan" },
|
||||
{ 248, "ax", "Åland Island" },
|
||||
{ 8, "al", "Albania" },
|
||||
{ 12, "dz", "Algeria" },
|
||||
{ 16, "as", "American Samoa" },
|
||||
{ 20, "ad", "Andorra" },
|
||||
{ 24, "ao", "Angola" },
|
||||
{ 660, "ai", "Anguilla" },
|
||||
{ 10, "aq", "Antarctica" },
|
||||
{ 28, "ag", "Antigua & Barbuda" },
|
||||
{ 32, "ar", "Argentina" },
|
||||
{ 51, "am", "Armenia" },
|
||||
{ 533, "aw", "Aruba" },
|
||||
{ 36, "au", "Australia" },
|
||||
{ 40, "at", "Austria" },
|
||||
{ 31, "az", "Azerbaijan" },
|
||||
{ 44, "bs", "Bahamas" },
|
||||
{ 48, "bh", "Bahrain" },
|
||||
{ 50, "bd", "Bangladesh" },
|
||||
{ 52, "bb", "Barbados" },
|
||||
{ 112, "by", "Belarus" },
|
||||
{ 56, "be", "Belgium" },
|
||||
{ 84, "bz", "Belize" },
|
||||
{ 204, "bj", "Benin" },
|
||||
{ 60, "bm", "Bermuda" },
|
||||
{ 64, "bt", "Bhutan" },
|
||||
{ 68, "bo", "Bolivia" },
|
||||
{ 70, "ba", "Bosnia & Herzegowina" },
|
||||
{ 72, "bw", "Botswana" },
|
||||
{ 74, "bv", "Bouvet Island" },
|
||||
{ 76, "br", "Brazil" },
|
||||
{ 86, "io", "British Indian Ocean Territory" },
|
||||
{ 96, "bn", "Brunei Darussalam" },
|
||||
{ 100, "bg", "Bulgaria" },
|
||||
{ 854, "bf", "Burkina Faso" },
|
||||
{ 108, "bi", "Burundi" },
|
||||
{ 116, "kh", "Cambodia" },
|
||||
{ 120, "cm", "Cameroon" },
|
||||
{ 124, "ca", "Canada" },
|
||||
{ 132, "cv", "Cape Verde" },
|
||||
{ 136, "ky", "Cayman Islands" },
|
||||
{ 140, "cf", "Central African Republic" },
|
||||
{ 148, "td", "Chad" },
|
||||
{ 152, "cl", "Chile" },
|
||||
{ 156, "cn", "China" },
|
||||
{ 162, "cx", "Christmas Island" },
|
||||
{ 166, "cc", "Cocos Islands" },
|
||||
{ 170, "co", "Colombia" },
|
||||
{ 174, "km", "Comoros" },
|
||||
{ 178, "cg", "Congo" },
|
||||
{ 180, "cd", "Congo" },
|
||||
{ 184, "ck", "Cook Islands" },
|
||||
{ 188, "cr", "Costa Rica" },
|
||||
{ 384, "ci", "Cote d'Ivoire" },
|
||||
{ 191, "hr", "Croatia" },
|
||||
{ 192, "cu", "Cuba" },
|
||||
{ 196, "cy", "Cyprus" },
|
||||
{ 203, "cz", "Czech Republic" },
|
||||
{ 208, "dk", "Denmark" },
|
||||
{ 262, "dj", "Djibouti" },
|
||||
{ 212, "dm", "Dominica" },
|
||||
{ 214, "do", "Dominican Republic" },
|
||||
{ 218, "ec", "Ecuador" },
|
||||
{ 818, "eg", "Egypt" },
|
||||
{ 222, "sv", "El Salvador" },
|
||||
{ 226, "gq", "Equatorial Guinea" },
|
||||
{ 232, "er", "Eritrea" },
|
||||
{ 233, "ee", "Estonia" },
|
||||
{ 231, "et", "Ethiopia" },
|
||||
{ 238, "fk", "Falkland Islands" },
|
||||
{ 234, "fo", "Faroe Islands" },
|
||||
{ 242, "fj", "Fiji" },
|
||||
{ 246, "fi", "Finland" },
|
||||
{ 250, "fr", "France" },
|
||||
{ 249, "fx", "France, Metropolitan" },
|
||||
{ 254, "gf", "French Guiana" },
|
||||
{ 258, "pf", "French Polynesia" },
|
||||
{ 260, "tf", "French Southern Territories" },
|
||||
{ 266, "ga", "Gabon" },
|
||||
{ 270, "gm", "Gambia" },
|
||||
{ 268, "ge", "Georgia" },
|
||||
{ 276, "de", "Germany" },
|
||||
{ 288, "gh", "Ghana" },
|
||||
{ 292, "gi", "Gibraltar" },
|
||||
{ 300, "gr", "Greece" },
|
||||
{ 304, "gl", "Greenland" },
|
||||
{ 308, "gd", "Grenada" },
|
||||
{ 312, "gp", "Guadeloupe" },
|
||||
{ 316, "gu", "Guam" },
|
||||
{ 320, "gt", "Guatemala" },
|
||||
{ 324, "gn", "Guinea" },
|
||||
{ 624, "gw", "Guinea-Bissau" },
|
||||
{ 328, "gy", "Guyana" },
|
||||
{ 332, "ht", "Haiti" },
|
||||
{ 334, "hm", "Heard & Mc Donald Islands" },
|
||||
{ 336, "va", "Vatican City" },
|
||||
{ 340, "hn", "Honduras" },
|
||||
{ 344, "hk", "Hong kong" },
|
||||
{ 348, "hu", "Hungary" },
|
||||
{ 352, "is", "Iceland" },
|
||||
{ 356, "in", "India" },
|
||||
{ 360, "id", "Indonesia" },
|
||||
{ 364, "ir", "Iran" },
|
||||
{ 368, "iq", "Iraq" },
|
||||
{ 372, "ie", "Ireland" },
|
||||
{ 376, "il", "Israel" },
|
||||
{ 380, "it", "Italy" },
|
||||
{ 388, "jm", "Jamaica" },
|
||||
{ 392, "jp", "Japan" },
|
||||
{ 400, "jo", "Jordan" },
|
||||
{ 398, "kz", "Kazakhstan" },
|
||||
{ 404, "ke", "Kenya" },
|
||||
{ 296, "ki", "Kiribati" },
|
||||
{ 408, "kp", "Korea (north)" },
|
||||
{ 410, "kr", "Korea (south)" },
|
||||
{ 414, "kw", "Kuwait" },
|
||||
{ 417, "kg", "Kyrgyzstan" },
|
||||
{ 418, "la", "Laos" },
|
||||
{ 428, "lv", "Latvia" },
|
||||
{ 422, "lb", "Lebanon" },
|
||||
{ 426, "ls", "Lesotho" },
|
||||
{ 430, "lr", "Liberia" },
|
||||
{ 434, "ly", "Libya" },
|
||||
{ 438, "li", "Liechtenstein" },
|
||||
{ 440, "lt", "Lithuania" },
|
||||
{ 442, "lu", "Luxembourg" },
|
||||
{ 446, "mo", "Macao" },
|
||||
{ 807, "mk", "Macedonia" },
|
||||
{ 450, "mg", "Madagascar" },
|
||||
{ 454, "mw", "Malawi" },
|
||||
{ 458, "my", "Malaysia" },
|
||||
{ 462, "mv", "Maldives" },
|
||||
{ 466, "ml", "Mali" },
|
||||
{ 470, "mt", "Malta" },
|
||||
{ 584, "mh", "Marshall Islands" },
|
||||
{ 474, "mq", "Martinique" },
|
||||
{ 478, "mr", "Mauritania" },
|
||||
{ 480, "mu", "Mauritius" },
|
||||
{ 175, "yt", "Mayotte" },
|
||||
{ 484, "mx", "Mexico" },
|
||||
{ 583, "fm", "Micronesia" },
|
||||
{ 498, "md", "Moldova" },
|
||||
{ 492, "mc", "Monaco" },
|
||||
{ 496, "mn", "Mongolia" },
|
||||
{ 500, "ms", "Montserrat" },
|
||||
{ 504, "ma", "Morocco" },
|
||||
{ 508, "mz", "Mozambique" },
|
||||
{ 104, "mm", "Myanmar" },
|
||||
{ 516, "na", "Namibia" },
|
||||
{ 520, "nr", "Nauru" },
|
||||
{ 524, "np", "Nepal" },
|
||||
{ 528, "nl", "Netherlands" },
|
||||
{ 530, "an", "Netherlands Antilles" },
|
||||
{ 540, "nc", "New Caledonia" },
|
||||
{ 554, "nz", "New Zealand" },
|
||||
{ 558, "ni", "Nicaragua" },
|
||||
{ 562, "ne", "Niger" },
|
||||
{ 566, "ng", "Nigeria" },
|
||||
{ 570, "nu", "Niue" },
|
||||
{ 574, "nf", "Norfolk Island" },
|
||||
{ 580, "mp", "Northern Mariana Islands" },
|
||||
{ 578, "no", "Norway" },
|
||||
{ 512, "om", "Oman" },
|
||||
{ 586, "pk", "Pakistan" },
|
||||
{ 585, "pw", "Palau" },
|
||||
{ 275, "ps", "Palestinian Territory" },
|
||||
{ 591, "pa", "Panama" },
|
||||
{ 598, "pg", "Papua New Guinea" },
|
||||
{ 600, "py", "Paraguay" },
|
||||
{ 604, "pe", "Peru" },
|
||||
{ 608, "ph", "Philippines" },
|
||||
{ 612, "pn", "Pitcairn" },
|
||||
{ 616, "pl", "Poland" },
|
||||
{ 620, "pt", "Portugal" },
|
||||
{ 630, "pr", "Puerto Rico" },
|
||||
{ 634, "qa", "Qatar" },
|
||||
{ 638, "re", "Reunion" },
|
||||
{ 642, "ro", "Romania" },
|
||||
{ 643, "ru", "Russia" },
|
||||
{ 646, "rw", "Rwanda" },
|
||||
{ 659, "kn", "Saint Kitts & Nevis" },
|
||||
{ 662, "lc", "Saint Lucia" },
|
||||
{ 670, "vc", "Saint Vincent" },
|
||||
{ 882, "ws", "Samoa" },
|
||||
{ 674, "sm", "San Marino" },
|
||||
{ 678, "st", "Sao Tome & Principe" },
|
||||
{ 682, "sa", "Saudi Arabia" },
|
||||
{ 686, "sn", "Senegal" },
|
||||
{ 891, "cs", "Serbia and Montenegro" },
|
||||
{ 690, "sc", "Seychelles" },
|
||||
{ 694, "sl", "Sierra Leone" },
|
||||
{ 702, "sg", "Singapore" },
|
||||
{ 703, "sk", "Slovakia" },
|
||||
{ 705, "si", "Slovenia" },
|
||||
{ 90, "sb", "Solomon Islands" },
|
||||
{ 706, "so", "Somalia" },
|
||||
{ 710, "za", "South Africa" },
|
||||
{ 239, "gs", "South Georgia" },
|
||||
{ 724, "es", "Spain" },
|
||||
{ 144, "lk", "Sri Lanka" },
|
||||
{ 654, "sh", "St. Helena" },
|
||||
{ 666, "pm", "St. Pierre & Miquelon" },
|
||||
{ 736, "sd", "Sudan" },
|
||||
{ 740, "sr", "Suriname" },
|
||||
{ 744, "sj", "Svalbard & Jan Mayen Islands" },
|
||||
{ 748, "sz", "Swaziland" },
|
||||
{ 752, "se", "Sweden" },
|
||||
{ 756, "ch", "Switzerland" },
|
||||
{ 760, "sy", "Syrian Arab Republic" },
|
||||
{ 626, "tl", "Timor-Leste" },
|
||||
{ 158, "tw", "Taiwan" },
|
||||
{ 762, "tj", "Tajikistan" },
|
||||
{ 834, "tz", "Tanzania" },
|
||||
{ 764, "th", "Thailand" },
|
||||
{ 768, "tg", "Togo" },
|
||||
{ 772, "tk", "Tokelau" },
|
||||
{ 776, "to", "Tonga" },
|
||||
{ 780, "tt", "Trinidad & Tobago" },
|
||||
{ 788, "tn", "Tunisia" },
|
||||
{ 792, "tr", "Turkey" },
|
||||
{ 795, "tm", "Turkmenistan" },
|
||||
{ 796, "tc", "Turks & Caicos Islands" },
|
||||
{ 798, "tv", "Tuvalu" },
|
||||
{ 800, "ug", "Uganda" },
|
||||
{ 804, "ua", "Ukraine" },
|
||||
{ 784, "ae", "United Arab Emirates" },
|
||||
{ 826, "gb", "United Kingdom" },
|
||||
{ 840, "us", "United States" },
|
||||
{ 581, "um", "United States Minor Outlying Islands" },
|
||||
{ 858, "uy", "Uruguay" },
|
||||
{ 860, "uz", "Uzbekistan" },
|
||||
{ 548, "vu", "Vanuatu" },
|
||||
{ 862, "ve", "Venezuela" },
|
||||
{ 704, "vn", "Vietnam" },
|
||||
{ 92, "vg", "Virgin Islands (British)" },
|
||||
{ 850, "vi", "Virgin Islands (US)" },
|
||||
{ 876, "wf", "Wallis & Futuna Islands" },
|
||||
{ 732, "eh", "Western Sahara" },
|
||||
{ 887, "ye", "Yemen" },
|
||||
{ 894, "zm", "Zambia" },
|
||||
{ 716, "zw", "Zimbabwe" }
|
||||
};
|
||||
|
||||
/*
|
||||
* Check if start of 'str' is simply an IPv4 address.
|
||||
*/
|
||||
#define BYTE_OK(x) ((x) >= 0 && (x) <= 255)
|
||||
|
||||
static int is_addr(char *str, char **end)
|
||||
{
|
||||
int a0, a1, a2, a3, num, rc = 0, length = 0;
|
||||
|
||||
num = sscanf(str,"%3d.%3d.%3d.%3d%n",&a0,&a1,&a2,&a3,&length);
|
||||
if( (num == 4) &&
|
||||
BYTE_OK(a0) && BYTE_OK(a1) && BYTE_OK(a2) && BYTE_OK(a3) &&
|
||||
length >= (3+4))
|
||||
{
|
||||
rc = 1;
|
||||
*end = str + length;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the country-code and name from the CNAME. E.g.:
|
||||
* version 1: CNAME = zzno.countries.nerd.dk with address 127.0.2.66
|
||||
* yields ccode_A" = "no" and cnumber 578 (2.66).
|
||||
* version 2: CNAME = <a.b.c.d>.zz.countries.nerd.dk with address 127.0.2.66
|
||||
* yields cnumber 578 (2.66). ccode_A is "";
|
||||
*/
|
||||
static void find_country_from_cname(const char *cname, struct in_addr addr)
|
||||
{
|
||||
const struct search_list *country;
|
||||
char ccode_A2[3], *ccopy, *dot_4;
|
||||
int cnumber, z0, z1, ver_1, ver_2;
|
||||
unsigned long ip;
|
||||
|
||||
ip = ntohl(addr.s_addr);
|
||||
z0 = tolower(cname[0]);
|
||||
z1 = tolower(cname[1]);
|
||||
ccopy = strdup(cname);
|
||||
dot_4 = NULL;
|
||||
|
||||
ver_1 = (z0 == 'z' && z1 == 'z' && !strcasecmp(cname+4,nerd_ver1));
|
||||
ver_2 = (is_addr(ccopy,&dot_4) && !strcasecmp(dot_4,nerd_ver2));
|
||||
|
||||
if (ver_1)
|
||||
{
|
||||
const char *dot = strchr(cname, '.');
|
||||
if ((z0 != 'z' && z1 != 'z') || dot != cname+4)
|
||||
{
|
||||
printf("Unexpected CNAME %s (ver_1)\n", cname);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (ver_2)
|
||||
{
|
||||
z0 = tolower(dot_4[1]);
|
||||
z1 = tolower(dot_4[2]);
|
||||
if (z0 != 'z' && z1 != 'z')
|
||||
{
|
||||
printf("Unexpected CNAME %s (ver_2)\n", cname);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unexpected CNAME %s (ver?)\n", cname);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ver_1)
|
||||
{
|
||||
ccode_A2[0] = (char)tolower(cname[2]);
|
||||
ccode_A2[1] = (char)tolower(cname[3]);
|
||||
ccode_A2[2] = '\0';
|
||||
}
|
||||
else
|
||||
ccode_A2[0] = '\0';
|
||||
|
||||
cnumber = ip & 0xFFFF;
|
||||
|
||||
TRACE(("Found country-code `%s', number %d\n",
|
||||
ver_1 ? ccode_A2 : "<n/a>", cnumber));
|
||||
|
||||
country = list_lookup(cnumber, country_list,
|
||||
sizeof(country_list) / sizeof(country_list[0]));
|
||||
if (!country)
|
||||
printf("Name for country-number %d not found.\n", cnumber);
|
||||
else
|
||||
{
|
||||
if (ver_1)
|
||||
{
|
||||
if ((country->short_name[0] != ccode_A2[0]) ||
|
||||
(country->short_name[1] != ccode_A2[1]) ||
|
||||
(country->short_name[2] != ccode_A2[2]))
|
||||
printf("short-name mismatch; %s vs %s\n",
|
||||
country->short_name, ccode_A2);
|
||||
}
|
||||
printf("%s (%s), number %d.\n",
|
||||
country->long_name, country->short_name, cnumber);
|
||||
}
|
||||
free(ccopy);
|
||||
}
|
||||
|
820
ares/adig.c
820
ares/adig.c
@ -1,820 +0,0 @@
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* 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_ARPA_INET_H
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
# include <netdb.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
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_dns.h"
|
||||
#include "inet_ntop.h"
|
||||
#include "inet_net_pton.h"
|
||||
#include "ares_getopt.h"
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
# include "ares_strdup.h"
|
||||
# define strdup(ptr) ares_strdup(ptr)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRCASECMP
|
||||
# include "ares_strcasecmp.h"
|
||||
# define strcasecmp(p1,p2) ares_strcasecmp(p1,p2)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRNCASECMP
|
||||
# include "ares_strcasecmp.h"
|
||||
# define strncasecmp(p1,p2,n) ares_strncasecmp(p1,p2,n)
|
||||
#endif
|
||||
|
||||
#ifdef WATT32
|
||||
#undef WIN32 /* Redefined in MingW headers */
|
||||
#endif
|
||||
|
||||
/* Mac OS X portability check */
|
||||
#ifndef T_SRV
|
||||
#define T_SRV 33 /* server selection */
|
||||
#endif
|
||||
|
||||
/* AIX portability check */
|
||||
#ifndef T_NAPTR
|
||||
#define T_NAPTR 35 /* naming authority pointer */
|
||||
#endif
|
||||
|
||||
struct nv {
|
||||
const char *name;
|
||||
int value;
|
||||
};
|
||||
|
||||
static const struct nv flags[] = {
|
||||
{ "usevc", ARES_FLAG_USEVC },
|
||||
{ "primary", ARES_FLAG_PRIMARY },
|
||||
{ "igntc", ARES_FLAG_IGNTC },
|
||||
{ "norecurse", ARES_FLAG_NORECURSE },
|
||||
{ "stayopen", ARES_FLAG_STAYOPEN },
|
||||
{ "noaliases", ARES_FLAG_NOALIASES }
|
||||
};
|
||||
static const int nflags = sizeof(flags) / sizeof(flags[0]);
|
||||
|
||||
static const struct nv classes[] = {
|
||||
{ "IN", C_IN },
|
||||
{ "CHAOS", C_CHAOS },
|
||||
{ "HS", C_HS },
|
||||
{ "ANY", C_ANY }
|
||||
};
|
||||
static const int nclasses = sizeof(classes) / sizeof(classes[0]);
|
||||
|
||||
static const struct nv types[] = {
|
||||
{ "A", T_A },
|
||||
{ "NS", T_NS },
|
||||
{ "MD", T_MD },
|
||||
{ "MF", T_MF },
|
||||
{ "CNAME", T_CNAME },
|
||||
{ "SOA", T_SOA },
|
||||
{ "MB", T_MB },
|
||||
{ "MG", T_MG },
|
||||
{ "MR", T_MR },
|
||||
{ "NULL", T_NULL },
|
||||
{ "WKS", T_WKS },
|
||||
{ "PTR", T_PTR },
|
||||
{ "HINFO", T_HINFO },
|
||||
{ "MINFO", T_MINFO },
|
||||
{ "MX", T_MX },
|
||||
{ "TXT", T_TXT },
|
||||
{ "RP", T_RP },
|
||||
{ "AFSDB", T_AFSDB },
|
||||
{ "X25", T_X25 },
|
||||
{ "ISDN", T_ISDN },
|
||||
{ "RT", T_RT },
|
||||
{ "NSAP", T_NSAP },
|
||||
{ "NSAP_PTR", T_NSAP_PTR },
|
||||
{ "SIG", T_SIG },
|
||||
{ "KEY", T_KEY },
|
||||
{ "PX", T_PX },
|
||||
{ "GPOS", T_GPOS },
|
||||
{ "AAAA", T_AAAA },
|
||||
{ "LOC", T_LOC },
|
||||
{ "SRV", T_SRV },
|
||||
{ "AXFR", T_AXFR },
|
||||
{ "MAILB", T_MAILB },
|
||||
{ "MAILA", T_MAILA },
|
||||
{ "NAPTR", T_NAPTR },
|
||||
{ "ANY", T_ANY }
|
||||
};
|
||||
static const int ntypes = sizeof(types) / sizeof(types[0]);
|
||||
|
||||
static const char *opcodes[] = {
|
||||
"QUERY", "IQUERY", "STATUS", "(reserved)", "NOTIFY",
|
||||
"(unknown)", "(unknown)", "(unknown)", "(unknown)",
|
||||
"UPDATEA", "UPDATED", "UPDATEDA", "UPDATEM", "UPDATEMA",
|
||||
"ZONEINIT", "ZONEREF"
|
||||
};
|
||||
|
||||
static const char *rcodes[] = {
|
||||
"NOERROR", "FORMERR", "SERVFAIL", "NXDOMAIN", "NOTIMP", "REFUSED",
|
||||
"(unknown)", "(unknown)", "(unknown)", "(unknown)", "(unknown)",
|
||||
"(unknown)", "(unknown)", "(unknown)", "(unknown)", "NOCHANGE"
|
||||
};
|
||||
|
||||
static void callback(void *arg, int status, int timeouts,
|
||||
unsigned char *abuf, int alen);
|
||||
static const unsigned char *display_question(const unsigned char *aptr,
|
||||
const unsigned char *abuf,
|
||||
int alen);
|
||||
static const unsigned char *display_rr(const unsigned char *aptr,
|
||||
const unsigned char *abuf, int alen);
|
||||
static const char *type_name(int type);
|
||||
static const char *class_name(int dnsclass);
|
||||
static void usage(void);
|
||||
static void destroy_addr_list(struct ares_addr_node *head);
|
||||
static void append_addr_list(struct ares_addr_node **head,
|
||||
struct ares_addr_node *node);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ares_channel channel;
|
||||
int c, i, optmask = ARES_OPT_FLAGS, dnsclass = C_IN, type = T_A;
|
||||
int status, nfds, count;
|
||||
struct ares_options options;
|
||||
struct hostent *hostent;
|
||||
fd_set read_fds, write_fds;
|
||||
struct timeval *tvp, tv;
|
||||
struct ares_addr_node *srvr, *servers = NULL;
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
WORD wVersionRequested = MAKEWORD(USE_WINSOCK,USE_WINSOCK);
|
||||
WSADATA wsaData;
|
||||
WSAStartup(wVersionRequested, &wsaData);
|
||||
#endif
|
||||
|
||||
status = ares_library_init(ARES_LIB_INIT_ALL);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status));
|
||||
return 1;
|
||||
}
|
||||
|
||||
options.flags = ARES_FLAG_NOCHECKRESP;
|
||||
options.servers = NULL;
|
||||
options.nservers = 0;
|
||||
while ((c = ares_getopt(argc, argv, "df:s:c:t:T:U:")) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'd':
|
||||
#ifdef WATT32
|
||||
dbug_init();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
/* Add a flag. */
|
||||
for (i = 0; i < nflags; i++)
|
||||
{
|
||||
if (strcmp(flags[i].name, optarg) == 0)
|
||||
break;
|
||||
}
|
||||
if (i < nflags)
|
||||
options.flags |= flags[i].value;
|
||||
else
|
||||
usage();
|
||||
break;
|
||||
|
||||
case 's':
|
||||
/* User specified name servers override default ones. */
|
||||
srvr = malloc(sizeof(struct ares_addr_node));
|
||||
if (!srvr)
|
||||
{
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
destroy_addr_list(servers);
|
||||
return 1;
|
||||
}
|
||||
append_addr_list(&servers, srvr);
|
||||
if (ares_inet_pton(AF_INET, optarg, &srvr->addr.addr4) > 0)
|
||||
srvr->family = AF_INET;
|
||||
else if (ares_inet_pton(AF_INET6, optarg, &srvr->addr.addr6) > 0)
|
||||
srvr->family = AF_INET6;
|
||||
else
|
||||
{
|
||||
hostent = gethostbyname(optarg);
|
||||
if (!hostent)
|
||||
{
|
||||
fprintf(stderr, "adig: server %s not found.\n", optarg);
|
||||
destroy_addr_list(servers);
|
||||
return 1;
|
||||
}
|
||||
switch (hostent->h_addrtype)
|
||||
{
|
||||
case AF_INET:
|
||||
srvr->family = AF_INET;
|
||||
memcpy(&srvr->addr.addr4, hostent->h_addr,
|
||||
sizeof(srvr->addr.addr4));
|
||||
break;
|
||||
case AF_INET6:
|
||||
srvr->family = AF_INET6;
|
||||
memcpy(&srvr->addr.addr6, hostent->h_addr,
|
||||
sizeof(srvr->addr.addr6));
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"adig: server %s unsupported address family.\n", optarg);
|
||||
destroy_addr_list(servers);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/* Notice that calling ares_init_options() without servers in the
|
||||
* options struct and with ARES_OPT_SERVERS set simultaneously in
|
||||
* the options mask, results in an initialization with no servers.
|
||||
* When alternative name servers have been specified these are set
|
||||
* later calling ares_set_servers() overriding any existing server
|
||||
* configuration. To prevent initial configuration with default
|
||||
* servers that will be discarded later ARES_OPT_SERVERS is set.
|
||||
* If this flag is not set here the result shall be the same but
|
||||
* ares_init_options() will do needless work. */
|
||||
optmask |= ARES_OPT_SERVERS;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
/* Set the query class. */
|
||||
for (i = 0; i < nclasses; i++)
|
||||
{
|
||||
if (strcasecmp(classes[i].name, optarg) == 0)
|
||||
break;
|
||||
}
|
||||
if (i < nclasses)
|
||||
dnsclass = classes[i].value;
|
||||
else
|
||||
usage();
|
||||
break;
|
||||
|
||||
case 't':
|
||||
/* Set the query type. */
|
||||
for (i = 0; i < ntypes; i++)
|
||||
{
|
||||
if (strcasecmp(types[i].name, optarg) == 0)
|
||||
break;
|
||||
}
|
||||
if (i < ntypes)
|
||||
type = types[i].value;
|
||||
else
|
||||
usage();
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
/* Set the TCP port number. */
|
||||
if (!ISDIGIT(*optarg))
|
||||
usage();
|
||||
options.tcp_port = (unsigned short)strtol(optarg, NULL, 0);
|
||||
optmask |= ARES_OPT_TCP_PORT;
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
/* Set the UDP port number. */
|
||||
if (!ISDIGIT(*optarg))
|
||||
usage();
|
||||
options.udp_port = (unsigned short)strtol(optarg, NULL, 0);
|
||||
optmask |= ARES_OPT_UDP_PORT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc == 0)
|
||||
usage();
|
||||
|
||||
status = ares_init_options(&channel, &options, optmask);
|
||||
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "ares_init_options: %s\n",
|
||||
ares_strerror(status));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(servers)
|
||||
{
|
||||
status = ares_set_servers(channel, servers);
|
||||
destroy_addr_list(servers);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "ares_init_options: %s\n",
|
||||
ares_strerror(status));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initiate the queries, one per command-line argument. If there is
|
||||
* only one query to do, supply NULL as the callback argument;
|
||||
* otherwise, supply the query name as an argument so we can
|
||||
* distinguish responses for the user when printing them out.
|
||||
*/
|
||||
if (argc == 1)
|
||||
ares_query(channel, *argv, dnsclass, type, callback, (char *) NULL);
|
||||
else
|
||||
{
|
||||
for (; *argv; argv++)
|
||||
ares_query(channel, *argv, dnsclass, type, callback, *argv);
|
||||
}
|
||||
|
||||
/* Wait for all queries to complete. */
|
||||
for (;;)
|
||||
{
|
||||
FD_ZERO(&read_fds);
|
||||
FD_ZERO(&write_fds);
|
||||
nfds = ares_fds(channel, &read_fds, &write_fds);
|
||||
if (nfds == 0)
|
||||
break;
|
||||
tvp = ares_timeout(channel, NULL, &tv);
|
||||
count = select(nfds, &read_fds, &write_fds, NULL, tvp);
|
||||
if (count < 0 && SOCKERRNO != EINVAL)
|
||||
{
|
||||
perror("select");
|
||||
return 1;
|
||||
}
|
||||
ares_process(channel, &read_fds, &write_fds);
|
||||
}
|
||||
|
||||
ares_destroy(channel);
|
||||
|
||||
ares_library_cleanup();
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
WSACleanup();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void callback(void *arg, int status, int timeouts,
|
||||
unsigned char *abuf, int alen)
|
||||
{
|
||||
char *name = (char *) arg;
|
||||
int id, qr, opcode, aa, tc, rd, ra, rcode;
|
||||
unsigned int qdcount, ancount, nscount, arcount, i;
|
||||
const unsigned char *aptr;
|
||||
|
||||
(void) timeouts;
|
||||
|
||||
/* Display the query name if given. */
|
||||
if (name)
|
||||
printf("Answer for query %s:\n", name);
|
||||
|
||||
/* Display an error message if there was an error, but only stop if
|
||||
* we actually didn't get an answer buffer.
|
||||
*/
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
printf("%s\n", ares_strerror(status));
|
||||
if (!abuf)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Won't happen, but check anyway, for safety. */
|
||||
if (alen < HFIXEDSZ)
|
||||
return;
|
||||
|
||||
/* Parse the answer header. */
|
||||
id = DNS_HEADER_QID(abuf);
|
||||
qr = DNS_HEADER_QR(abuf);
|
||||
opcode = DNS_HEADER_OPCODE(abuf);
|
||||
aa = DNS_HEADER_AA(abuf);
|
||||
tc = DNS_HEADER_TC(abuf);
|
||||
rd = DNS_HEADER_RD(abuf);
|
||||
ra = DNS_HEADER_RA(abuf);
|
||||
rcode = DNS_HEADER_RCODE(abuf);
|
||||
qdcount = DNS_HEADER_QDCOUNT(abuf);
|
||||
ancount = DNS_HEADER_ANCOUNT(abuf);
|
||||
nscount = DNS_HEADER_NSCOUNT(abuf);
|
||||
arcount = DNS_HEADER_ARCOUNT(abuf);
|
||||
|
||||
/* Display the answer header. */
|
||||
printf("id: %d\n", id);
|
||||
printf("flags: %s%s%s%s%s\n",
|
||||
qr ? "qr " : "",
|
||||
aa ? "aa " : "",
|
||||
tc ? "tc " : "",
|
||||
rd ? "rd " : "",
|
||||
ra ? "ra " : "");
|
||||
printf("opcode: %s\n", opcodes[opcode]);
|
||||
printf("rcode: %s\n", rcodes[rcode]);
|
||||
|
||||
/* Display the questions. */
|
||||
printf("Questions:\n");
|
||||
aptr = abuf + HFIXEDSZ;
|
||||
for (i = 0; i < qdcount; i++)
|
||||
{
|
||||
aptr = display_question(aptr, abuf, alen);
|
||||
if (aptr == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Display the answers. */
|
||||
printf("Answers:\n");
|
||||
for (i = 0; i < ancount; i++)
|
||||
{
|
||||
aptr = display_rr(aptr, abuf, alen);
|
||||
if (aptr == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Display the NS records. */
|
||||
printf("NS records:\n");
|
||||
for (i = 0; i < nscount; i++)
|
||||
{
|
||||
aptr = display_rr(aptr, abuf, alen);
|
||||
if (aptr == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Display the additional records. */
|
||||
printf("Additional records:\n");
|
||||
for (i = 0; i < arcount; i++)
|
||||
{
|
||||
aptr = display_rr(aptr, abuf, alen);
|
||||
if (aptr == NULL)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static const unsigned char *display_question(const unsigned char *aptr,
|
||||
const unsigned char *abuf,
|
||||
int alen)
|
||||
{
|
||||
char *name;
|
||||
int type, dnsclass, status;
|
||||
long len;
|
||||
|
||||
/* Parse the question name. */
|
||||
status = ares_expand_name(aptr, abuf, alen, &name, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
aptr += len;
|
||||
|
||||
/* Make sure there's enough data after the name for the fixed part
|
||||
* of the question.
|
||||
*/
|
||||
if (aptr + QFIXEDSZ > abuf + alen)
|
||||
{
|
||||
ares_free_string(name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Parse the question type and class. */
|
||||
type = DNS_QUESTION_TYPE(aptr);
|
||||
dnsclass = DNS_QUESTION_CLASS(aptr);
|
||||
aptr += QFIXEDSZ;
|
||||
|
||||
/* Display the question, in a format sort of similar to how we will
|
||||
* display RRs.
|
||||
*/
|
||||
printf("\t%-15s.\t", name);
|
||||
if (dnsclass != C_IN)
|
||||
printf("\t%s", class_name(dnsclass));
|
||||
printf("\t%s\n", type_name(type));
|
||||
ares_free_string(name);
|
||||
return aptr;
|
||||
}
|
||||
|
||||
static const unsigned char *display_rr(const unsigned char *aptr,
|
||||
const unsigned char *abuf, int alen)
|
||||
{
|
||||
const unsigned char *p;
|
||||
int type, dnsclass, ttl, dlen, status;
|
||||
long len;
|
||||
char addr[46];
|
||||
union {
|
||||
unsigned char * as_uchar;
|
||||
char * as_char;
|
||||
} name;
|
||||
|
||||
/* Parse the RR name. */
|
||||
status = ares_expand_name(aptr, abuf, alen, &name.as_char, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
aptr += len;
|
||||
|
||||
/* Make sure there is enough data after the RR name for the fixed
|
||||
* part of the RR.
|
||||
*/
|
||||
if (aptr + RRFIXEDSZ > abuf + alen)
|
||||
{
|
||||
ares_free_string(name.as_char);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Parse the fixed part of the RR, and advance to the RR data
|
||||
* field. */
|
||||
type = DNS_RR_TYPE(aptr);
|
||||
dnsclass = DNS_RR_CLASS(aptr);
|
||||
ttl = DNS_RR_TTL(aptr);
|
||||
dlen = DNS_RR_LEN(aptr);
|
||||
aptr += RRFIXEDSZ;
|
||||
if (aptr + dlen > abuf + alen)
|
||||
{
|
||||
ares_free_string(name.as_char);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Display the RR name, class, and type. */
|
||||
printf("\t%-15s.\t%d", name.as_char, ttl);
|
||||
if (dnsclass != C_IN)
|
||||
printf("\t%s", class_name(dnsclass));
|
||||
printf("\t%s", type_name(type));
|
||||
ares_free_string(name.as_char);
|
||||
|
||||
/* Display the RR data. Don't touch aptr. */
|
||||
switch (type)
|
||||
{
|
||||
case T_CNAME:
|
||||
case T_MB:
|
||||
case T_MD:
|
||||
case T_MF:
|
||||
case T_MG:
|
||||
case T_MR:
|
||||
case T_NS:
|
||||
case T_PTR:
|
||||
/* For these types, the RR data is just a domain name. */
|
||||
status = ares_expand_name(aptr, abuf, alen, &name.as_char, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t%s.", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
break;
|
||||
|
||||
case T_HINFO:
|
||||
/* The RR data is two length-counted character strings. */
|
||||
p = aptr;
|
||||
len = *p;
|
||||
if (p + len + 1 > aptr + dlen)
|
||||
return NULL;
|
||||
status = ares_expand_string(p, abuf, alen, &name.as_uchar, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t%s", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
p += len;
|
||||
len = *p;
|
||||
if (p + len + 1 > aptr + dlen)
|
||||
return NULL;
|
||||
status = ares_expand_string(p, abuf, alen, &name.as_uchar, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t%s", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
break;
|
||||
|
||||
case T_MINFO:
|
||||
/* The RR data is two domain names. */
|
||||
p = aptr;
|
||||
status = ares_expand_name(p, abuf, alen, &name.as_char, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t%s.", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
p += len;
|
||||
status = ares_expand_name(p, abuf, alen, &name.as_char, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t%s.", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
break;
|
||||
|
||||
case T_MX:
|
||||
/* The RR data is two bytes giving a preference ordering, and
|
||||
* then a domain name.
|
||||
*/
|
||||
if (dlen < 2)
|
||||
return NULL;
|
||||
printf("\t%d", DNS__16BIT(aptr));
|
||||
status = ares_expand_name(aptr + 2, abuf, alen, &name.as_char, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t%s.", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
break;
|
||||
|
||||
case T_SOA:
|
||||
/* The RR data is two domain names and then five four-byte
|
||||
* numbers giving the serial number and some timeouts.
|
||||
*/
|
||||
p = aptr;
|
||||
status = ares_expand_name(p, abuf, alen, &name.as_char, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t%s.\n", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
p += len;
|
||||
status = ares_expand_name(p, abuf, alen, &name.as_char, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t\t\t\t\t\t%s.\n", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
p += len;
|
||||
if (p + 20 > aptr + dlen)
|
||||
return NULL;
|
||||
printf("\t\t\t\t\t\t( %lu %lu %lu %lu %lu )",
|
||||
(unsigned long)DNS__32BIT(p), (unsigned long)DNS__32BIT(p+4),
|
||||
(unsigned long)DNS__32BIT(p+8), (unsigned long)DNS__32BIT(p+12),
|
||||
(unsigned long)DNS__32BIT(p+16));
|
||||
break;
|
||||
|
||||
case T_TXT:
|
||||
/* The RR data is one or more length-counted character
|
||||
* strings. */
|
||||
p = aptr;
|
||||
while (p < aptr + dlen)
|
||||
{
|
||||
len = *p;
|
||||
if (p + len + 1 > aptr + dlen)
|
||||
return NULL;
|
||||
status = ares_expand_string(p, abuf, alen, &name.as_uchar, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t%s", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
p += len;
|
||||
}
|
||||
break;
|
||||
|
||||
case T_A:
|
||||
/* The RR data is a four-byte Internet address. */
|
||||
if (dlen != 4)
|
||||
return NULL;
|
||||
printf("\t%s", ares_inet_ntop(AF_INET,aptr,addr,sizeof(addr)));
|
||||
break;
|
||||
|
||||
case T_AAAA:
|
||||
/* The RR data is a 16-byte IPv6 address. */
|
||||
if (dlen != 16)
|
||||
return NULL;
|
||||
printf("\t%s", ares_inet_ntop(AF_INET6,aptr,addr,sizeof(addr)));
|
||||
break;
|
||||
|
||||
case T_WKS:
|
||||
/* Not implemented yet */
|
||||
break;
|
||||
|
||||
case T_SRV:
|
||||
/* The RR data is three two-byte numbers representing the
|
||||
* priority, weight, and port, followed by a domain name.
|
||||
*/
|
||||
|
||||
printf("\t%d", DNS__16BIT(aptr));
|
||||
printf(" %d", DNS__16BIT(aptr + 2));
|
||||
printf(" %d", DNS__16BIT(aptr + 4));
|
||||
|
||||
status = ares_expand_name(aptr + 6, abuf, alen, &name.as_char, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t%s.", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
break;
|
||||
|
||||
case T_NAPTR:
|
||||
|
||||
printf("\t%d", DNS__16BIT(aptr)); /* order */
|
||||
printf(" %d\n", DNS__16BIT(aptr + 2)); /* preference */
|
||||
|
||||
p = aptr + 4;
|
||||
status = ares_expand_string(p, abuf, alen, &name.as_uchar, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t\t\t\t\t\t%s\n", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
p += len;
|
||||
|
||||
status = ares_expand_string(p, abuf, alen, &name.as_uchar, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t\t\t\t\t\t%s\n", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
p += len;
|
||||
|
||||
status = ares_expand_string(p, abuf, alen, &name.as_uchar, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t\t\t\t\t\t%s\n", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
p += len;
|
||||
|
||||
status = ares_expand_string(p, abuf, alen, &name.as_uchar, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return NULL;
|
||||
printf("\t\t\t\t\t\t%s", name.as_char);
|
||||
ares_free_string(name.as_char);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
printf("\t[Unknown RR; cannot parse]");
|
||||
break;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return aptr + dlen;
|
||||
}
|
||||
|
||||
static const char *type_name(int type)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ntypes; i++)
|
||||
{
|
||||
if (types[i].value == type)
|
||||
return types[i].name;
|
||||
}
|
||||
return "(unknown)";
|
||||
}
|
||||
|
||||
static const char *class_name(int dnsclass)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nclasses; i++)
|
||||
{
|
||||
if (classes[i].value == dnsclass)
|
||||
return classes[i].name;
|
||||
}
|
||||
return "(unknown)";
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: adig [-f flag] [-s server] [-c class] "
|
||||
"[-t type] [-p port] name ...\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void destroy_addr_list(struct ares_addr_node *head)
|
||||
{
|
||||
while(head)
|
||||
{
|
||||
struct ares_addr_node *detached = head;
|
||||
head = head->next;
|
||||
free(detached);
|
||||
}
|
||||
}
|
||||
|
||||
static void append_addr_list(struct ares_addr_node **head,
|
||||
struct ares_addr_node *node)
|
||||
{
|
||||
struct ares_addr_node *last;
|
||||
node->next = NULL;
|
||||
if(*head)
|
||||
{
|
||||
last = *head;
|
||||
while(last->next)
|
||||
last = last->next;
|
||||
last->next = node;
|
||||
}
|
||||
else
|
||||
*head = node;
|
||||
}
|
202
ares/ahost.c
202
ares/ahost.c
@ -1,202 +0,0 @@
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* 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"
|
||||
|
||||
#if !defined(WIN32) || defined(WATT32)
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_dns.h"
|
||||
#include "inet_ntop.h"
|
||||
#include "inet_net_pton.h"
|
||||
#include "ares_getopt.h"
|
||||
#include "ares_ipv6.h"
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
# include "ares_strdup.h"
|
||||
# define strdup(ptr) ares_strdup(ptr)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRCASECMP
|
||||
# include "ares_strcasecmp.h"
|
||||
# define strcasecmp(p1,p2) ares_strcasecmp(p1,p2)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRNCASECMP
|
||||
# include "ares_strcasecmp.h"
|
||||
# define strncasecmp(p1,p2,n) ares_strncasecmp(p1,p2,n)
|
||||
#endif
|
||||
|
||||
static void callback(void *arg, int status, int timeouts, struct hostent *host);
|
||||
static void usage(void);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ares_channel channel;
|
||||
int status, nfds, c, addr_family = AF_INET;
|
||||
fd_set read_fds, write_fds;
|
||||
struct timeval *tvp, tv;
|
||||
struct in_addr addr4;
|
||||
struct ares_in6_addr addr6;
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
WORD wVersionRequested = MAKEWORD(USE_WINSOCK,USE_WINSOCK);
|
||||
WSADATA wsaData;
|
||||
WSAStartup(wVersionRequested, &wsaData);
|
||||
#endif
|
||||
|
||||
status = ares_library_init(ARES_LIB_INIT_ALL);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status));
|
||||
return 1;
|
||||
}
|
||||
|
||||
while ((c = ares_getopt(argc,argv,"dt:h")) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'd':
|
||||
#ifdef WATT32
|
||||
dbug_init();
|
||||
#endif
|
||||
break;
|
||||
case 't':
|
||||
if (!strcasecmp(optarg,"a"))
|
||||
addr_family = AF_INET;
|
||||
else if (!strcasecmp(optarg,"aaaa"))
|
||||
addr_family = AF_INET6;
|
||||
else
|
||||
usage();
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc < 1)
|
||||
usage();
|
||||
|
||||
status = ares_init(&channel);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "ares_init: %s\n", ares_strerror(status));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Initiate the queries, one per command-line argument. */
|
||||
for ( ; *argv; argv++)
|
||||
{
|
||||
if (ares_inet_pton(AF_INET, *argv, &addr4) == 1)
|
||||
{
|
||||
ares_gethostbyaddr(channel, &addr4, sizeof(addr4), AF_INET, callback,
|
||||
*argv);
|
||||
}
|
||||
else if (ares_inet_pton(AF_INET6, *argv, &addr6) == 1)
|
||||
{
|
||||
ares_gethostbyaddr(channel, &addr6, sizeof(addr6), AF_INET6, callback,
|
||||
*argv);
|
||||
}
|
||||
else
|
||||
{
|
||||
ares_gethostbyname(channel, *argv, addr_family, callback, *argv);
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait for all queries to complete. */
|
||||
for (;;)
|
||||
{
|
||||
FD_ZERO(&read_fds);
|
||||
FD_ZERO(&write_fds);
|
||||
nfds = ares_fds(channel, &read_fds, &write_fds);
|
||||
if (nfds == 0)
|
||||
break;
|
||||
tvp = ares_timeout(channel, NULL, &tv);
|
||||
select(nfds, &read_fds, &write_fds, NULL, tvp);
|
||||
ares_process(channel, &read_fds, &write_fds);
|
||||
}
|
||||
|
||||
ares_destroy(channel);
|
||||
|
||||
ares_library_cleanup();
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
WSACleanup();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void callback(void *arg, int status, int timeouts, struct hostent *host)
|
||||
{
|
||||
char **p;
|
||||
|
||||
(void)timeouts;
|
||||
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "%s: %s\n", (char *) arg, ares_strerror(status));
|
||||
return;
|
||||
}
|
||||
|
||||
for (p = host->h_addr_list; *p; p++)
|
||||
{
|
||||
char addr_buf[46] = "??";
|
||||
|
||||
ares_inet_ntop(host->h_addrtype, *p, addr_buf, sizeof(addr_buf));
|
||||
printf("%-32s\t%s", host->h_name, addr_buf);
|
||||
#if 0
|
||||
if (host->h_aliases[0])
|
||||
{
|
||||
int i;
|
||||
|
||||
printf (", Aliases: ");
|
||||
for (i = 0; host->h_aliases[i]; i++)
|
||||
printf("%s ", host->h_aliases[i]);
|
||||
}
|
||||
#endif
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: ahost [-t {a|aaaa}] {host|addr} ...\n");
|
||||
exit(1);
|
||||
}
|
509
ares/ares.h
509
ares/ares.h
@ -1,509 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998, 2009 by the Massachusetts Institute of Technology.
|
||||
* Copyright (C) 2007-2010 by Daniel Stenberg
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ARES__H
|
||||
#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
|
||||
*/
|
||||
|
||||
#if (defined(_WIN32) || defined(__WIN32__)) && \
|
||||
!defined(WIN32) && !defined(__SYMBIAN32__)
|
||||
# define WIN32
|
||||
#endif
|
||||
|
||||
#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)
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
|
||||
#include <sys/bsdskt.h>
|
||||
#endif
|
||||
|
||||
#if defined(WATT32)
|
||||
# include <netinet/in.h>
|
||||
# include <sys/socket.h>
|
||||
# include <tcp.h>
|
||||
#elif defined(WIN32)
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h>
|
||||
#else
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
** c-ares external API function linkage decorations.
|
||||
*/
|
||||
|
||||
#if !defined(CARES_STATICLIB) && \
|
||||
(defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__))
|
||||
/* __declspec function decoration for Win32 and Symbian DLL's */
|
||||
# if defined(CARES_BUILDING_LIBRARY)
|
||||
# define CARES_EXTERN __declspec(dllexport)
|
||||
# else
|
||||
# define CARES_EXTERN __declspec(dllimport)
|
||||
# endif
|
||||
#else
|
||||
/* visibility function decoration for other cases */
|
||||
# if !defined(CARES_SYMBOL_HIDING) || \
|
||||
defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__)
|
||||
# define CARES_EXTERN
|
||||
# else
|
||||
# define CARES_EXTERN CARES_SYMBOL_SCOPE_EXTERN
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#define ARES_SUCCESS 0
|
||||
|
||||
/* Server error codes (ARES_ENODATA indicates no relevant answer) */
|
||||
#define ARES_ENODATA 1
|
||||
#define ARES_EFORMERR 2
|
||||
#define ARES_ESERVFAIL 3
|
||||
#define ARES_ENOTFOUND 4
|
||||
#define ARES_ENOTIMP 5
|
||||
#define ARES_EREFUSED 6
|
||||
|
||||
/* Locally generated error codes */
|
||||
#define ARES_EBADQUERY 7
|
||||
#define ARES_EBADNAME 8
|
||||
#define ARES_EBADFAMILY 9
|
||||
#define ARES_EBADRESP 10
|
||||
#define ARES_ECONNREFUSED 11
|
||||
#define ARES_ETIMEOUT 12
|
||||
#define ARES_EOF 13
|
||||
#define ARES_EFILE 14
|
||||
#define ARES_ENOMEM 15
|
||||
#define ARES_EDESTRUCTION 16
|
||||
#define ARES_EBADSTR 17
|
||||
|
||||
/* ares_getnameinfo error codes */
|
||||
#define ARES_EBADFLAGS 18
|
||||
|
||||
/* ares_getaddrinfo error codes */
|
||||
#define ARES_ENONAME 19
|
||||
#define ARES_EBADHINTS 20
|
||||
|
||||
/* Uninitialized library error code */
|
||||
#define ARES_ENOTINITIALIZED 21 /* introduced in 1.7.0 */
|
||||
|
||||
/* ares_library_init error codes */
|
||||
#define ARES_ELOADIPHLPAPI 22 /* introduced in 1.7.0 */
|
||||
#define ARES_EADDRGETNETWORKPARAMS 23 /* introduced in 1.7.0 */
|
||||
|
||||
/* More error codes */
|
||||
#define ARES_ECANCELLED 24 /* introduced in 1.7.0 */
|
||||
|
||||
/* Flag values */
|
||||
#define ARES_FLAG_USEVC (1 << 0)
|
||||
#define ARES_FLAG_PRIMARY (1 << 1)
|
||||
#define ARES_FLAG_IGNTC (1 << 2)
|
||||
#define ARES_FLAG_NORECURSE (1 << 3)
|
||||
#define ARES_FLAG_STAYOPEN (1 << 4)
|
||||
#define ARES_FLAG_NOSEARCH (1 << 5)
|
||||
#define ARES_FLAG_NOALIASES (1 << 6)
|
||||
#define ARES_FLAG_NOCHECKRESP (1 << 7)
|
||||
|
||||
/* Option mask values */
|
||||
#define ARES_OPT_FLAGS (1 << 0)
|
||||
#define ARES_OPT_TIMEOUT (1 << 1)
|
||||
#define ARES_OPT_TRIES (1 << 2)
|
||||
#define ARES_OPT_NDOTS (1 << 3)
|
||||
#define ARES_OPT_UDP_PORT (1 << 4)
|
||||
#define ARES_OPT_TCP_PORT (1 << 5)
|
||||
#define ARES_OPT_SERVERS (1 << 6)
|
||||
#define ARES_OPT_DOMAINS (1 << 7)
|
||||
#define ARES_OPT_LOOKUPS (1 << 8)
|
||||
#define ARES_OPT_SOCK_STATE_CB (1 << 9)
|
||||
#define ARES_OPT_SORTLIST (1 << 10)
|
||||
#define ARES_OPT_SOCK_SNDBUF (1 << 11)
|
||||
#define ARES_OPT_SOCK_RCVBUF (1 << 12)
|
||||
#define ARES_OPT_TIMEOUTMS (1 << 13)
|
||||
#define ARES_OPT_ROTATE (1 << 14)
|
||||
|
||||
/* 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_IDN_ALLOW_UNASSIGNED (1 << 11)
|
||||
#define ARES_NI_IDN_USE_STD3_ASCII_RULES (1 << 12)
|
||||
|
||||
/* Addrinfo flag values */
|
||||
#define ARES_AI_CANONNAME (1 << 0)
|
||||
#define ARES_AI_NUMERICHOST (1 << 1)
|
||||
#define ARES_AI_PASSIVE (1 << 2)
|
||||
#define ARES_AI_NUMERICSERV (1 << 3)
|
||||
#define ARES_AI_V4MAPPED (1 << 4)
|
||||
#define ARES_AI_ALL (1 << 5)
|
||||
#define ARES_AI_ADDRCONFIG (1 << 6)
|
||||
/* Reserved for future use */
|
||||
#define ARES_AI_IDN (1 << 10)
|
||||
#define ARES_AI_IDN_ALLOW_UNASSIGNED (1 << 11)
|
||||
#define ARES_AI_IDN_USE_STD3_ASCII_RULES (1 << 12)
|
||||
#define ARES_AI_CANONIDN (1 << 13)
|
||||
|
||||
#define ARES_AI_MASK (ARES_AI_CANONNAME|ARES_AI_NUMERICHOST|ARES_AI_PASSIVE| \
|
||||
ARES_AI_NUMERICSERV|ARES_AI_V4MAPPED|ARES_AI_ALL| \
|
||||
ARES_AI_ADDRCONFIG)
|
||||
#define ARES_GETSOCK_MAXNUM 16 /* ares_getsock() can return info about this
|
||||
many sockets */
|
||||
#define ARES_GETSOCK_READABLE(bits,num) (bits & (1<< (num)))
|
||||
#define ARES_GETSOCK_WRITABLE(bits,num) (bits & (1 << ((num) + \
|
||||
ARES_GETSOCK_MAXNUM)))
|
||||
|
||||
/* c-ares library initialization flag values */
|
||||
#define ARES_LIB_INIT_NONE (0)
|
||||
#define ARES_LIB_INIT_WIN32 (1 << 0)
|
||||
#define ARES_LIB_INIT_ALL (ARES_LIB_INIT_WIN32)
|
||||
|
||||
|
||||
/*
|
||||
* Typedef our socket type
|
||||
*/
|
||||
|
||||
#ifndef ares_socket_typedef
|
||||
#ifdef WIN32
|
||||
typedef SOCKET ares_socket_t;
|
||||
#define ARES_SOCKET_BAD INVALID_SOCKET
|
||||
#else
|
||||
typedef int ares_socket_t;
|
||||
#define ARES_SOCKET_BAD -1
|
||||
#endif
|
||||
#define ares_socket_typedef
|
||||
#endif /* ares_socket_typedef */
|
||||
|
||||
typedef void (*ares_sock_state_cb)(void *data,
|
||||
ares_socket_t socket_fd,
|
||||
int readable,
|
||||
int writable);
|
||||
|
||||
struct apattern;
|
||||
|
||||
/* NOTE about the ares_options struct to users and developers.
|
||||
|
||||
This struct will remain looking like this. It will not be extended nor
|
||||
shrunk in future releases, but all new options will be set by ares_set_*()
|
||||
options instead of with the ares_init_options() function.
|
||||
|
||||
Eventually (in a galaxy far far away), all options will be settable by
|
||||
ares_set_*() options and the ares_init_options() function will become
|
||||
deprecated.
|
||||
|
||||
When new options are added to c-ares, they are not added to this
|
||||
struct. And they are not "saved" with the ares_save_options() function but
|
||||
instead we encourage the use of the ares_dup() function. Needless to say,
|
||||
if you add config options to c-ares you need to make sure ares_dup()
|
||||
duplicates this new option.
|
||||
|
||||
*/
|
||||
struct ares_options {
|
||||
int flags;
|
||||
int timeout; /* in seconds or milliseconds, depending on options */
|
||||
int tries;
|
||||
int ndots;
|
||||
unsigned short udp_port;
|
||||
unsigned short tcp_port;
|
||||
int socket_send_buffer_size;
|
||||
int socket_receive_buffer_size;
|
||||
struct in_addr *servers;
|
||||
int nservers;
|
||||
char **domains;
|
||||
int ndomains;
|
||||
char *lookups;
|
||||
ares_sock_state_cb sock_state_cb;
|
||||
void *sock_state_cb_data;
|
||||
struct apattern *sortlist;
|
||||
int nsort;
|
||||
};
|
||||
|
||||
struct hostent;
|
||||
struct timeval;
|
||||
struct sockaddr;
|
||||
struct ares_channeldata;
|
||||
|
||||
typedef struct ares_channeldata *ares_channel;
|
||||
|
||||
typedef void (*ares_callback)(void *arg,
|
||||
int status,
|
||||
int timeouts,
|
||||
unsigned char *abuf,
|
||||
int alen);
|
||||
|
||||
typedef void (*ares_host_callback)(void *arg,
|
||||
int status,
|
||||
int timeouts,
|
||||
struct hostent *hostent);
|
||||
|
||||
typedef void (*ares_nameinfo_callback)(void *arg,
|
||||
int status,
|
||||
int timeouts,
|
||||
char *node,
|
||||
char *service);
|
||||
|
||||
typedef int (*ares_sock_create_callback)(ares_socket_t socket_fd,
|
||||
int type,
|
||||
void *data);
|
||||
|
||||
CARES_EXTERN int ares_library_init(int flags);
|
||||
|
||||
CARES_EXTERN void ares_library_cleanup(void);
|
||||
|
||||
CARES_EXTERN const char *ares_version(int *version);
|
||||
|
||||
CARES_EXTERN int ares_init(ares_channel *channelptr);
|
||||
|
||||
CARES_EXTERN int ares_init_options(ares_channel *channelptr,
|
||||
struct ares_options *options,
|
||||
int optmask);
|
||||
|
||||
CARES_EXTERN int ares_save_options(ares_channel channel,
|
||||
struct ares_options *options,
|
||||
int *optmask);
|
||||
|
||||
CARES_EXTERN void ares_destroy_options(struct ares_options *options);
|
||||
|
||||
CARES_EXTERN int ares_dup(ares_channel *dest,
|
||||
ares_channel src);
|
||||
|
||||
CARES_EXTERN void ares_destroy(ares_channel channel);
|
||||
|
||||
CARES_EXTERN void ares_cancel(ares_channel channel);
|
||||
|
||||
CARES_EXTERN void ares_set_socket_callback(ares_channel channel,
|
||||
ares_sock_create_callback callback,
|
||||
void *user_data);
|
||||
|
||||
CARES_EXTERN void ares_send(ares_channel channel,
|
||||
const unsigned char *qbuf,
|
||||
int qlen,
|
||||
ares_callback callback,
|
||||
void *arg);
|
||||
|
||||
CARES_EXTERN void ares_query(ares_channel channel,
|
||||
const char *name,
|
||||
int dnsclass,
|
||||
int type,
|
||||
ares_callback callback,
|
||||
void *arg);
|
||||
|
||||
CARES_EXTERN void ares_search(ares_channel channel,
|
||||
const char *name,
|
||||
int dnsclass,
|
||||
int type,
|
||||
ares_callback callback,
|
||||
void *arg);
|
||||
|
||||
CARES_EXTERN void ares_gethostbyname(ares_channel channel,
|
||||
const char *name,
|
||||
int family,
|
||||
ares_host_callback callback,
|
||||
void *arg);
|
||||
|
||||
CARES_EXTERN int ares_gethostbyname_file(ares_channel channel,
|
||||
const char *name,
|
||||
int family,
|
||||
struct hostent **host);
|
||||
|
||||
CARES_EXTERN void ares_gethostbyaddr(ares_channel channel,
|
||||
const void *addr,
|
||||
int addrlen,
|
||||
int family,
|
||||
ares_host_callback callback,
|
||||
void *arg);
|
||||
|
||||
CARES_EXTERN void ares_getnameinfo(ares_channel channel,
|
||||
const struct sockaddr *sa,
|
||||
ares_socklen_t salen,
|
||||
int flags,
|
||||
ares_nameinfo_callback callback,
|
||||
void *arg);
|
||||
|
||||
CARES_EXTERN int ares_fds(ares_channel channel,
|
||||
fd_set *read_fds,
|
||||
fd_set *write_fds);
|
||||
|
||||
CARES_EXTERN int ares_getsock(ares_channel channel,
|
||||
ares_socket_t *socks,
|
||||
int numsocks);
|
||||
|
||||
CARES_EXTERN struct timeval *ares_timeout(ares_channel channel,
|
||||
struct timeval *maxtv,
|
||||
struct timeval *tv);
|
||||
|
||||
CARES_EXTERN void ares_process(ares_channel channel,
|
||||
fd_set *read_fds,
|
||||
fd_set *write_fds);
|
||||
|
||||
CARES_EXTERN void ares_process_fd(ares_channel channel,
|
||||
ares_socket_t read_fd,
|
||||
ares_socket_t write_fd);
|
||||
|
||||
CARES_EXTERN int ares_mkquery(const char *name,
|
||||
int dnsclass,
|
||||
int type,
|
||||
unsigned short id,
|
||||
int rd,
|
||||
unsigned char **buf,
|
||||
int *buflen);
|
||||
|
||||
CARES_EXTERN int ares_expand_name(const unsigned char *encoded,
|
||||
const unsigned char *abuf,
|
||||
int alen,
|
||||
char **s,
|
||||
long *enclen);
|
||||
|
||||
CARES_EXTERN int ares_expand_string(const unsigned char *encoded,
|
||||
const unsigned char *abuf,
|
||||
int alen,
|
||||
unsigned char **s,
|
||||
long *enclen);
|
||||
|
||||
/*
|
||||
* NOTE: before c-ares 1.7.0 we would most often use the system in6_addr
|
||||
* struct below when ares itself was built, but many apps would use this
|
||||
* private version since the header checked a HAVE_* define for it. Starting
|
||||
* with 1.7.0 we always declare and use our own to stop relying on the
|
||||
* system's one.
|
||||
*/
|
||||
struct ares_in6_addr {
|
||||
union {
|
||||
unsigned char _S6_u8[16];
|
||||
} _S6_un;
|
||||
};
|
||||
|
||||
struct ares_addrttl {
|
||||
struct in_addr ipaddr;
|
||||
int ttl;
|
||||
};
|
||||
|
||||
struct ares_addr6ttl {
|
||||
struct ares_in6_addr ip6addr;
|
||||
int ttl;
|
||||
};
|
||||
|
||||
struct ares_srv_reply {
|
||||
struct ares_srv_reply *next;
|
||||
char *host;
|
||||
unsigned short priority;
|
||||
unsigned short weight;
|
||||
unsigned short port;
|
||||
};
|
||||
|
||||
struct ares_txt_reply {
|
||||
struct ares_txt_reply *next;
|
||||
unsigned char *txt;
|
||||
size_t length; /* length excludes null termination */
|
||||
};
|
||||
|
||||
/*
|
||||
** 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.
|
||||
** Also, if addrttls is nonnull, put up to *naddrttls IPv4 addresses along with
|
||||
** their TTLs in that array, and set *naddrttls to the number of addresses
|
||||
** so written.
|
||||
*/
|
||||
|
||||
CARES_EXTERN int ares_parse_a_reply(const unsigned char *abuf,
|
||||
int alen,
|
||||
struct hostent **host,
|
||||
struct ares_addrttl *addrttls,
|
||||
int *naddrttls);
|
||||
|
||||
CARES_EXTERN int ares_parse_aaaa_reply(const unsigned char *abuf,
|
||||
int alen,
|
||||
struct hostent **host,
|
||||
struct ares_addr6ttl *addrttls,
|
||||
int *naddrttls);
|
||||
|
||||
CARES_EXTERN int ares_parse_ptr_reply(const unsigned char *abuf,
|
||||
int alen,
|
||||
const void *addr,
|
||||
int addrlen,
|
||||
int family,
|
||||
struct hostent **host);
|
||||
|
||||
CARES_EXTERN int ares_parse_ns_reply(const unsigned char *abuf,
|
||||
int alen,
|
||||
struct hostent **host);
|
||||
|
||||
CARES_EXTERN int ares_parse_srv_reply(const unsigned char* abuf,
|
||||
int alen,
|
||||
struct ares_srv_reply** srv_out);
|
||||
|
||||
CARES_EXTERN int ares_parse_txt_reply(const unsigned char* abuf,
|
||||
int alen,
|
||||
struct ares_txt_reply** txt_out);
|
||||
|
||||
CARES_EXTERN void ares_free_string(void *str);
|
||||
|
||||
CARES_EXTERN void ares_free_hostent(struct hostent *host);
|
||||
|
||||
CARES_EXTERN void ares_free_data(void *dataptr);
|
||||
|
||||
CARES_EXTERN const char *ares_strerror(int code);
|
||||
|
||||
struct ares_addr_node {
|
||||
struct ares_addr_node *next;
|
||||
int family;
|
||||
union {
|
||||
struct in_addr addr4;
|
||||
struct ares_in6_addr addr6;
|
||||
} addr;
|
||||
};
|
||||
|
||||
CARES_EXTERN int ares_set_servers(ares_channel channel,
|
||||
struct ares_addr_node *servers);
|
||||
|
||||
CARES_EXTERN int ares_get_servers(ares_channel channel,
|
||||
struct ares_addr_node **servers);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ARES__H */
|
@ -1,67 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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"
|
||||
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
void ares__close_sockets(ares_channel channel, struct server_state *server)
|
||||
{
|
||||
struct send_request *sendreq;
|
||||
|
||||
/* Free all pending output buffers. */
|
||||
while (server->qhead)
|
||||
{
|
||||
/* Advance server->qhead; pull out query as we go. */
|
||||
sendreq = server->qhead;
|
||||
server->qhead = sendreq->next;
|
||||
if (sendreq->data_storage != NULL)
|
||||
free(sendreq->data_storage);
|
||||
free(sendreq);
|
||||
}
|
||||
server->qtail = NULL;
|
||||
|
||||
/* Reset any existing input buffer. */
|
||||
if (server->tcp_buffer)
|
||||
free(server->tcp_buffer);
|
||||
server->tcp_buffer = NULL;
|
||||
server->tcp_lenbuf_pos = 0;
|
||||
|
||||
/* Reset brokenness */
|
||||
server->is_broken = 0;
|
||||
|
||||
/* Close the TCP and UDP sockets. */
|
||||
if (server->tcp_socket != ARES_SOCKET_BAD)
|
||||
{
|
||||
SOCK_STATE_CALLBACK(channel, server->tcp_socket, 0, 0);
|
||||
sclose(server->tcp_socket);
|
||||
server->tcp_socket = ARES_SOCKET_BAD;
|
||||
server->tcp_connection_generation = ++channel->tcp_connection_generation;
|
||||
}
|
||||
if (server->udp_socket != ARES_SOCKET_BAD)
|
||||
{
|
||||
SOCK_STATE_CALLBACK(channel, server->udp_socket, 0, 0);
|
||||
sclose(server->udp_socket);
|
||||
server->udp_socket = ARES_SOCKET_BAD;
|
||||
}
|
||||
}
|
@ -1,264 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998, 2010 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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
|
||||
|
||||
#include "ares.h"
|
||||
#include "inet_net_pton.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
int ares__get_hostent(FILE *fp, int family, struct hostent **host)
|
||||
{
|
||||
char *line = NULL, *p, *q, **alias;
|
||||
char *txtaddr, *txthost, *txtalias;
|
||||
int status;
|
||||
size_t addrlen, linesize, naliases;
|
||||
struct ares_addr addr;
|
||||
struct hostent *hostent = NULL;
|
||||
|
||||
*host = NULL; /* Assume failure */
|
||||
|
||||
/* Validate family */
|
||||
switch (family) {
|
||||
case AF_INET:
|
||||
case AF_INET6:
|
||||
case AF_UNSPEC:
|
||||
break;
|
||||
default:
|
||||
return ARES_EBADFAMILY;
|
||||
}
|
||||
|
||||
while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
|
||||
{
|
||||
|
||||
/* Trim line comment. */
|
||||
p = line;
|
||||
while (*p && (*p != '#'))
|
||||
p++;
|
||||
*p = '\0';
|
||||
|
||||
/* Trim trailing whitespace. */
|
||||
q = p - 1;
|
||||
while ((q >= line) && ISSPACE(*q))
|
||||
q--;
|
||||
*++q = '\0';
|
||||
|
||||
/* Skip leading whitespace. */
|
||||
p = line;
|
||||
while (*p && ISSPACE(*p))
|
||||
p++;
|
||||
if (!*p)
|
||||
/* Ignore line if empty. */
|
||||
continue;
|
||||
|
||||
/* Pointer to start of IPv4 or IPv6 address part. */
|
||||
txtaddr = p;
|
||||
|
||||
/* Advance past address part. */
|
||||
while (*p && !ISSPACE(*p))
|
||||
p++;
|
||||
if (!*p)
|
||||
/* Ignore line if reached end of line. */
|
||||
continue;
|
||||
|
||||
/* Null terminate address part. */
|
||||
*p = '\0';
|
||||
|
||||
/* Advance to host name */
|
||||
p++;
|
||||
while (*p && ISSPACE(*p))
|
||||
p++;
|
||||
if (!*p)
|
||||
/* Ignore line if reached end of line. */
|
||||
continue;
|
||||
|
||||
/* Pointer to start of host name. */
|
||||
txthost = p;
|
||||
|
||||
/* Advance past host name. */
|
||||
while (*p && !ISSPACE(*p))
|
||||
p++;
|
||||
|
||||
/* Pointer to start of first alias. */
|
||||
txtalias = NULL;
|
||||
if (*p)
|
||||
{
|
||||
q = p + 1;
|
||||
while (*q && ISSPACE(*q))
|
||||
q++;
|
||||
if (*q)
|
||||
txtalias = q;
|
||||
}
|
||||
|
||||
/* Null terminate host name. */
|
||||
*p = '\0';
|
||||
|
||||
/* find out number of aliases. */
|
||||
naliases = 0;
|
||||
if (txtalias)
|
||||
{
|
||||
p = txtalias;
|
||||
while (*p)
|
||||
{
|
||||
while (*p && !ISSPACE(*p))
|
||||
p++;
|
||||
while (*p && ISSPACE(*p))
|
||||
p++;
|
||||
naliases++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Convert address string to network address for the requested family. */
|
||||
addrlen = 0;
|
||||
addr.family = AF_UNSPEC;
|
||||
addr.addrV4.s_addr = INADDR_NONE;
|
||||
if ((family == AF_INET) || (family == AF_UNSPEC))
|
||||
{
|
||||
addr.addrV4.s_addr = inet_addr(txtaddr);
|
||||
if (addr.addrV4.s_addr != INADDR_NONE)
|
||||
{
|
||||
/* Actual network address family and length. */
|
||||
addr.family = AF_INET;
|
||||
addrlen = sizeof(addr.addrV4);
|
||||
}
|
||||
}
|
||||
if ((family == AF_INET6) || ((family == AF_UNSPEC) && (!addrlen)))
|
||||
{
|
||||
if (ares_inet_pton(AF_INET6, txtaddr, &addr.addrV6) > 0)
|
||||
{
|
||||
/* Actual network address family and length. */
|
||||
addr.family = AF_INET6;
|
||||
addrlen = sizeof(addr.addrV6);
|
||||
}
|
||||
}
|
||||
if (!addrlen)
|
||||
/* Ignore line if invalid address string for the requested family. */
|
||||
continue;
|
||||
|
||||
/*
|
||||
** Actual address family possible values are AF_INET and AF_INET6 only.
|
||||
*/
|
||||
|
||||
/* Allocate memory for the hostent structure. */
|
||||
hostent = malloc(sizeof(struct hostent));
|
||||
if (!hostent)
|
||||
break;
|
||||
|
||||
/* Initialize fields for out of memory condition. */
|
||||
hostent->h_aliases = NULL;
|
||||
hostent->h_addr_list = NULL;
|
||||
|
||||
/* Copy official host name. */
|
||||
hostent->h_name = strdup(txthost);
|
||||
if (!hostent->h_name)
|
||||
break;
|
||||
|
||||
/* Copy network address. */
|
||||
hostent->h_addr_list = malloc(2 * sizeof(char *));
|
||||
if (!hostent->h_addr_list)
|
||||
break;
|
||||
hostent->h_addr_list[1] = NULL;
|
||||
hostent->h_addr_list[0] = malloc(addrlen);
|
||||
if (!hostent->h_addr_list[0])
|
||||
break;
|
||||
if (addr.family == AF_INET)
|
||||
memcpy(hostent->h_addr_list[0], &addr.addrV4, sizeof(addr.addrV4));
|
||||
else
|
||||
memcpy(hostent->h_addr_list[0], &addr.addrV6, sizeof(addr.addrV6));
|
||||
|
||||
/* Copy aliases. */
|
||||
hostent->h_aliases = malloc((naliases + 1) * sizeof(char *));
|
||||
if (!hostent->h_aliases)
|
||||
break;
|
||||
alias = hostent->h_aliases;
|
||||
while (naliases)
|
||||
*(alias + naliases--) = NULL;
|
||||
*alias = NULL;
|
||||
while (txtalias)
|
||||
{
|
||||
p = txtalias;
|
||||
while (*p && !ISSPACE(*p))
|
||||
p++;
|
||||
q = p;
|
||||
while (*q && ISSPACE(*q))
|
||||
q++;
|
||||
*p = '\0';
|
||||
if ((*alias = strdup(txtalias)) == NULL)
|
||||
break;
|
||||
alias++;
|
||||
txtalias = *q ? q : NULL;
|
||||
}
|
||||
if (txtalias)
|
||||
/* Alias memory allocation failure. */
|
||||
break;
|
||||
|
||||
/* Copy actual network address family and length. */
|
||||
hostent->h_addrtype = addr.family;
|
||||
hostent->h_length = (int)addrlen;
|
||||
|
||||
/* Free line buffer. */
|
||||
free(line);
|
||||
|
||||
/* Return hostent successfully */
|
||||
*host = hostent;
|
||||
return ARES_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
/* If allocated, free line buffer. */
|
||||
if (line)
|
||||
free(line);
|
||||
|
||||
if (status == ARES_SUCCESS)
|
||||
{
|
||||
/* Memory allocation failure; clean up. */
|
||||
if (hostent)
|
||||
{
|
||||
if (hostent->h_name)
|
||||
free((char *) hostent->h_name);
|
||||
if (hostent->h_aliases)
|
||||
{
|
||||
for (alias = hostent->h_aliases; *alias; alias++)
|
||||
free(*alias);
|
||||
free(hostent->h_aliases);
|
||||
}
|
||||
if (hostent->h_addr_list)
|
||||
{
|
||||
if (hostent->h_addr_list[0])
|
||||
free(hostent->h_addr_list[0]);
|
||||
free(hostent->h_addr_list);
|
||||
}
|
||||
free(hostent);
|
||||
}
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "ares.h"
|
||||
#include "ares_nowarn.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
/* This is an internal function. Its contract is to read a line from
|
||||
* a file into a dynamically allocated buffer, zeroing the trailing
|
||||
* newline if there is one. The calling routine may call
|
||||
* ares__read_line multiple times with the same buf and bufsize
|
||||
* pointers; *buf will be reallocated and *bufsize adjusted as
|
||||
* appropriate. The initial value of *buf should be NULL. After the
|
||||
* calling routine is done reading lines, it should free *buf.
|
||||
*/
|
||||
int ares__read_line(FILE *fp, char **buf, size_t *bufsize)
|
||||
{
|
||||
char *newbuf;
|
||||
size_t offset = 0;
|
||||
size_t len;
|
||||
|
||||
if (*buf == NULL)
|
||||
{
|
||||
*buf = malloc(128);
|
||||
if (!*buf)
|
||||
return ARES_ENOMEM;
|
||||
*bufsize = 128;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int bytestoread = aresx_uztosi(*bufsize - offset);
|
||||
|
||||
if (!fgets(*buf + offset, bytestoread, fp))
|
||||
return (offset != 0) ? 0 : (ferror(fp)) ? ARES_EFILE : ARES_EOF;
|
||||
len = offset + strlen(*buf + offset);
|
||||
if ((*buf)[len - 1] == '\n')
|
||||
{
|
||||
(*buf)[len - 1] = 0;
|
||||
break;
|
||||
}
|
||||
offset = len;
|
||||
if(len < *bufsize - 1)
|
||||
continue;
|
||||
|
||||
/* Allocate more space. */
|
||||
newbuf = realloc(*buf, *bufsize * 2);
|
||||
if (!newbuf)
|
||||
return ARES_ENOMEM;
|
||||
*buf = newbuf;
|
||||
*bufsize *= 2;
|
||||
}
|
||||
return ARES_SUCCESS;
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 2008 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
|
||||
* 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"
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
#if defined(WIN32) && !defined(MSDOS)
|
||||
|
||||
struct timeval ares__tvnow(void)
|
||||
{
|
||||
/*
|
||||
** GetTickCount() is available on _all_ Windows versions from W95 up
|
||||
** to nowadays. Returns milliseconds elapsed since last system boot,
|
||||
** increases monotonically and wraps once 49.7 days have elapsed.
|
||||
*/
|
||||
struct timeval now;
|
||||
DWORD milliseconds = GetTickCount();
|
||||
now.tv_sec = milliseconds / 1000;
|
||||
now.tv_usec = (milliseconds % 1000) * 1000;
|
||||
return now;
|
||||
}
|
||||
|
||||
#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
|
||||
|
||||
struct timeval ares__tvnow(void)
|
||||
{
|
||||
/*
|
||||
** clock_gettime() is granted to be increased monotonically when the
|
||||
** monotonic clock is queried. Time starting point is unspecified, it
|
||||
** could be the system start-up time, the Epoch, or something else,
|
||||
** in any case the time starting point does not change once that the
|
||||
** system has started up.
|
||||
*/
|
||||
struct timeval now;
|
||||
struct timespec tsnow;
|
||||
if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) {
|
||||
now.tv_sec = tsnow.tv_sec;
|
||||
now.tv_usec = tsnow.tv_nsec / 1000;
|
||||
}
|
||||
/*
|
||||
** Even when the configure process has truly detected monotonic clock
|
||||
** availability, it might happen that it is not actually available at
|
||||
** run-time. When this occurs simply fallback to other time source.
|
||||
*/
|
||||
#ifdef HAVE_GETTIMEOFDAY
|
||||
else
|
||||
(void)gettimeofday(&now, NULL);
|
||||
#else
|
||||
else {
|
||||
now.tv_sec = (long)time(NULL);
|
||||
now.tv_usec = 0;
|
||||
}
|
||||
#endif
|
||||
return now;
|
||||
}
|
||||
|
||||
#elif defined(HAVE_GETTIMEOFDAY)
|
||||
|
||||
struct timeval ares__tvnow(void)
|
||||
{
|
||||
/*
|
||||
** gettimeofday() is not granted to be increased monotonically, due to
|
||||
** clock drifting and external source time synchronization it can jump
|
||||
** forward or backward in time.
|
||||
*/
|
||||
struct timeval now;
|
||||
(void)gettimeofday(&now, NULL);
|
||||
return now;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
struct timeval ares__tvnow(void)
|
||||
{
|
||||
/*
|
||||
** time() returns the value of time in seconds since the Epoch.
|
||||
*/
|
||||
struct timeval now;
|
||||
now.tv_sec = (long)time(NULL);
|
||||
now.tv_usec = 0;
|
||||
return now;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if 0 /* Not used */
|
||||
/*
|
||||
* Make sure that the first argument is the more recent time, as otherwise
|
||||
* we'll get a weird negative time-diff back...
|
||||
*
|
||||
* Returns: the time difference in number of milliseconds.
|
||||
*/
|
||||
long ares__tvdiff(struct timeval newer, struct timeval older)
|
||||
{
|
||||
return (newer.tv_sec-older.tv_sec)*1000+
|
||||
(newer.tv_usec-older.tv_usec)/1000;
|
||||
}
|
||||
#endif
|
||||
|
@ -1,253 +0,0 @@
|
||||
#ifndef __CARES_BUILD_H
|
||||
#define __CARES_BUILD_H
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 2009 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ================================================================ */
|
||||
/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */
|
||||
/* ================================================================ */
|
||||
|
||||
/*
|
||||
* NOTE 1:
|
||||
* -------
|
||||
*
|
||||
* See file ares_build.h.in, run configure, and forget that this file
|
||||
* exists it is only used for non-configure systems.
|
||||
* But you can keep reading if you want ;-)
|
||||
*
|
||||
*/
|
||||
|
||||
/* ================================================================ */
|
||||
/* NOTES FOR NON-CONFIGURE SYSTEMS */
|
||||
/* ================================================================ */
|
||||
|
||||
/*
|
||||
* NOTE 1:
|
||||
* -------
|
||||
*
|
||||
* Nothing in this file is intended to be modified or adjusted by the
|
||||
* c-ares library user nor by the c-ares library builder.
|
||||
*
|
||||
* If you think that something actually needs to be changed, adjusted
|
||||
* or fixed in this file, then, report it on the c-ares development
|
||||
* mailing list: http://cool.haxx.se/mailman/listinfo/c-ares/
|
||||
*
|
||||
* Try to keep one section per platform, compiler and architecture,
|
||||
* otherwise, if an existing section is reused for a different one and
|
||||
* later on the original is adjusted, probably the piggybacking one can
|
||||
* be adversely changed.
|
||||
*
|
||||
* In order to differentiate between platforms/compilers/architectures
|
||||
* use only compiler built in predefined preprocessor symbols.
|
||||
*
|
||||
* This header file shall only export symbols which are 'cares' or 'CARES'
|
||||
* prefixed, otherwise public name space would be polluted.
|
||||
*
|
||||
* NOTE 2:
|
||||
* -------
|
||||
*
|
||||
* Right now you might be staring at file ares_build.h.dist or ares_build.h,
|
||||
* this is due to the following reason: file ares_build.h.dist is renamed
|
||||
* to ares_build.h when the c-ares source code distribution archive file is
|
||||
* created.
|
||||
*
|
||||
* File ares_build.h.dist is not included in the distribution archive.
|
||||
* File ares_build.h is not present in the CVS tree.
|
||||
*
|
||||
* The distributed ares_build.h file is only intended to be used on systems
|
||||
* which can not run the also distributed configure script.
|
||||
*
|
||||
* On systems capable of running the configure script, the configure process
|
||||
* will overwrite the distributed ares_build.h file with one that is suitable
|
||||
* and specific to the library being configured and built, which is generated
|
||||
* from the ares_build.h.in template file.
|
||||
*
|
||||
* If you check out from CVS on a non-configure platform, you must run the
|
||||
* appropriate buildconf* script to set up ares_build.h and other local files.
|
||||
*
|
||||
*/
|
||||
|
||||
/* ================================================================ */
|
||||
/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */
|
||||
/* ================================================================ */
|
||||
|
||||
#ifdef CARES_SIZEOF_LONG
|
||||
# error "CARES_SIZEOF_LONG shall not be defined except in ares_build.h"
|
||||
Error Compilation_aborted_CARES_SIZEOF_LONG_already_defined
|
||||
#endif
|
||||
|
||||
#ifdef CARES_TYPEOF_ARES_SOCKLEN_T
|
||||
# error "CARES_TYPEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
|
||||
Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_already_defined
|
||||
#endif
|
||||
|
||||
#ifdef CARES_SIZEOF_ARES_SOCKLEN_T
|
||||
# error "CARES_SIZEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
|
||||
Error Compilation_aborted_CARES_SIZEOF_ARES_SOCKLEN_T_already_defined
|
||||
#endif
|
||||
|
||||
/* ================================================================ */
|
||||
/* EXTERNAL INTERFACE SETTINGS FOR NON-CONFIGURE SYSTEMS ONLY */
|
||||
/* ================================================================ */
|
||||
|
||||
#if defined(__DJGPP__) || defined(__GO32__)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
#elif defined(__SALFORDC__)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
#elif defined(__BORLANDC__)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
#elif defined(__TURBOC__)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
#elif defined(__WATCOMC__)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
#elif defined(__POCC__)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
#elif defined(__LCC__)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
#elif defined(__SYMBIAN32__)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T unsigned int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
#elif defined(__MWERKS__)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
#elif defined(_WIN32_WCE)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
#elif defined(__MINGW32__)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
#elif defined(__VMS)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T unsigned int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
#elif defined(__OS400__)
|
||||
# if defined(__ILEC400__)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
# define CARES_PULL_SYS_TYPES_H 1
|
||||
# define CARES_PULL_SYS_SOCKET_H 1
|
||||
# endif
|
||||
|
||||
#elif defined(__MVS__)
|
||||
# if defined(__IBMC__) || defined(__IBMCPP__)
|
||||
# if defined(_ILP32)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# elif defined(_LP64)
|
||||
# define CARES_SIZEOF_LONG 8
|
||||
# endif
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
# define CARES_PULL_SYS_TYPES_H 1
|
||||
# define CARES_PULL_SYS_SOCKET_H 1
|
||||
# endif
|
||||
|
||||
#elif defined(__370__)
|
||||
# if defined(__IBMC__) || defined(__IBMCPP__)
|
||||
# if defined(_ILP32)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# elif defined(_LP64)
|
||||
# define CARES_SIZEOF_LONG 8
|
||||
# endif
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
# define CARES_PULL_SYS_TYPES_H 1
|
||||
# define CARES_PULL_SYS_SOCKET_H 1
|
||||
# endif
|
||||
|
||||
#elif defined(TPF)
|
||||
# define CARES_SIZEOF_LONG 8
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
/* ===================================== */
|
||||
/* KEEP MSVC THE PENULTIMATE ENTRY */
|
||||
/* ===================================== */
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
|
||||
/* ===================================== */
|
||||
/* KEEP GENERIC GCC THE LAST ENTRY */
|
||||
/* ===================================== */
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
# if defined(__i386__) || defined(__ppc__)
|
||||
# define CARES_SIZEOF_LONG 4
|
||||
# elif defined(__x86_64__) || defined(__ppc64__)
|
||||
# define CARES_SIZEOF_LONG 8
|
||||
# endif
|
||||
# define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t
|
||||
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
||||
# define CARES_PULL_SYS_TYPES_H 1
|
||||
# define CARES_PULL_SYS_SOCKET_H 1
|
||||
|
||||
#else
|
||||
# error "Unknown non-configure build target!"
|
||||
Error Compilation_aborted_Unknown_non_configure_build_target
|
||||
#endif
|
||||
|
||||
/* CARES_PULL_SYS_TYPES_H is defined above when inclusion of header file */
|
||||
/* sys/types.h is required here to properly make type definitions below. */
|
||||
#ifdef CARES_PULL_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/* CARES_PULL_SYS_SOCKET_H is defined above when inclusion of header file */
|
||||
/* sys/socket.h is required here to properly make type definitions below. */
|
||||
#ifdef CARES_PULL_SYS_SOCKET_H
|
||||
# include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
/* Data type definition of ares_socklen_t. */
|
||||
|
||||
#ifdef CARES_TYPEOF_ARES_SOCKLEN_T
|
||||
typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;
|
||||
#endif
|
||||
|
||||
#endif /* __CARES_BUILD_H */
|
@ -1,111 +0,0 @@
|
||||
#ifndef __CARES_BUILD_H
|
||||
#define __CARES_BUILD_H
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 2009 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ================================================================ */
|
||||
/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */
|
||||
/* ================================================================ */
|
||||
|
||||
/*
|
||||
* NOTE 1:
|
||||
* -------
|
||||
*
|
||||
* Nothing in this file is intended to be modified or adjusted by the
|
||||
* c-ares library user nor by the c-ares library builder.
|
||||
*
|
||||
* If you think that something actually needs to be changed, adjusted
|
||||
* or fixed in this file, then, report it on the c-ares development
|
||||
* mailing list: http://cool.haxx.se/mailman/listinfo/c-ares/
|
||||
*
|
||||
* This header file shall only export symbols which are 'cares' or 'CARES'
|
||||
* prefixed, otherwise public name space would be polluted.
|
||||
*
|
||||
* NOTE 2:
|
||||
* -------
|
||||
*
|
||||
* Right now you might be staring at file ares_build.h.in or ares_build.h,
|
||||
* this is due to the following reason:
|
||||
*
|
||||
* On systems capable of running the configure script, the configure process
|
||||
* will overwrite the distributed ares_build.h file with one that is suitable
|
||||
* and specific to the library being configured and built, which is generated
|
||||
* from the ares_build.h.in template file.
|
||||
*
|
||||
*/
|
||||
|
||||
/* ================================================================ */
|
||||
/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */
|
||||
/* ================================================================ */
|
||||
|
||||
#ifdef CARES_SIZEOF_LONG
|
||||
# error "CARES_SIZEOF_LONG shall not be defined except in ares_build.h"
|
||||
Error Compilation_aborted_CARES_SIZEOF_LONG_already_defined
|
||||
#endif
|
||||
|
||||
#ifdef CARES_TYPEOF_ARES_SOCKLEN_T
|
||||
# error "CARES_TYPEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
|
||||
Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_already_defined
|
||||
#endif
|
||||
|
||||
#ifdef CARES_SIZEOF_ARES_SOCKLEN_T
|
||||
# error "CARES_SIZEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
|
||||
Error Compilation_aborted_CARES_SIZEOF_ARES_SOCKLEN_T_already_defined
|
||||
#endif
|
||||
|
||||
/* ================================================================ */
|
||||
/* EXTERNAL INTERFACE SETTINGS FOR CONFIGURE CAPABLE SYSTEMS ONLY */
|
||||
/* ================================================================ */
|
||||
|
||||
/* 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
|
||||
#ifdef CARES_PULL_WS2TCPIP_H
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
/* Configure process defines this to 1 when it finds out that system */
|
||||
/* header file sys/types.h must be included by the external interface. */
|
||||
#undef CARES_PULL_SYS_TYPES_H
|
||||
#ifdef CARES_PULL_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/* Configure process defines this to 1 when it finds out that system */
|
||||
/* header file sys/socket.h must be included by the external interface. */
|
||||
#undef CARES_PULL_SYS_SOCKET_H
|
||||
#ifdef CARES_PULL_SYS_SOCKET_H
|
||||
# include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
/* The size of `long', as computed by sizeof. */
|
||||
#undef CARES_SIZEOF_LONG
|
||||
|
||||
/* Integral data type used for ares_socklen_t. */
|
||||
#undef CARES_TYPEOF_ARES_SOCKLEN_T
|
||||
|
||||
/* The size of `ares_socklen_t', as computed by sizeof. */
|
||||
#undef CARES_SIZEOF_ARES_SOCKLEN_T
|
||||
|
||||
/* Data type definition of ares_socklen_t. */
|
||||
typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;
|
||||
|
||||
#endif /* __CARES_BUILD_H */
|
@ -1,44 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_CANCEL 3 "31 March 2004"
|
||||
.SH NAME
|
||||
ares_cancel \- Cancel a resolve
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B void ares_cancel(ares_channel \fIchannel\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The \fBares_cancel\fP function cancels all lookups/requests made on the the
|
||||
name service channel identified by \fIchannel\fP. \fBares_cancel\fP invokes
|
||||
the callbacks for each pending query on the channel, passing a status of
|
||||
.BR ARES_ECANCELLED .
|
||||
These calls give the callbacks a chance to clean up any state which
|
||||
might have been stored in their arguments.
|
||||
.SH SEE ALSO
|
||||
.BR ares_init (3)
|
||||
.BR ares_destroy (3)
|
||||
.SH NOTES
|
||||
This function was added in c-ares 1.2.0
|
||||
|
||||
c-ares 1.6.0 and earlier pass a status of
|
||||
.BR ARES_ETIMEOUT
|
||||
instead of
|
||||
.BR ARES_ECANCELLED .
|
||||
.SH AUTHOR
|
||||
Dirk Manske
|
@ -1,64 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 2004 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
|
||||
* 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"
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
/*
|
||||
* ares_cancel() cancels all ongoing requests/resolves that might be going on
|
||||
* on the given channel. It does NOT kill the channel, use ares_destroy() for
|
||||
* that.
|
||||
*/
|
||||
void ares_cancel(ares_channel channel)
|
||||
{
|
||||
struct query *query;
|
||||
struct list_node* list_head;
|
||||
struct list_node* list_node;
|
||||
int i;
|
||||
|
||||
list_head = &(channel->all_queries);
|
||||
for (list_node = list_head->next; list_node != list_head; )
|
||||
{
|
||||
query = list_node->data;
|
||||
list_node = list_node->next; /* since we're deleting the query */
|
||||
query->callback(query->arg, ARES_ECANCELLED, 0, NULL, 0);
|
||||
ares__free_query(query);
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
/* Freeing the query should remove it from all the lists in which it sits,
|
||||
* so all query lists should be empty now.
|
||||
*/
|
||||
assert(ares__is_list_empty(&(channel->all_queries)));
|
||||
for (i = 0; i < ARES_QID_TABLE_SIZE; i++)
|
||||
{
|
||||
assert(ares__is_list_empty(&(channel->queries_by_qid[i])));
|
||||
}
|
||||
for (i = 0; i < ARES_TIMEOUT_TABLE_SIZE; i++)
|
||||
{
|
||||
assert(ares__is_list_empty(&(channel->queries_by_timeout[i])));
|
||||
}
|
||||
#endif
|
||||
if (!(channel->flags & ARES_FLAG_STAYOPEN))
|
||||
{
|
||||
if (channel->servers)
|
||||
{
|
||||
for (i = 0; i < channel->nservers; i++)
|
||||
ares__close_sockets(channel, &channel->servers[i]);
|
||||
}
|
||||
}
|
||||
}
|
176
ares/ares_data.c
176
ares/ares_data.c
@ -1,176 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 2009-2010 by Daniel Stenberg
|
||||
*
|
||||
* 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"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_data.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
|
||||
/*
|
||||
** ares_free_data() - c-ares external API function.
|
||||
**
|
||||
** This function must be used by the application to free data memory that
|
||||
** has been internally allocated by some c-ares function and for which a
|
||||
** pointer has already been returned to the calling application. The list
|
||||
** of c-ares functions returning pointers that must be free'ed using this
|
||||
** function is:
|
||||
**
|
||||
** ares_get_servers()
|
||||
** ares_parse_srv_reply()
|
||||
** ares_parse_txt_reply()
|
||||
*/
|
||||
|
||||
void ares_free_data(void *dataptr)
|
||||
{
|
||||
struct ares_data *ptr;
|
||||
|
||||
if (!dataptr)
|
||||
return;
|
||||
|
||||
#ifdef __INTEL_COMPILER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:1684)
|
||||
/* 1684: conversion from pointer to same-sized integral type */
|
||||
#endif
|
||||
|
||||
ptr = (void *)((char *)dataptr - offsetof(struct ares_data, data));
|
||||
|
||||
#ifdef __INTEL_COMPILER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
if (ptr->mark != ARES_DATATYPE_MARK)
|
||||
return;
|
||||
|
||||
switch (ptr->type)
|
||||
{
|
||||
case ARES_DATATYPE_SRV_REPLY:
|
||||
|
||||
if (ptr->data.srv_reply.next)
|
||||
ares_free_data(ptr->data.srv_reply.next);
|
||||
if (ptr->data.srv_reply.host)
|
||||
free(ptr->data.srv_reply.host);
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_TXT_REPLY:
|
||||
|
||||
if (ptr->data.txt_reply.next)
|
||||
ares_free_data(ptr->data.txt_reply.next);
|
||||
if (ptr->data.txt_reply.txt)
|
||||
free(ptr->data.txt_reply.txt);
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_ADDR_NODE:
|
||||
|
||||
if (ptr->data.addr_node.next)
|
||||
ares_free_data(ptr->data.addr_node.next);
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** ares_malloc_data() - c-ares internal helper function.
|
||||
**
|
||||
** This function allocates memory for a c-ares private ares_data struct
|
||||
** for the specified ares_datatype, initializes c-ares private fields
|
||||
** and zero initializes those which later might be used from the public
|
||||
** API. It returns an interior pointer which can be passed by c-ares
|
||||
** functions to the calling application, and that must be free'ed using
|
||||
** c-ares external API function ares_free_data().
|
||||
*/
|
||||
|
||||
void *ares_malloc_data(ares_datatype type)
|
||||
{
|
||||
struct ares_data *ptr;
|
||||
|
||||
ptr = malloc(sizeof(struct ares_data));
|
||||
if (!ptr)
|
||||
return NULL;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ARES_DATATYPE_SRV_REPLY:
|
||||
ptr->data.srv_reply.next = NULL;
|
||||
ptr->data.srv_reply.host = NULL;
|
||||
ptr->data.srv_reply.priority = 0;
|
||||
ptr->data.srv_reply.weight = 0;
|
||||
ptr->data.srv_reply.port = 0;
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_TXT_REPLY:
|
||||
ptr->data.txt_reply.next = NULL;
|
||||
ptr->data.txt_reply.txt = NULL;
|
||||
ptr->data.txt_reply.length = 0;
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_ADDR_NODE:
|
||||
ptr->data.addr_node.next = NULL;
|
||||
ptr->data.addr_node.family = 0;
|
||||
memset(&ptr->data.addr_node.addrV6, 0,
|
||||
sizeof(ptr->data.addr_node.addrV6));
|
||||
|
||||
default:
|
||||
free(ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr->mark = ARES_DATATYPE_MARK;
|
||||
ptr->type = type;
|
||||
|
||||
return &ptr->data;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** ares_get_datatype() - c-ares internal helper function.
|
||||
**
|
||||
** This function returns the ares_datatype of the data stored in a
|
||||
** private ares_data struct when given the public API pointer.
|
||||
*/
|
||||
|
||||
ares_datatype ares_get_datatype(void * dataptr)
|
||||
{
|
||||
struct ares_data *ptr;
|
||||
|
||||
#ifdef __INTEL_COMPILER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:1684)
|
||||
/* 1684: conversion from pointer to same-sized integral type */
|
||||
#endif
|
||||
|
||||
ptr = (void *)((char *)dataptr - offsetof(struct ares_data, data));
|
||||
|
||||
#ifdef __INTEL_COMPILER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
if (ptr->mark == ARES_DATATYPE_MARK)
|
||||
return ptr->type;
|
||||
|
||||
return ARES_DATATYPE_UNKNOWN;
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 2009-2010 by Daniel Stenberg
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
ARES_DATATYPE_UNKNOWN = 1, /* unknown data type - introduced in 1.7.0 */
|
||||
ARES_DATATYPE_SRV_REPLY, /* struct ares_srv_reply - introduced in 1.7.0 */
|
||||
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 */
|
||||
#if 0
|
||||
ARES_DATATYPE_ADDR6TTL, /* struct ares_addrttl */
|
||||
ARES_DATATYPE_ADDRTTL, /* struct ares_addr6ttl */
|
||||
ARES_DATATYPE_HOSTENT, /* struct hostent */
|
||||
ARES_DATATYPE_OPTIONS, /* struct ares_options */
|
||||
#endif
|
||||
ARES_DATATYPE_LAST /* not used - introduced in 1.7.0 */
|
||||
} ares_datatype;
|
||||
|
||||
#define ARES_DATATYPE_MARK 0xbead
|
||||
|
||||
/*
|
||||
* ares_data struct definition is internal to c-ares and shall not
|
||||
* be exposed by the public API in order to allow future changes
|
||||
* and extensions to it without breaking ABI. This will be used
|
||||
* internally by c-ares as the container of multiple types of data
|
||||
* dynamically allocated for which a reference will be returned
|
||||
* to the calling application.
|
||||
*
|
||||
* c-ares API functions returning a pointer to c-ares internally
|
||||
* allocated data will actually be returning an interior pointer
|
||||
* into this ares_data struct.
|
||||
*
|
||||
* All this is 'invisible' to the calling application, the only
|
||||
* requirement is that this kind of data must be free'ed by the
|
||||
* calling application using ares_free_data() with the pointer
|
||||
* it has received from a previous c-ares function call.
|
||||
*/
|
||||
|
||||
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;
|
||||
} data;
|
||||
};
|
||||
|
||||
void *ares_malloc_data(ares_datatype type);
|
||||
|
||||
ares_datatype ares_get_datatype(void * dataptr);
|
@ -1,44 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_DESTROY 3 "7 December 2004"
|
||||
.SH NAME
|
||||
ares_destroy \- Destroy a resolver channel
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B void ares_destroy(ares_channel \fIchannel\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_destroy
|
||||
function destroys the name service channel identified by
|
||||
.IR channel ,
|
||||
freeing all memory and closing all sockets used by the channel.
|
||||
.B ares_destroy
|
||||
invokes the callbacks for each pending query on the channel, passing a
|
||||
status of
|
||||
.BR ARES_EDESTRUCTION .
|
||||
These calls give the callbacks a chance to clean up any state which
|
||||
might have been stored in their arguments.
|
||||
.SH SEE ALSO
|
||||
.BR ares_init (3),
|
||||
.BR ares_cancel (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
@ -1,106 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
* Copyright (C) 2004-2010 by Daniel Stenberg
|
||||
*
|
||||
* 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"
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
void ares_destroy_options(struct ares_options *options)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(options->servers)
|
||||
free(options->servers);
|
||||
for (i = 0; i < options->ndomains; i++)
|
||||
free(options->domains[i]);
|
||||
free(options->domains);
|
||||
if(options->sortlist)
|
||||
free(options->sortlist);
|
||||
free(options->lookups);
|
||||
}
|
||||
|
||||
void ares_destroy(ares_channel channel)
|
||||
{
|
||||
int i;
|
||||
struct query *query;
|
||||
struct list_node* list_head;
|
||||
struct list_node* list_node;
|
||||
|
||||
if (!channel)
|
||||
return;
|
||||
|
||||
list_head = &(channel->all_queries);
|
||||
for (list_node = list_head->next; list_node != list_head; )
|
||||
{
|
||||
query = list_node->data;
|
||||
list_node = list_node->next; /* since we're deleting the query */
|
||||
query->callback(query->arg, ARES_EDESTRUCTION, 0, NULL, 0);
|
||||
ares__free_query(query);
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
/* Freeing the query should remove it from all the lists in which it sits,
|
||||
* so all query lists should be empty now.
|
||||
*/
|
||||
assert(ares__is_list_empty(&(channel->all_queries)));
|
||||
for (i = 0; i < ARES_QID_TABLE_SIZE; i++)
|
||||
{
|
||||
assert(ares__is_list_empty(&(channel->queries_by_qid[i])));
|
||||
}
|
||||
for (i = 0; i < ARES_TIMEOUT_TABLE_SIZE; i++)
|
||||
{
|
||||
assert(ares__is_list_empty(&(channel->queries_by_timeout[i])));
|
||||
}
|
||||
#endif
|
||||
|
||||
ares__destroy_servers_state(channel);
|
||||
|
||||
if (channel->domains) {
|
||||
for (i = 0; i < channel->ndomains; i++)
|
||||
free(channel->domains[i]);
|
||||
free(channel->domains);
|
||||
}
|
||||
|
||||
if(channel->sortlist)
|
||||
free(channel->sortlist);
|
||||
|
||||
if (channel->lookups)
|
||||
free(channel->lookups);
|
||||
|
||||
free(channel);
|
||||
}
|
||||
|
||||
void ares__destroy_servers_state(ares_channel channel)
|
||||
{
|
||||
struct server_state *server;
|
||||
int i;
|
||||
|
||||
if (channel->servers)
|
||||
{
|
||||
for (i = 0; i < channel->nservers; i++)
|
||||
{
|
||||
server = &channel->servers[i];
|
||||
ares__close_sockets(channel, server);
|
||||
assert(ares__is_list_empty(&server->queries_to_server));
|
||||
}
|
||||
free(channel->servers);
|
||||
channel->servers = NULL;
|
||||
}
|
||||
channel->nservers = -1;
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_DESTROY_OPTIONS 3 "1 June 2007"
|
||||
.SH NAME
|
||||
ares_destroy_options \- Destroy options initialized with ares_save_options
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B void ares_destroy_options(struct ares_options *\fIoptions\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_destroy_options
|
||||
function destroys the options struct identified by
|
||||
.IR options ,
|
||||
freeing all memory allocated by ares_save_options.
|
||||
|
||||
.SH SEE ALSO
|
||||
.BR ares_save_options (3),
|
||||
.BR ares_init_options (3)
|
||||
.SH AUTHOR
|
||||
Brad House
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
@ -1,91 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ARES__DNS_H
|
||||
#define ARES__DNS_H
|
||||
|
||||
#define DNS__16BIT(p) (((p)[0] << 8) | (p)[1])
|
||||
#define DNS__32BIT(p) (((p)[0] << 24) | ((p)[1] << 16) | \
|
||||
((p)[2] << 8) | (p)[3])
|
||||
|
||||
#define DNS__SET16BIT(p, v) (((p)[0] = (unsigned char)(((v) >> 8) & 0xff)), \
|
||||
((p)[1] = (unsigned char)((v) & 0xff)))
|
||||
#define DNS__SET32BIT(p, v) (((p)[0] = (unsigned char)(((v) >> 24) & 0xff)), \
|
||||
((p)[1] = (unsigned char)(((v) >> 16) & 0xff)), \
|
||||
((p)[2] = (unsigned char)(((v) >> 8) & 0xff)), \
|
||||
((p)[3] = (unsigned char)((v) & 0xff)))
|
||||
|
||||
#if 0
|
||||
/* we cannot use this approach on systems where we can't access 16/32 bit
|
||||
data on un-aligned addresses */
|
||||
#define DNS__16BIT(p) ntohs(*(unsigned short*)(p))
|
||||
#define DNS__32BIT(p) ntohl(*(unsigned long*)(p))
|
||||
#define DNS__SET16BIT(p, v) *(unsigned short*)(p) = htons(v)
|
||||
#define DNS__SET32BIT(p, v) *(unsigned long*)(p) = htonl(v)
|
||||
#endif
|
||||
|
||||
/* Macros for parsing a DNS header */
|
||||
#define DNS_HEADER_QID(h) DNS__16BIT(h)
|
||||
#define DNS_HEADER_QR(h) (((h)[2] >> 7) & 0x1)
|
||||
#define DNS_HEADER_OPCODE(h) (((h)[2] >> 3) & 0xf)
|
||||
#define DNS_HEADER_AA(h) (((h)[2] >> 2) & 0x1)
|
||||
#define DNS_HEADER_TC(h) (((h)[2] >> 1) & 0x1)
|
||||
#define DNS_HEADER_RD(h) ((h)[2] & 0x1)
|
||||
#define DNS_HEADER_RA(h) (((h)[3] >> 7) & 0x1)
|
||||
#define DNS_HEADER_Z(h) (((h)[3] >> 4) & 0x7)
|
||||
#define DNS_HEADER_RCODE(h) ((h)[3] & 0xf)
|
||||
#define DNS_HEADER_QDCOUNT(h) DNS__16BIT((h) + 4)
|
||||
#define DNS_HEADER_ANCOUNT(h) DNS__16BIT((h) + 6)
|
||||
#define DNS_HEADER_NSCOUNT(h) DNS__16BIT((h) + 8)
|
||||
#define DNS_HEADER_ARCOUNT(h) DNS__16BIT((h) + 10)
|
||||
|
||||
/* Macros for constructing a DNS header */
|
||||
#define DNS_HEADER_SET_QID(h, v) DNS__SET16BIT(h, v)
|
||||
#define DNS_HEADER_SET_QR(h, v) ((h)[2] |= (unsigned char)(((v) & 0x1) << 7))
|
||||
#define DNS_HEADER_SET_OPCODE(h, v) ((h)[2] |= (unsigned char)(((v) & 0xf) << 3))
|
||||
#define DNS_HEADER_SET_AA(h, v) ((h)[2] |= (unsigned char)(((v) & 0x1) << 2))
|
||||
#define DNS_HEADER_SET_TC(h, v) ((h)[2] |= (unsigned char)(((v) & 0x1) << 1))
|
||||
#define DNS_HEADER_SET_RD(h, v) ((h)[2] |= (unsigned char)((v) & 0x1))
|
||||
#define DNS_HEADER_SET_RA(h, v) ((h)[3] |= (unsigned char)(((v) & 0x1) << 7))
|
||||
#define DNS_HEADER_SET_Z(h, v) ((h)[3] |= (unsigned char)(((v) & 0x7) << 4))
|
||||
#define DNS_HEADER_SET_RCODE(h, v) ((h)[3] |= (unsigned char)((v) & 0xf))
|
||||
#define DNS_HEADER_SET_QDCOUNT(h, v) DNS__SET16BIT((h) + 4, v)
|
||||
#define DNS_HEADER_SET_ANCOUNT(h, v) DNS__SET16BIT((h) + 6, v)
|
||||
#define DNS_HEADER_SET_NSCOUNT(h, v) DNS__SET16BIT((h) + 8, v)
|
||||
#define DNS_HEADER_SET_ARCOUNT(h, v) DNS__SET16BIT((h) + 10, v)
|
||||
|
||||
/* Macros for parsing the fixed part of a DNS question */
|
||||
#define DNS_QUESTION_TYPE(q) DNS__16BIT(q)
|
||||
#define DNS_QUESTION_CLASS(q) DNS__16BIT((q) + 2)
|
||||
|
||||
/* Macros for constructing the fixed part of a DNS question */
|
||||
#define DNS_QUESTION_SET_TYPE(q, v) DNS__SET16BIT(q, v)
|
||||
#define DNS_QUESTION_SET_CLASS(q, v) DNS__SET16BIT((q) + 2, v)
|
||||
|
||||
/* Macros for parsing the fixed part of a DNS resource record */
|
||||
#define DNS_RR_TYPE(r) DNS__16BIT(r)
|
||||
#define DNS_RR_CLASS(r) DNS__16BIT((r) + 2)
|
||||
#define DNS_RR_TTL(r) DNS__32BIT((r) + 4)
|
||||
#define DNS_RR_LEN(r) DNS__16BIT((r) + 8)
|
||||
|
||||
/* Macros for constructing the fixed part of a DNS resource record */
|
||||
#define DNS_RR_SET_TYPE(r) DNS__SET16BIT(r, v)
|
||||
#define DNS_RR_SET_CLASS(r) DNS__SET16BIT((r) + 2, v)
|
||||
#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 */
|
@ -1,44 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright (C) 2004-2009 by Daniel Stenberg
|
||||
.\"
|
||||
.\" 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_DUP 3 "26 May 2009"
|
||||
.SH NAME
|
||||
ares_dup \- Duplicate a resolver channel
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_dup(ares_channel *\fIdest\fP, ares_channel \fIsource\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The \fBares_dup(3)\fP function duplicates an existing communications channel
|
||||
for name service lookups. If it returns successfully, \fBares_dup(3)\fP will
|
||||
set the variable pointed to by \fIdest\fP to a handle used to identify the
|
||||
name service channel. The caller should invoke \fIares_destroy(3)\fP on the
|
||||
handle when the channel is no longer needed.
|
||||
|
||||
The \fBares_dup_options\fP function also initializes a name service channel,
|
||||
with additional options set exactly as the \fIsource\fP channel has them
|
||||
configured.
|
||||
.SH SEE ALSO
|
||||
.BR ares_destroy(3),
|
||||
.BR ares_init(3),
|
||||
.BR ares_library_init(3)
|
||||
.SH AVAILABILITY
|
||||
ares_dup(3) was added in c-ares 1.6.0
|
||||
.SH AUTHOR
|
||||
Daniel Stenberg
|
||||
|
@ -1,64 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_EXPAND_NAME 3 "20 Nov 2009"
|
||||
.SH NAME
|
||||
ares_expand_name \- Expand a DNS-encoded domain name
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_expand_name(const unsigned char *\fIencoded\fP,
|
||||
.B const unsigned char *\fIabuf\fP, int \fIalen\fP, char **\fIs\fP,
|
||||
.B long *\fIenclen\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_expand_name
|
||||
function converts a DNS-encoded domain name to a dot-separated C
|
||||
string. The argument
|
||||
.I encoded
|
||||
gives the beginning of the encoded domain name, and the arguments
|
||||
.I abuf
|
||||
and
|
||||
.I alen
|
||||
give the containing message buffer (necessary for the processing of
|
||||
indirection pointers within the encoded domain name). The result is
|
||||
placed in a NUL-terminated allocated buffer, a pointer to which is
|
||||
stored in the variable pointed to by
|
||||
.IR s .
|
||||
The length of the encoded name is stored in the variable pointed to by
|
||||
.I enclen
|
||||
so that the caller can advance past the encoded domain name to read
|
||||
further data in the message.
|
||||
.SH RETURN VALUES
|
||||
.B ares_expand_name
|
||||
can return any of the following values:
|
||||
.TP 15
|
||||
.B ARES_SUCCESS
|
||||
Expansion of the encoded name succeeded.
|
||||
.TP 15
|
||||
.B ARES_EBADNAME
|
||||
The encoded domain name was malformed and could not be expanded.
|
||||
.TP 15
|
||||
.B ARES_ENOMEM
|
||||
Memory was exhausted.
|
||||
.SH SEE ALSO
|
||||
.BR ares_mkquery (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
@ -1,194 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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_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 "ares.h"
|
||||
#include "ares_private.h" /* for the memdebug */
|
||||
|
||||
static int name_length(const unsigned char *encoded, const unsigned char *abuf,
|
||||
int alen);
|
||||
|
||||
/* Expand an RFC1035-encoded domain name given by encoded. The
|
||||
* containing message is given by abuf and alen. The result given by
|
||||
* *s, which is set to a NUL-terminated allocated buffer. *enclen is
|
||||
* set to the length of the encoded name (not the length of the
|
||||
* expanded name; the goal is to tell the caller how many bytes to
|
||||
* move forward to get past the encoded name).
|
||||
*
|
||||
* In the simple case, an encoded name is a series of labels, each
|
||||
* composed of a one-byte length (limited to values between 0 and 63
|
||||
* inclusive) followed by the label contents. The name is terminated
|
||||
* by a zero-length label.
|
||||
*
|
||||
* In the more complicated case, a label may be terminated by an
|
||||
* indirection pointer, specified by two bytes with the high bits of
|
||||
* the first byte (corresponding to INDIR_MASK) set to 11. With the
|
||||
* two high bits of the first byte stripped off, the indirection
|
||||
* pointer gives an offset from the beginning of the containing
|
||||
* message with more labels to decode. Indirection can happen an
|
||||
* arbitrary number of times, so we have to detect loops.
|
||||
*
|
||||
* Since the expanded name uses '.' as a label separator, we use
|
||||
* backslashes to escape periods or backslashes in the expanded name.
|
||||
*/
|
||||
|
||||
int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
|
||||
int alen, char **s, long *enclen)
|
||||
{
|
||||
int len, indir = 0;
|
||||
char *q;
|
||||
const unsigned char *p;
|
||||
union {
|
||||
ssize_t sig;
|
||||
size_t uns;
|
||||
} nlen;
|
||||
|
||||
nlen.sig = name_length(encoded, abuf, alen);
|
||||
if (nlen.sig < 0)
|
||||
return ARES_EBADNAME;
|
||||
|
||||
*s = malloc(nlen.uns + 1);
|
||||
if (!*s)
|
||||
return ARES_ENOMEM;
|
||||
q = *s;
|
||||
|
||||
if (nlen.uns == 0) {
|
||||
/* RFC2181 says this should be ".": the root of the DNS tree.
|
||||
* Since this function strips trailing dots though, it becomes ""
|
||||
*/
|
||||
q[0] = '\0';
|
||||
*enclen = 1; /* the caller should move one byte to get past this */
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
/* No error-checking necessary; it was all done by name_length(). */
|
||||
p = encoded;
|
||||
while (*p)
|
||||
{
|
||||
if ((*p & INDIR_MASK) == INDIR_MASK)
|
||||
{
|
||||
if (!indir)
|
||||
{
|
||||
*enclen = p + 2 - encoded;
|
||||
indir = 1;
|
||||
}
|
||||
p = abuf + ((*p & ~INDIR_MASK) << 8 | *(p + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
len = *p;
|
||||
p++;
|
||||
while (len--)
|
||||
{
|
||||
if (*p == '.' || *p == '\\')
|
||||
*q++ = '\\';
|
||||
*q++ = *p;
|
||||
p++;
|
||||
}
|
||||
*q++ = '.';
|
||||
}
|
||||
}
|
||||
if (!indir)
|
||||
*enclen = p + 1 - encoded;
|
||||
|
||||
/* Nuke the trailing period if we wrote one. */
|
||||
if (q > *s)
|
||||
*(q - 1) = 0;
|
||||
else
|
||||
*q = 0; /* zero terminate */
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
/* Return the length of the expansion of an encoded domain name, or
|
||||
* -1 if the encoding is invalid.
|
||||
*/
|
||||
static int name_length(const unsigned char *encoded, const unsigned char *abuf,
|
||||
int alen)
|
||||
{
|
||||
int n = 0, offset, indir = 0;
|
||||
|
||||
/* Allow the caller to pass us abuf + alen and have us check for it. */
|
||||
if (encoded == abuf + alen)
|
||||
return -1;
|
||||
|
||||
while (*encoded)
|
||||
{
|
||||
if ((*encoded & INDIR_MASK) == INDIR_MASK)
|
||||
{
|
||||
/* Check the offset and go there. */
|
||||
if (encoded + 1 >= abuf + alen)
|
||||
return -1;
|
||||
offset = (*encoded & ~INDIR_MASK) << 8 | *(encoded + 1);
|
||||
if (offset >= alen)
|
||||
return -1;
|
||||
encoded = abuf + offset;
|
||||
|
||||
/* If we've seen more indirects than the message length,
|
||||
* then there's a loop.
|
||||
*/
|
||||
if (++indir > alen)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = *encoded;
|
||||
if (encoded + offset + 1 >= abuf + alen)
|
||||
return -1;
|
||||
encoded++;
|
||||
while (offset--)
|
||||
{
|
||||
n += (*encoded == '.' || *encoded == '\\') ? 2 : 1;
|
||||
encoded++;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
/* If there were any labels at all, then the number of dots is one
|
||||
* less than the number of labels, so subtract one.
|
||||
*/
|
||||
return (n) ? n - 1 : n;
|
||||
}
|
||||
|
||||
/* Like ares_expand_name but returns EBADRESP in case of invalid input. */
|
||||
int ares__expand_name_for_response(const unsigned char *encoded,
|
||||
const unsigned char *abuf, int alen,
|
||||
char **s, long *enclen)
|
||||
{
|
||||
int status = ares_expand_name(encoded, abuf, alen, s, enclen);
|
||||
if (status == ARES_EBADNAME)
|
||||
status = ARES_EBADRESP;
|
||||
return status;
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_EXPAND_NAME 3 "20 Nov 2009"
|
||||
.SH NAME
|
||||
ares_expand_string \- Expand a length encoded string
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_expand_string(const unsigned char *\fIencoded\fP,
|
||||
.B const unsigned char *\fIabuf\fP, int \fIalen\fP, unsigned char **\fIs\fP,
|
||||
.B long *\fIenclen\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_expand_string
|
||||
function converts a length encoded string to a NUL-terminated C
|
||||
string. The argument
|
||||
.I encoded
|
||||
gives the beginning of the encoded string, and the arguments
|
||||
.I abuf
|
||||
and
|
||||
.I alen
|
||||
give the containing message buffer (necessary for the processing of
|
||||
indirection pointers within the encoded domain name). The result is
|
||||
placed in a NUL-terminated allocated buffer, a pointer to which is
|
||||
stored in the variable pointed to by
|
||||
.IR s .
|
||||
The length of the encoded string is stored in the variable pointed to by
|
||||
.I enclen
|
||||
so that the caller can advance past the encoded string to read
|
||||
further data in the message.
|
||||
.SH RETURN VALUES
|
||||
.B ares_expand_string
|
||||
can return any of the following values:
|
||||
.TP 15
|
||||
.B ARES_SUCCESS
|
||||
Expansion of the encoded string succeeded.
|
||||
.TP 15
|
||||
.B ARES_EBADSTR
|
||||
The encoded string was malformed and could not be expanded.
|
||||
.TP 15
|
||||
.B ARES_ENOMEM
|
||||
Memory was exhausted.
|
||||
.SH SEE ALSO
|
||||
.BR ares_free_string (3)
|
||||
.SH AUTHOR
|
||||
Dominick Meglio
|
@ -1,76 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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_ARPA_NAMESER_H
|
||||
# include <arpa/nameser.h>
|
||||
#else
|
||||
# include "nameser.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "ares.h"
|
||||
#include "ares_private.h" /* for the memdebug */
|
||||
|
||||
/* Simply decodes a length-encoded character string. The first byte of the
|
||||
* input is the length of the string to be returned and the bytes thereafter
|
||||
* are the characters of the string. The returned result will be NULL
|
||||
* terminated.
|
||||
*/
|
||||
int ares_expand_string(const unsigned char *encoded,
|
||||
const unsigned char *abuf,
|
||||
int alen,
|
||||
unsigned char **s,
|
||||
long *enclen)
|
||||
{
|
||||
unsigned char *q;
|
||||
union {
|
||||
ssize_t sig;
|
||||
size_t uns;
|
||||
} elen;
|
||||
|
||||
if (encoded == abuf+alen)
|
||||
return ARES_EBADSTR;
|
||||
|
||||
elen.uns = *encoded;
|
||||
if (encoded+elen.sig+1 > abuf+alen)
|
||||
return ARES_EBADSTR;
|
||||
|
||||
encoded++;
|
||||
|
||||
*s = malloc(elen.uns+1);
|
||||
if (*s == NULL)
|
||||
return ARES_ENOMEM;
|
||||
q = *s;
|
||||
strncpy((char *)q, (char *)encoded, elen.uns);
|
||||
q[elen.uns] = '\0';
|
||||
|
||||
*s = q;
|
||||
|
||||
*enclen = (long)(elen.sig+1);
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
@ -1,62 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_FDS 3 "23 July 1998"
|
||||
.SH NAME
|
||||
ares_fds \- Get file descriptors to select on for name service
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_fds(ares_channel \fIchannel\fP, fd_set *\fIread_fds\fP,
|
||||
.B fd_set *\fIwrite_fds\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_fds
|
||||
function retrieves the set of file descriptors which the calling
|
||||
application should select on for reading and writing for the
|
||||
processing of name service queries pending on the name service channel
|
||||
identified by
|
||||
.IR channel .
|
||||
File descriptors will be set in the file descriptor sets pointed to by
|
||||
.I read_fds
|
||||
and
|
||||
.I write_fds
|
||||
as appropriate. File descriptors already set in
|
||||
.I read_fds
|
||||
and
|
||||
.I write_fds
|
||||
will remain set; initialization of the file descriptor sets
|
||||
(using
|
||||
.BR FD_ZERO )
|
||||
is the responsibility of the caller.
|
||||
.SH RETURN VALUES
|
||||
.B ares_fds
|
||||
returns one greater than the number of the highest socket set in either
|
||||
.I read_fds
|
||||
or
|
||||
.IR write_fds .
|
||||
If no queries are active,
|
||||
.B ares_fds
|
||||
will return 0.
|
||||
.SH SEE ALSO
|
||||
.BR ares_timeout (3),
|
||||
.BR ares_process (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
@ -1,63 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds)
|
||||
{
|
||||
struct server_state *server;
|
||||
ares_socket_t nfds;
|
||||
int i;
|
||||
|
||||
/* Are there any active queries? */
|
||||
int active_queries = !ares__is_list_empty(&(channel->all_queries));
|
||||
|
||||
nfds = 0;
|
||||
for (i = 0; i < channel->nservers; i++)
|
||||
{
|
||||
server = &channel->servers[i];
|
||||
/* We only need to register interest in UDP sockets if we have
|
||||
* outstanding queries.
|
||||
*/
|
||||
if (active_queries && server->udp_socket != ARES_SOCKET_BAD)
|
||||
{
|
||||
FD_SET(server->udp_socket, read_fds);
|
||||
if (server->udp_socket >= nfds)
|
||||
nfds = server->udp_socket + 1;
|
||||
}
|
||||
/* We always register for TCP events, because we want to know
|
||||
* when the other side closes the connection, so we don't waste
|
||||
* time trying to use a broken connection.
|
||||
*/
|
||||
if (server->tcp_socket != ARES_SOCKET_BAD)
|
||||
{
|
||||
FD_SET(server->tcp_socket, read_fds);
|
||||
if (server->qhead)
|
||||
FD_SET(server->tcp_socket, write_fds);
|
||||
if (server->tcp_socket >= nfds)
|
||||
nfds = server->tcp_socket + 1;
|
||||
}
|
||||
}
|
||||
return (int)nfds;
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\" Copyright (C) 2004-2010 by Daniel Stenberg
|
||||
.\"
|
||||
.\" 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_FREE_DATA 3 "5 March 2010"
|
||||
.SH NAME
|
||||
ares_free_data \- Free data allocated by several c-ares functions
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B void ares_free_data(void *\fIdataptr\fP)
|
||||
.PP
|
||||
.B cc file.c -lcares
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
The
|
||||
.B ares_free_data(3)
|
||||
function frees one or more data structures allocated and returned
|
||||
by several c-ares functions. Specifically the data returned by the
|
||||
following list of functions must be deallocated using this function.
|
||||
.TP 5
|
||||
.B ares_get_servers(3)
|
||||
When used to free the data returned by ares_get_servers(3) this
|
||||
will free the whole linked list of ares_addr_node structures returned
|
||||
by ares_get_servers(3).
|
||||
.TP
|
||||
.B ares_parse_srv_reply(3)
|
||||
When used to free the data returned by ares_parse_srv_reply(3) this
|
||||
will free the whole linked list of ares_srv_reply structures returned
|
||||
by ares_parse_srv_reply(3), along with any additional storage
|
||||
associated with those structures.
|
||||
.TP
|
||||
.B ares_parse_txt_reply(3)
|
||||
When used to free the data returned by ares_parse_txt_reply(3) this
|
||||
will free the whole linked list of ares_txt_reply structures returned
|
||||
by ares_parse_txt_reply(3), along with any additional storage
|
||||
associated with those structures.
|
||||
.SH RETURN VALUE
|
||||
The ares_free_data() function does not return a value.
|
||||
.SH AVAILABILITY
|
||||
This function was first introduced in c-ares version 1.7.0.
|
||||
.SH SEE ALSO
|
||||
.BR ares_get_servers(3),
|
||||
.BR ares_parse_srv_reply(3),
|
||||
.BR ares_parse_txt_reply(3)
|
||||
.SH AUTHOR
|
||||
Yang Tse
|
||||
.PP
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.br
|
||||
Copyright (C) 2004-2010 by Daniel Stenberg.
|
@ -1,46 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_FREE_HOSTENT 3 "23 July 1998"
|
||||
.SH NAME
|
||||
ares_free_hostent \- Free host structure allocated by ares functions
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B void ares_free_hostent(struct hostent *\fIhost\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.I ares_free_hostent
|
||||
function frees a
|
||||
.B struct hostent
|
||||
allocated by one of the functions \fIares_parse_a_reply(3)\fP,
|
||||
\fIares_parse_aaaa_reply(3)\fP, or \fIares_parse_ptr_reply(3)\fP.
|
||||
.SH NOTES
|
||||
It is not necessary (and is not correct) to free the host structure passed to
|
||||
the callback functions for \fIares_gethostbyname(3)\fP or
|
||||
\fIares_gethostbyaddr(3)\fP. c-ares will automatically free such host
|
||||
structures when the callback returns.
|
||||
.SH SEE ALSO
|
||||
.BR ares_parse_a_reply (3),
|
||||
.BR ares_parse_aaaa_reply (3),
|
||||
.BR ares_parse_ptr_reply (3),
|
||||
.BR ares_parse_ns_reply (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
@ -1,40 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_private.h" /* for memdebug */
|
||||
|
||||
void ares_free_hostent(struct hostent *host)
|
||||
{
|
||||
char **p;
|
||||
|
||||
free((char *)(host->h_name));
|
||||
for (p = host->h_aliases; *p; p++)
|
||||
free(*p);
|
||||
free(host->h_aliases);
|
||||
free(host->h_addr_list[0]); /* no matter if there is one or many entries,
|
||||
there is only one malloc for all of them */
|
||||
free(host->h_addr_list);
|
||||
free(host);
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 2000 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_FREE_STRING 3 "4 February 2004"
|
||||
.SH NAME
|
||||
ares_free_string \- Free strings allocated by ares functions
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B void ares_free_string(void *\fIstr\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.I ares_free_string
|
||||
function frees a string allocated by an ares function.
|
||||
.SH SEE ALSO
|
||||
.BR ares_mkquery (3)
|
||||
.BR ares_expand_string (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 2000 by the Massachusetts Institute of Technology.
|
@ -1,26 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 2000 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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"
|
||||
#include <stdlib.h>
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
void ares_free_string(void *str)
|
||||
{
|
||||
free(str);
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\" Copyright (C) 2008-2010 by Daniel Stenberg
|
||||
.\"
|
||||
.\" 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_GET_SERVERS 3 "5 March 2010"
|
||||
.SH NAME
|
||||
ares_get_servers \- Retrieve name servers from an initialized ares_channel
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_get_servers(ares_channel \fIchannel\fP, struct ares_addr_node **\fIservers\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The \fBares_get_servers(3)\fP function retrieves name servers configuration
|
||||
from the
|
||||
channel data identified by
|
||||
.IR channel ,
|
||||
as a linked list of ares_addr_node structs storing a pointer to the first
|
||||
node at the address specified by
|
||||
.IR servers .
|
||||
|
||||
Function caller may traverse the returned name server linked list, or may use
|
||||
it directly as suitable input for the \fBares_set_servers(3)\fP function, but
|
||||
shall not shrink or extend the list on its own.
|
||||
|
||||
Each node of the name server linked list is stored in memory dynamically
|
||||
allocated and managed by c-ares. It is the caller's responsibility to free
|
||||
the resulting linked list, using \fBares_free_data(3)\fP , once the caller
|
||||
does not need it any longer.
|
||||
|
||||
This function is capable of handling IPv4 and IPv6 name server
|
||||
addresses simultaneously, rendering \fBares_save_options(3)\fP with
|
||||
optmask \fBARES_OPT_SERVERS\fP functionally obsolete except for
|
||||
IPv4-only name server usage.
|
||||
|
||||
.SH RETURN VALUES
|
||||
.B ares_get_servers(3)
|
||||
may return any of the following values:
|
||||
.TP 15
|
||||
.B ARES_SUCCESS
|
||||
The name servers configuration was successfuly retrieved
|
||||
.TP 15
|
||||
.B ARES_ENOMEM
|
||||
The memory was exhausted
|
||||
.TP 15
|
||||
.B ARES_ENODATA
|
||||
The channel data identified by
|
||||
.IR channel
|
||||
was invalid.
|
||||
.SH SEE ALSO
|
||||
.BR ares_set_servers (3),
|
||||
.BR ares_init_options (3),
|
||||
.BR ares_save_options(3)
|
||||
.SH AVAILABILITY
|
||||
ares_get_servers(3) was added in c-ares 1.7.1
|
||||
.SH AUTHOR
|
||||
Implementation of this function and associated library internals are based
|
||||
on code, comments and feedback provided November and December of 2008 by
|
||||
Daniel Stenberg, Gregor Jasny, Phil Blundell and Yang Tse, December 2009
|
||||
by Cedric Bail, February 2010 by Jakub Hrozek. On March 2010 Yang Tse
|
||||
shuffled all the bits and this function popped out.
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.br
|
||||
Copyright (C) 2008-2010 by Daniel Stenberg
|
@ -1,102 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_GETHOSTBYADDR 3 "24 July 1998"
|
||||
.SH NAME
|
||||
ares_gethostbyaddr \- Initiate a host query by address
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B typedef void (*ares_host_callback)(void *\fIarg\fP, int \fIstatus\fP,
|
||||
.B int \fItimeouts\fP, struct hostent *\fIhostent\fP)
|
||||
.PP
|
||||
.B void ares_gethostbyaddr(ares_channel \fIchannel\fP, const void *\fIaddr\fP,
|
||||
.B int \fIaddrlen\fP, int \fIfamily\fP, ares_host_callback \fIcallback\fP,
|
||||
.B void *\fIarg\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_gethostbyaddr
|
||||
function initiates a host query by address on the name service channel
|
||||
identified by
|
||||
.IR channel .
|
||||
The parameters
|
||||
.I addr
|
||||
and
|
||||
.I addrlen
|
||||
give the address as a series of bytes, and
|
||||
.I family
|
||||
gives the type of address. 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_gethostbyaddr
|
||||
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.
|
||||
.PP
|
||||
The callback argument
|
||||
.I timeouts
|
||||
reports how many times a query timed out during the execution of the
|
||||
given request.
|
||||
.PP
|
||||
On successful completion of the query, the callback argument
|
||||
.I hostent
|
||||
points to a
|
||||
.B struct hostent
|
||||
containing the name of the host returned by the query. The callback
|
||||
need not and should not attempt to free the memory pointed to by
|
||||
.IR hostent ;
|
||||
the ares library will free it when the callback returns. If the query
|
||||
did not complete successfully,
|
||||
.I hostent
|
||||
will be
|
||||
.BR NULL .
|
||||
.SH SEE ALSO
|
||||
.BR ares_process (3),
|
||||
.BR ares_gethostbyname (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
@ -1,291 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ares.h"
|
||||
#include "inet_net_pton.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
#ifdef WATT32
|
||||
#undef WIN32
|
||||
#endif
|
||||
|
||||
struct addr_query {
|
||||
/* Arguments passed to ares_gethostbyaddr() */
|
||||
ares_channel channel;
|
||||
struct ares_addr addr;
|
||||
ares_host_callback callback;
|
||||
void *arg;
|
||||
|
||||
const char *remaining_lookups;
|
||||
int timeouts;
|
||||
};
|
||||
|
||||
static void next_lookup(struct addr_query *aquery);
|
||||
static void addr_callback(void *arg, int status, int timeouts,
|
||||
unsigned char *abuf, int alen);
|
||||
static void end_aquery(struct addr_query *aquery, int status,
|
||||
struct hostent *host);
|
||||
static int file_lookup(struct ares_addr *addr, struct hostent **host);
|
||||
static void ptr_rr_name(char *name, const struct ares_addr *addr);
|
||||
|
||||
void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
|
||||
int family, ares_host_callback callback, void *arg)
|
||||
{
|
||||
struct addr_query *aquery;
|
||||
|
||||
if (family != AF_INET && family != AF_INET6)
|
||||
{
|
||||
callback(arg, ARES_ENOTIMP, 0, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((family == AF_INET && addrlen != sizeof(aquery->addr.addrV4)) ||
|
||||
(family == AF_INET6 && addrlen != sizeof(aquery->addr.addrV6)))
|
||||
{
|
||||
callback(arg, ARES_ENOTIMP, 0, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
aquery = malloc(sizeof(struct addr_query));
|
||||
if (!aquery)
|
||||
{
|
||||
callback(arg, ARES_ENOMEM, 0, NULL);
|
||||
return;
|
||||
}
|
||||
aquery->channel = channel;
|
||||
if (family == AF_INET)
|
||||
memcpy(&aquery->addr.addrV4, addr, sizeof(aquery->addr.addrV4));
|
||||
else
|
||||
memcpy(&aquery->addr.addrV6, addr, sizeof(aquery->addr.addrV6));
|
||||
aquery->addr.family = family;
|
||||
aquery->callback = callback;
|
||||
aquery->arg = arg;
|
||||
aquery->remaining_lookups = channel->lookups;
|
||||
aquery->timeouts = 0;
|
||||
|
||||
next_lookup(aquery);
|
||||
}
|
||||
|
||||
static void next_lookup(struct addr_query *aquery)
|
||||
{
|
||||
const char *p;
|
||||
char name[128];
|
||||
int status;
|
||||
struct hostent *host;
|
||||
|
||||
for (p = aquery->remaining_lookups; *p; p++)
|
||||
{
|
||||
switch (*p)
|
||||
{
|
||||
case 'b':
|
||||
ptr_rr_name(name, &aquery->addr);
|
||||
aquery->remaining_lookups = p + 1;
|
||||
ares_query(aquery->channel, name, C_IN, T_PTR, addr_callback,
|
||||
aquery);
|
||||
return;
|
||||
case 'f':
|
||||
status = file_lookup(&aquery->addr, &host);
|
||||
|
||||
/* this status check below previously checked for !ARES_ENOTFOUND,
|
||||
but we should not assume that this single error code is the one
|
||||
that can occur, as that is in fact no longer the case */
|
||||
if (status == ARES_SUCCESS)
|
||||
{
|
||||
end_aquery(aquery, status, host);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
end_aquery(aquery, ARES_ENOTFOUND, NULL);
|
||||
}
|
||||
|
||||
static void addr_callback(void *arg, int status, int timeouts,
|
||||
unsigned char *abuf, int alen)
|
||||
{
|
||||
struct addr_query *aquery = (struct addr_query *) arg;
|
||||
struct hostent *host;
|
||||
size_t addrlen;
|
||||
|
||||
aquery->timeouts += timeouts;
|
||||
if (status == ARES_SUCCESS)
|
||||
{
|
||||
if (aquery->addr.family == AF_INET)
|
||||
{
|
||||
addrlen = sizeof(aquery->addr.addrV4);
|
||||
status = ares_parse_ptr_reply(abuf, alen, &aquery->addr.addrV4,
|
||||
(int)addrlen, AF_INET, &host);
|
||||
}
|
||||
else
|
||||
{
|
||||
addrlen = sizeof(aquery->addr.addrV6);
|
||||
status = ares_parse_ptr_reply(abuf, alen, &aquery->addr.addrV6,
|
||||
(int)addrlen, AF_INET6, &host);
|
||||
}
|
||||
end_aquery(aquery, status, host);
|
||||
}
|
||||
else if (status == ARES_EDESTRUCTION)
|
||||
end_aquery(aquery, status, NULL);
|
||||
else
|
||||
next_lookup(aquery);
|
||||
}
|
||||
|
||||
static void end_aquery(struct addr_query *aquery, int status,
|
||||
struct hostent *host)
|
||||
{
|
||||
aquery->callback(aquery->arg, status, aquery->timeouts, host);
|
||||
if (host)
|
||||
ares_free_hostent(host);
|
||||
free(aquery);
|
||||
}
|
||||
|
||||
static int file_lookup(struct ares_addr *addr, struct hostent **host)
|
||||
{
|
||||
FILE *fp;
|
||||
int status;
|
||||
int error;
|
||||
|
||||
#ifdef WIN32
|
||||
char PATH_HOSTS[MAX_PATH];
|
||||
if (IS_NT()) {
|
||||
char tmp[MAX_PATH];
|
||||
HKEY hkeyHosts;
|
||||
|
||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
|
||||
== ERROR_SUCCESS)
|
||||
{
|
||||
DWORD dwLength = MAX_PATH;
|
||||
RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, (LPBYTE)tmp,
|
||||
&dwLength);
|
||||
ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
|
||||
RegCloseKey(hkeyHosts);
|
||||
}
|
||||
}
|
||||
else
|
||||
GetWindowsDirectory(PATH_HOSTS, MAX_PATH);
|
||||
|
||||
strcat(PATH_HOSTS, WIN_PATH_HOSTS);
|
||||
|
||||
#elif defined(WATT32)
|
||||
extern const char *_w32_GetHostsFile (void);
|
||||
const char *PATH_HOSTS = _w32_GetHostsFile();
|
||||
|
||||
if (!PATH_HOSTS)
|
||||
return ARES_ENOTFOUND;
|
||||
#endif
|
||||
|
||||
fp = fopen(PATH_HOSTS, "r");
|
||||
if (!fp)
|
||||
{
|
||||
error = ERRNO;
|
||||
switch(error)
|
||||
{
|
||||
case ENOENT:
|
||||
case ESRCH:
|
||||
return ARES_ENOTFOUND;
|
||||
default:
|
||||
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
|
||||
error, strerror(error)));
|
||||
DEBUGF(fprintf(stderr, "Error opening file: %s\n",
|
||||
PATH_HOSTS));
|
||||
*host = NULL;
|
||||
return ARES_EFILE;
|
||||
}
|
||||
}
|
||||
while ((status = ares__get_hostent(fp, addr->family, host)) == ARES_SUCCESS)
|
||||
{
|
||||
if (addr->family != (*host)->h_addrtype)
|
||||
{
|
||||
ares_free_hostent(*host);
|
||||
continue;
|
||||
}
|
||||
if (addr->family == AF_INET)
|
||||
{
|
||||
if (memcmp((*host)->h_addr, &addr->addrV4, sizeof(addr->addrV4)) == 0)
|
||||
break;
|
||||
}
|
||||
else if (addr->family == AF_INET6)
|
||||
{
|
||||
if (memcmp((*host)->h_addr, &addr->addrV6, sizeof(addr->addrV6)) == 0)
|
||||
break;
|
||||
}
|
||||
ares_free_hostent(*host);
|
||||
}
|
||||
fclose(fp);
|
||||
if (status == ARES_EOF)
|
||||
status = ARES_ENOTFOUND;
|
||||
if (status != ARES_SUCCESS)
|
||||
*host = NULL;
|
||||
return status;
|
||||
}
|
||||
|
||||
static void ptr_rr_name(char *name, const struct ares_addr *addr)
|
||||
{
|
||||
if (addr->family == AF_INET)
|
||||
{
|
||||
unsigned long laddr = ntohl(addr->addrV4.s_addr);
|
||||
int a1 = (int)((laddr >> 24) & 0xff);
|
||||
int a2 = (int)((laddr >> 16) & 0xff);
|
||||
int a3 = (int)((laddr >> 8) & 0xff);
|
||||
int a4 = (int)(laddr & 0xff);
|
||||
sprintf(name, "%d.%d.%d.%d.in-addr.arpa", a4, a3, a2, a1);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char *bytes = (unsigned char *)&addr->addrV6;
|
||||
/* There are too many arguments to do this in one line using
|
||||
* minimally C89-compliant compilers */
|
||||
sprintf(name,
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.",
|
||||
bytes[15]&0xf, bytes[15] >> 4, bytes[14]&0xf, bytes[14] >> 4,
|
||||
bytes[13]&0xf, bytes[13] >> 4, bytes[12]&0xf, bytes[12] >> 4,
|
||||
bytes[11]&0xf, bytes[11] >> 4, bytes[10]&0xf, bytes[10] >> 4,
|
||||
bytes[9]&0xf, bytes[9] >> 4, bytes[8]&0xf, bytes[8] >> 4);
|
||||
sprintf(name+strlen(name),
|
||||
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa",
|
||||
bytes[7]&0xf, bytes[7] >> 4, bytes[6]&0xf, bytes[6] >> 4,
|
||||
bytes[5]&0xf, bytes[5] >> 4, bytes[4]&0xf, bytes[4] >> 4,
|
||||
bytes[3]&0xf, bytes[3] >> 4, bytes[2]&0xf, bytes[2] >> 4,
|
||||
bytes[1]&0xf, bytes[1] >> 4, bytes[0]&0xf, bytes[0] >> 4);
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_GETHOSTBYNAME 3 "25 July 1998"
|
||||
.SH NAME
|
||||
ares_gethostbyname \- Initiate a host query by name
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B typedef void (*ares_host_callback)(void *\fIarg\fP, int \fIstatus\fP,
|
||||
.B int \fItimeouts\fP, struct hostent *\fIhostent\fP)
|
||||
.PP
|
||||
.B void ares_gethostbyname(ares_channel \fIchannel\fP, const char *\fIname\fP,
|
||||
.B int \fIfamily\fP, ares_host_callback \fIcallback\fP, void *\fIarg\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_gethostbyname
|
||||
function initiates a host query by name on the name service channel
|
||||
identified by
|
||||
.IR channel .
|
||||
The parameter
|
||||
.I name
|
||||
gives the hostname as a NUL-terminated C string, and
|
||||
.I family
|
||||
gives the desired type of address for the resulting host entry. 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_gethostbyname
|
||||
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 find addresses of type
|
||||
.IR family .
|
||||
.TP 19
|
||||
.B ARES_EBADNAME
|
||||
The hostname
|
||||
.B name
|
||||
is composed entirely of numbers and periods, but is not a valid
|
||||
representation of an Internet address.
|
||||
.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.
|
||||
.PP
|
||||
The callback argument
|
||||
.I timeouts
|
||||
reports how many times a query timed out during the execution of the
|
||||
given request.
|
||||
.PP
|
||||
On successful completion of the query, the callback argument
|
||||
.I hostent
|
||||
points to a
|
||||
.B struct hostent
|
||||
containing the name of the host returned by the query. The callback
|
||||
need not and should not attempt to free the memory pointed to by
|
||||
.IR hostent ;
|
||||
the ares library will free it when the callback returns. If the query
|
||||
did not complete successfully,
|
||||
.I hostent
|
||||
will be
|
||||
.BR NULL .
|
||||
.SH SEE ALSO
|
||||
.BR ares_process (3),
|
||||
.BR ares_gethostbyaddr (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
@ -1,513 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "inet_net_pton.h"
|
||||
#include "bitncmp.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
#ifdef WATT32
|
||||
#undef WIN32
|
||||
#endif
|
||||
|
||||
struct host_query {
|
||||
/* Arguments passed to ares_gethostbyname() */
|
||||
ares_channel channel;
|
||||
char *name;
|
||||
ares_host_callback callback;
|
||||
void *arg;
|
||||
int sent_family; /* this family is what was is being used */
|
||||
int want_family; /* this family is what is asked for in the API */
|
||||
const char *remaining_lookups;
|
||||
int timeouts;
|
||||
};
|
||||
|
||||
static void next_lookup(struct host_query *hquery, int status_code);
|
||||
static void host_callback(void *arg, int status, int timeouts,
|
||||
unsigned char *abuf, int alen);
|
||||
static void end_hquery(struct host_query *hquery, int status,
|
||||
struct hostent *host);
|
||||
static int fake_hostent(const char *name, int family,
|
||||
ares_host_callback callback, void *arg);
|
||||
static int file_lookup(const char *name, int family, struct hostent **host);
|
||||
static void sort_addresses(struct hostent *host,
|
||||
const struct apattern *sortlist, int nsort);
|
||||
static void sort6_addresses(struct hostent *host,
|
||||
const struct apattern *sortlist, int nsort);
|
||||
static int get_address_index(const struct in_addr *addr,
|
||||
const struct apattern *sortlist, int nsort);
|
||||
static int get6_address_index(const struct ares_in6_addr *addr,
|
||||
const struct apattern *sortlist, int nsort);
|
||||
|
||||
void ares_gethostbyname(ares_channel channel, const char *name, int family,
|
||||
ares_host_callback callback, void *arg)
|
||||
{
|
||||
struct host_query *hquery;
|
||||
|
||||
/* Right now we only know how to look up Internet addresses - and unspec
|
||||
means try both basically. */
|
||||
switch (family) {
|
||||
case AF_INET:
|
||||
case AF_INET6:
|
||||
case AF_UNSPEC:
|
||||
break;
|
||||
default:
|
||||
callback(arg, ARES_ENOTIMP, 0, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fake_hostent(name, family, callback, arg))
|
||||
return;
|
||||
|
||||
/* Allocate and fill in the host query structure. */
|
||||
hquery = malloc(sizeof(struct host_query));
|
||||
if (!hquery)
|
||||
{
|
||||
callback(arg, ARES_ENOMEM, 0, NULL);
|
||||
return;
|
||||
}
|
||||
hquery->channel = channel;
|
||||
hquery->name = strdup(name);
|
||||
hquery->want_family = family;
|
||||
hquery->sent_family = -1; /* nothing is sent yet */
|
||||
if (!hquery->name) {
|
||||
free(hquery);
|
||||
callback(arg, ARES_ENOMEM, 0, NULL);
|
||||
return;
|
||||
}
|
||||
hquery->callback = callback;
|
||||
hquery->arg = arg;
|
||||
hquery->remaining_lookups = channel->lookups;
|
||||
hquery->timeouts = 0;
|
||||
|
||||
/* Start performing lookups according to channel->lookups. */
|
||||
next_lookup(hquery, ARES_ECONNREFUSED /* initial error code */);
|
||||
}
|
||||
|
||||
static void next_lookup(struct host_query *hquery, int status_code)
|
||||
{
|
||||
const char *p;
|
||||
struct hostent *host;
|
||||
int status = status_code;
|
||||
|
||||
for (p = hquery->remaining_lookups; *p; p++)
|
||||
{
|
||||
switch (*p)
|
||||
{
|
||||
case 'b':
|
||||
/* DNS lookup */
|
||||
hquery->remaining_lookups = p + 1;
|
||||
if ((hquery->want_family == AF_INET6) ||
|
||||
(hquery->want_family == AF_UNSPEC)) {
|
||||
/* if inet6 or unspec, start out with AAAA */
|
||||
hquery->sent_family = AF_INET6;
|
||||
ares_search(hquery->channel, hquery->name, C_IN, T_AAAA,
|
||||
host_callback, hquery);
|
||||
}
|
||||
else {
|
||||
hquery->sent_family = AF_INET;
|
||||
ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback,
|
||||
hquery);
|
||||
}
|
||||
return;
|
||||
|
||||
case 'f':
|
||||
/* Host file lookup */
|
||||
status = file_lookup(hquery->name, hquery->want_family, &host);
|
||||
|
||||
/* this status check below previously checked for !ARES_ENOTFOUND,
|
||||
but we should not assume that this single error code is the one
|
||||
that can occur, as that is in fact no longer the case */
|
||||
if (status == ARES_SUCCESS)
|
||||
{
|
||||
end_hquery(hquery, status, host);
|
||||
return;
|
||||
}
|
||||
status = status_code; /* Use original status code */
|
||||
break;
|
||||
}
|
||||
}
|
||||
end_hquery(hquery, status, NULL);
|
||||
}
|
||||
|
||||
static void host_callback(void *arg, int status, int timeouts,
|
||||
unsigned char *abuf, int alen)
|
||||
{
|
||||
struct host_query *hquery = (struct host_query *) arg;
|
||||
ares_channel channel = hquery->channel;
|
||||
struct hostent *host = NULL;
|
||||
|
||||
hquery->timeouts += timeouts;
|
||||
if (status == ARES_SUCCESS)
|
||||
{
|
||||
if (hquery->sent_family == AF_INET)
|
||||
{
|
||||
status = ares_parse_a_reply(abuf, alen, &host, NULL, NULL);
|
||||
if (host && channel->nsort)
|
||||
sort_addresses(host, channel->sortlist, channel->nsort);
|
||||
}
|
||||
else if (hquery->sent_family == AF_INET6)
|
||||
{
|
||||
status = ares_parse_aaaa_reply(abuf, alen, &host, NULL, NULL);
|
||||
if (status == ARES_ENODATA || status == ARES_EBADRESP) {
|
||||
/* The query returned something but either there were no AAAA records (e.g. just CNAME)
|
||||
or the response was malformed. Try looking up A instead.
|
||||
We should possibly limit this attempt-next logic to AF_UNSPEC lookups only. */
|
||||
hquery->sent_family = AF_INET;
|
||||
ares_search(hquery->channel, hquery->name, C_IN, T_A,
|
||||
host_callback, hquery);
|
||||
return;
|
||||
}
|
||||
if (host && channel->nsort)
|
||||
sort6_addresses(host, channel->sortlist, channel->nsort);
|
||||
}
|
||||
end_hquery(hquery, status, host);
|
||||
}
|
||||
else if ((status == ARES_ENODATA || status == ARES_EBADRESP || status == ARES_ETIMEOUT) && hquery->sent_family == AF_INET6)
|
||||
{
|
||||
/* The AAAA query yielded no useful result. Now look up an A instead.
|
||||
We should possibly limit this attempt-next logic to AF_UNSPEC lookups only. */
|
||||
hquery->sent_family = AF_INET;
|
||||
ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback,
|
||||
hquery);
|
||||
}
|
||||
else if (status == ARES_EDESTRUCTION)
|
||||
end_hquery(hquery, status, NULL);
|
||||
else
|
||||
next_lookup(hquery, status);
|
||||
}
|
||||
|
||||
static void end_hquery(struct host_query *hquery, int status,
|
||||
struct hostent *host)
|
||||
{
|
||||
hquery->callback(hquery->arg, status, hquery->timeouts, host);
|
||||
if (host)
|
||||
ares_free_hostent(host);
|
||||
free(hquery->name);
|
||||
free(hquery);
|
||||
}
|
||||
|
||||
/* If the name looks like an IP address, fake up a host entry, end the
|
||||
* query immediately, and return true. Otherwise return false.
|
||||
*/
|
||||
static int fake_hostent(const char *name, int family, ares_host_callback callback,
|
||||
void *arg)
|
||||
{
|
||||
struct hostent hostent;
|
||||
char *aliases[1] = { NULL };
|
||||
char *addrs[2];
|
||||
int result = 0;
|
||||
struct in_addr in;
|
||||
struct ares_in6_addr in6;
|
||||
|
||||
if (family == AF_INET || family == AF_INET6)
|
||||
{
|
||||
/* It only looks like an IP address if it's all numbers and dots. */
|
||||
int numdots = 0, valid = 1;
|
||||
const char *p;
|
||||
for (p = name; *p; p++)
|
||||
{
|
||||
if (!ISDIGIT(*p) && *p != '.') {
|
||||
valid = 0;
|
||||
break;
|
||||
} else if (*p == '.') {
|
||||
numdots++;
|
||||
}
|
||||
}
|
||||
|
||||
/* if we don't have 3 dots, it is illegal
|
||||
* (although inet_addr doesn't think so).
|
||||
*/
|
||||
if (numdots != 3 || !valid)
|
||||
result = 0;
|
||||
else
|
||||
result = ((in.s_addr = inet_addr(name)) == INADDR_NONE ? 0 : 1);
|
||||
|
||||
if (result)
|
||||
family = AF_INET;
|
||||
}
|
||||
if (family == AF_INET6)
|
||||
result = (ares_inet_pton(AF_INET6, name, &in6) < 1 ? 0 : 1);
|
||||
|
||||
if (!result)
|
||||
return 0;
|
||||
|
||||
if (family == AF_INET)
|
||||
{
|
||||
hostent.h_length = (int)sizeof(struct in_addr);
|
||||
addrs[0] = (char *)∈
|
||||
}
|
||||
else if (family == AF_INET6)
|
||||
{
|
||||
hostent.h_length = (int)sizeof(struct ares_in6_addr);
|
||||
addrs[0] = (char *)&in6;
|
||||
}
|
||||
/* Duplicate the name, to avoid a constness violation. */
|
||||
hostent.h_name = strdup(name);
|
||||
if (!hostent.h_name)
|
||||
{
|
||||
callback(arg, ARES_ENOMEM, 0, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 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_addr_list = addrs;
|
||||
callback(arg, ARES_SUCCESS, 0, &hostent);
|
||||
|
||||
free((char *)(hostent.h_name));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* This is an API method */
|
||||
int ares_gethostbyname_file(ares_channel channel, const char *name,
|
||||
int family, struct hostent **host)
|
||||
{
|
||||
int result;
|
||||
|
||||
/* We only take the channel to ensure that ares_init() been called. */
|
||||
if(channel == NULL)
|
||||
{
|
||||
/* Anything will do, really. This seems fine, and is consistent with
|
||||
other error cases. */
|
||||
*host = NULL;
|
||||
return ARES_ENOTFOUND;
|
||||
}
|
||||
|
||||
/* Just chain to the internal implementation we use here; it's exactly
|
||||
* what we want.
|
||||
*/
|
||||
result = file_lookup(name, family, host);
|
||||
if(result != ARES_SUCCESS)
|
||||
{
|
||||
/* We guarantee a NULL hostent on failure. */
|
||||
*host = NULL;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int file_lookup(const char *name, int family, struct hostent **host)
|
||||
{
|
||||
FILE *fp;
|
||||
char **alias;
|
||||
int status;
|
||||
int error;
|
||||
|
||||
#ifdef WIN32
|
||||
char PATH_HOSTS[MAX_PATH];
|
||||
if (IS_NT()) {
|
||||
char tmp[MAX_PATH];
|
||||
HKEY hkeyHosts;
|
||||
|
||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
|
||||
== ERROR_SUCCESS)
|
||||
{
|
||||
DWORD dwLength = MAX_PATH;
|
||||
RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, (LPBYTE)tmp,
|
||||
&dwLength);
|
||||
ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
|
||||
RegCloseKey(hkeyHosts);
|
||||
}
|
||||
}
|
||||
else
|
||||
GetWindowsDirectory(PATH_HOSTS, MAX_PATH);
|
||||
|
||||
strcat(PATH_HOSTS, WIN_PATH_HOSTS);
|
||||
|
||||
#elif defined(WATT32)
|
||||
extern const char *_w32_GetHostsFile (void);
|
||||
const char *PATH_HOSTS = _w32_GetHostsFile();
|
||||
|
||||
if (!PATH_HOSTS)
|
||||
return ARES_ENOTFOUND;
|
||||
#endif
|
||||
|
||||
fp = fopen(PATH_HOSTS, "r");
|
||||
if (!fp)
|
||||
{
|
||||
error = ERRNO;
|
||||
switch(error)
|
||||
{
|
||||
case ENOENT:
|
||||
case ESRCH:
|
||||
return ARES_ENOTFOUND;
|
||||
default:
|
||||
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
|
||||
error, strerror(error)));
|
||||
DEBUGF(fprintf(stderr, "Error opening file: %s\n",
|
||||
PATH_HOSTS));
|
||||
*host = NULL;
|
||||
return ARES_EFILE;
|
||||
}
|
||||
}
|
||||
while ((status = ares__get_hostent(fp, family, host)) == ARES_SUCCESS)
|
||||
{
|
||||
if (strcasecmp((*host)->h_name, name) == 0)
|
||||
break;
|
||||
for (alias = (*host)->h_aliases; *alias; alias++)
|
||||
{
|
||||
if (strcasecmp(*alias, name) == 0)
|
||||
break;
|
||||
}
|
||||
if (*alias)
|
||||
break;
|
||||
ares_free_hostent(*host);
|
||||
}
|
||||
fclose(fp);
|
||||
if (status == ARES_EOF)
|
||||
status = ARES_ENOTFOUND;
|
||||
if (status != ARES_SUCCESS)
|
||||
*host = NULL;
|
||||
return status;
|
||||
}
|
||||
|
||||
static void sort_addresses(struct hostent *host, const struct apattern *sortlist,
|
||||
int nsort)
|
||||
{
|
||||
struct in_addr a1, a2;
|
||||
int i1, i2, ind1, ind2;
|
||||
|
||||
/* This is a simple insertion sort, not optimized at all. i1 walks
|
||||
* through the address list, with the loop invariant that everything
|
||||
* to the left of i1 is sorted. In the loop body, the value at i1 is moved
|
||||
* back through the list (via i2) until it is in sorted order.
|
||||
*/
|
||||
for (i1 = 0; host->h_addr_list[i1]; i1++)
|
||||
{
|
||||
memcpy(&a1, host->h_addr_list[i1], sizeof(struct in_addr));
|
||||
ind1 = get_address_index(&a1, sortlist, nsort);
|
||||
for (i2 = i1 - 1; i2 >= 0; i2--)
|
||||
{
|
||||
memcpy(&a2, host->h_addr_list[i2], sizeof(struct in_addr));
|
||||
ind2 = get_address_index(&a2, sortlist, nsort);
|
||||
if (ind2 <= ind1)
|
||||
break;
|
||||
memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct in_addr));
|
||||
}
|
||||
memcpy(host->h_addr_list[i2 + 1], &a1, sizeof(struct in_addr));
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the first entry in sortlist which matches addr. Return nsort
|
||||
* if none of them match.
|
||||
*/
|
||||
static int get_address_index(const struct in_addr *addr,
|
||||
const struct apattern *sortlist,
|
||||
int nsort)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nsort; i++)
|
||||
{
|
||||
if (sortlist[i].family != AF_INET)
|
||||
continue;
|
||||
if (sortlist[i].type == PATTERN_MASK)
|
||||
{
|
||||
if ((addr->s_addr & sortlist[i].mask.addr4.s_addr)
|
||||
== sortlist[i].addrV4.s_addr)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ares_bitncmp(&addr->s_addr, &sortlist[i].addrV4.s_addr,
|
||||
sortlist[i].mask.bits))
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
static void sort6_addresses(struct hostent *host, const struct apattern *sortlist,
|
||||
int nsort)
|
||||
{
|
||||
struct ares_in6_addr a1, a2;
|
||||
int i1, i2, ind1, ind2;
|
||||
|
||||
/* This is a simple insertion sort, not optimized at all. i1 walks
|
||||
* through the address list, with the loop invariant that everything
|
||||
* to the left of i1 is sorted. In the loop body, the value at i1 is moved
|
||||
* back through the list (via i2) until it is in sorted order.
|
||||
*/
|
||||
for (i1 = 0; host->h_addr_list[i1]; i1++)
|
||||
{
|
||||
memcpy(&a1, host->h_addr_list[i1], sizeof(struct ares_in6_addr));
|
||||
ind1 = get6_address_index(&a1, sortlist, nsort);
|
||||
for (i2 = i1 - 1; i2 >= 0; i2--)
|
||||
{
|
||||
memcpy(&a2, host->h_addr_list[i2], sizeof(struct ares_in6_addr));
|
||||
ind2 = get6_address_index(&a2, sortlist, nsort);
|
||||
if (ind2 <= ind1)
|
||||
break;
|
||||
memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct ares_in6_addr));
|
||||
}
|
||||
memcpy(host->h_addr_list[i2 + 1], &a1, sizeof(struct ares_in6_addr));
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the first entry in sortlist which matches addr. Return nsort
|
||||
* if none of them match.
|
||||
*/
|
||||
static int get6_address_index(const struct ares_in6_addr *addr,
|
||||
const struct apattern *sortlist,
|
||||
int nsort)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nsort; i++)
|
||||
{
|
||||
if (sortlist[i].family != AF_INET6)
|
||||
continue;
|
||||
if (!ares_bitncmp(addr,
|
||||
&sortlist[i].addrV6,
|
||||
sortlist[i].mask.bits))
|
||||
break;
|
||||
}
|
||||
return i;
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_GETHOSTBYNAME 3 "25 July 1998"
|
||||
.SH NAME
|
||||
ares_gethostbyname_file \- Lookup a name in the system's hosts file
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_gethostbyname_file(ares_channel \fIchannel\fP, const char *\fIname\fP,
|
||||
.B int \fIfamily\fP, struct hostent **host)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_gethostbyname_file
|
||||
function performs a host lookup by name against the system's hosts file (or equivalent local hostname database).
|
||||
The
|
||||
.IR channel
|
||||
parameter is required, but no asynchronous queries are performed. Instead, the
|
||||
lookup is done via the same mechanism used to perform 'f' lookups
|
||||
(see the
|
||||
.I lookups
|
||||
options field in \fIares_init_options(3)\fP).
|
||||
The parameter
|
||||
.I name
|
||||
gives the hostname as a NUL-terminated C string, and
|
||||
.I family
|
||||
gives the desired type of address for the resulting host entry.
|
||||
.PP
|
||||
The return value 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 and
|
||||
.I host
|
||||
now points to the result (and must be freed with \fIares_free_hostent(3)\fP).
|
||||
.TP 19
|
||||
.B ARES_ENOTFOUND
|
||||
The hostname
|
||||
.I name
|
||||
was not found.
|
||||
.TP 19
|
||||
.B ARES_EFILE
|
||||
There was a file I/O error while performing the lookup.
|
||||
.TP 19
|
||||
.B ARES_ENOMEM
|
||||
Memory was exhausted.
|
||||
.PP
|
||||
On successful completion of the query, the pointer pointed to by
|
||||
.I host
|
||||
points to a
|
||||
.B struct hostent
|
||||
containing the address of the host returned by the lookup. The user must
|
||||
free the memory pointed to by
|
||||
.IR host
|
||||
when finished with it by calling \fIares_free_hostent(3)\fP. If the lookup did
|
||||
not complete successfully,
|
||||
.I host
|
||||
will be
|
||||
.BR NULL .
|
||||
.SH AVAILABILITY
|
||||
Added in c-ares 1.5.4
|
||||
.SH SEE ALSO
|
||||
.BR ares_gethostbyname (3),
|
||||
.BR ares_free_hostent (3),
|
||||
.BR ares_init_options (3)
|
||||
.SH AUTHOR
|
||||
Brad Spencer
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
@ -1,150 +0,0 @@
|
||||
.\" $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 "1 May 2009"
|
||||
.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 int \fItimeouts\fP, char *\fInode\fP, char *\fIservice\fP)
|
||||
.PP
|
||||
.B void ares_getnameinfo(ares_channel \fIchannel\fP, const struct sockaddr *\fIsa\fP,
|
||||
.B ares_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
|
||||
The callback argument
|
||||
.I timeouts
|
||||
reports how many times a query timed out during the execution of the
|
||||
given request.
|
||||
.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.
|
@ -1,413 +0,0 @@
|
||||
/* $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.
|
||||
*/
|
||||
#include "ares_setup.h"
|
||||
|
||||
#ifdef HAVE_GETSERVBYPORT_R
|
||||
# if !defined(GETSERVBYPORT_R_ARGS) || \
|
||||
(GETSERVBYPORT_R_ARGS < 4) || (GETSERVBYPORT_R_ARGS > 6)
|
||||
# error "you MUST specifiy a valid number of arguments for getservbyport_r"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
#ifdef HAVE_NET_IF_H
|
||||
#include <net/if.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_ipv6.h"
|
||||
#include "inet_ntop.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
struct nameinfo_query {
|
||||
ares_nameinfo_callback callback;
|
||||
void *arg;
|
||||
union {
|
||||
struct sockaddr_in addr4;
|
||||
struct sockaddr_in6 addr6;
|
||||
} addr;
|
||||
int family;
|
||||
int flags;
|
||||
int timeouts;
|
||||
};
|
||||
|
||||
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
#define IPBUFSIZ \
|
||||
(sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") + IF_NAMESIZE)
|
||||
#else
|
||||
#define IPBUFSIZ \
|
||||
(sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"))
|
||||
#endif
|
||||
|
||||
static void nameinfo_callback(void *arg, int status, int timeouts, struct hostent *host);
|
||||
static char *lookup_service(unsigned short port, int flags,
|
||||
char *buf, size_t buflen);
|
||||
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int scopeid,
|
||||
char *buf, size_t buflen);
|
||||
#endif
|
||||
static char *ares_striendstr(const char *s1, const char *s2);
|
||||
|
||||
void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa,
|
||||
ares_socklen_t salen,
|
||||
int flags, ares_nameinfo_callback callback, void *arg)
|
||||
{
|
||||
struct sockaddr_in *addr = NULL;
|
||||
struct sockaddr_in6 *addr6 = NULL;
|
||||
struct nameinfo_query *niquery;
|
||||
unsigned int port = 0;
|
||||
|
||||
/* Verify the buffer size */
|
||||
if (salen == sizeof(struct sockaddr_in))
|
||||
{
|
||||
addr = (struct sockaddr_in *)sa;
|
||||
port = addr->sin_port;
|
||||
}
|
||||
else if (salen == sizeof(struct sockaddr_in6))
|
||||
{
|
||||
addr6 = (struct sockaddr_in6 *)sa;
|
||||
port = addr6->sin6_port;
|
||||
}
|
||||
else
|
||||
{
|
||||
callback(arg, ARES_ENOTIMP, 0, NULL, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
/* If neither, assume they want a host */
|
||||
if (!(flags & ARES_NI_LOOKUPSERVICE) && !(flags & ARES_NI_LOOKUPHOST))
|
||||
flags |= ARES_NI_LOOKUPHOST;
|
||||
|
||||
/* All they want is a service, no need for DNS */
|
||||
if ((flags & ARES_NI_LOOKUPSERVICE) && !(flags & ARES_NI_LOOKUPHOST))
|
||||
{
|
||||
char buf[33], *service;
|
||||
|
||||
service = lookup_service((unsigned short)(port & 0xffff),
|
||||
flags, buf, sizeof(buf));
|
||||
callback(arg, ARES_SUCCESS, 0, NULL, service);
|
||||
return;
|
||||
}
|
||||
|
||||
/* They want a host lookup */
|
||||
if ((flags & ARES_NI_LOOKUPHOST))
|
||||
{
|
||||
/* A numeric host can be handled without DNS */
|
||||
if ((flags & ARES_NI_NUMERICHOST))
|
||||
{
|
||||
char ipbuf[IPBUFSIZ];
|
||||
char srvbuf[33];
|
||||
char *service = NULL;
|
||||
ipbuf[0] = 0;
|
||||
|
||||
/* Specifying not to lookup a host, but then saying a host
|
||||
* is required has to be illegal.
|
||||
*/
|
||||
if (flags & ARES_NI_NAMEREQD)
|
||||
{
|
||||
callback(arg, ARES_EBADFLAGS, 0, NULL, NULL);
|
||||
return;
|
||||
}
|
||||
if (salen == sizeof(struct sockaddr_in6))
|
||||
{
|
||||
ares_inet_ntop(AF_INET6, &addr6->sin6_addr, ipbuf, IPBUFSIZ);
|
||||
/* If the system supports scope IDs, use it */
|
||||
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
append_scopeid(addr6, flags, ipbuf, sizeof(ipbuf));
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
ares_inet_ntop(AF_INET, &addr->sin_addr, ipbuf, IPBUFSIZ);
|
||||
}
|
||||
/* They also want a service */
|
||||
if (flags & ARES_NI_LOOKUPSERVICE)
|
||||
service = lookup_service((unsigned short)(port & 0xffff),
|
||||
flags, srvbuf, sizeof(srvbuf));
|
||||
callback(arg, ARES_SUCCESS, 0, ipbuf, service);
|
||||
return;
|
||||
}
|
||||
/* This is where a DNS lookup becomes necessary */
|
||||
else
|
||||
{
|
||||
niquery = malloc(sizeof(struct nameinfo_query));
|
||||
if (!niquery)
|
||||
{
|
||||
callback(arg, ARES_ENOMEM, 0, NULL, NULL);
|
||||
return;
|
||||
}
|
||||
niquery->callback = callback;
|
||||
niquery->arg = arg;
|
||||
niquery->flags = flags;
|
||||
niquery->timeouts = 0;
|
||||
if (sa->sa_family == AF_INET)
|
||||
{
|
||||
niquery->family = AF_INET;
|
||||
memcpy(&niquery->addr.addr4, addr, sizeof(addr));
|
||||
ares_gethostbyaddr(channel, &addr->sin_addr,
|
||||
sizeof(struct in_addr), AF_INET,
|
||||
nameinfo_callback, niquery);
|
||||
}
|
||||
else
|
||||
{
|
||||
niquery->family = AF_INET6;
|
||||
memcpy(&niquery->addr.addr6, addr6, sizeof(addr6));
|
||||
ares_gethostbyaddr(channel, &addr6->sin6_addr,
|
||||
sizeof(struct ares_in6_addr), AF_INET6,
|
||||
nameinfo_callback, niquery);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void nameinfo_callback(void *arg, int status, int timeouts, struct hostent *host)
|
||||
{
|
||||
struct nameinfo_query *niquery = (struct nameinfo_query *) arg;
|
||||
char srvbuf[33];
|
||||
char *service = NULL;
|
||||
|
||||
niquery->timeouts += timeouts;
|
||||
if (status == ARES_SUCCESS)
|
||||
{
|
||||
/* They want a service too */
|
||||
if (niquery->flags & ARES_NI_LOOKUPSERVICE)
|
||||
{
|
||||
if (niquery->family == AF_INET)
|
||||
service = lookup_service(niquery->addr.addr4.sin_port,
|
||||
niquery->flags, srvbuf, sizeof(srvbuf));
|
||||
else
|
||||
service = lookup_service(niquery->addr.addr6.sin6_port,
|
||||
niquery->flags, srvbuf, sizeof(srvbuf));
|
||||
}
|
||||
/* NOFQDN means we have to strip off the domain name portion.
|
||||
We do this by determining our own domain name, then searching the string
|
||||
for this domain name and removing it.
|
||||
*/
|
||||
#ifdef HAVE_GETHOSTNAME
|
||||
if (niquery->flags & ARES_NI_NOFQDN)
|
||||
{
|
||||
char buf[255];
|
||||
char *domain;
|
||||
gethostname(buf, 255);
|
||||
if ((domain = strchr(buf, '.')))
|
||||
{
|
||||
char *end = ares_striendstr(host->h_name, domain);
|
||||
if (end)
|
||||
*end = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
niquery->callback(niquery->arg, ARES_SUCCESS, niquery->timeouts, (char *)(host->h_name),
|
||||
service);
|
||||
return;
|
||||
}
|
||||
/* We couldn't find the host, but it's OK, we can use the IP */
|
||||
else if (status == ARES_ENOTFOUND && !(niquery->flags & ARES_NI_NAMEREQD))
|
||||
{
|
||||
char ipbuf[IPBUFSIZ];
|
||||
if (niquery->family == AF_INET)
|
||||
ares_inet_ntop(AF_INET, &niquery->addr.addr4.sin_addr, ipbuf, IPBUFSIZ);
|
||||
else
|
||||
{
|
||||
ares_inet_ntop(AF_INET6, &niquery->addr.addr6.sin6_addr, ipbuf, IPBUFSIZ);
|
||||
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
append_scopeid(&niquery->addr.addr6, niquery->flags, ipbuf, sizeof(ipbuf));
|
||||
#endif
|
||||
}
|
||||
/* They want a service too */
|
||||
if (niquery->flags & ARES_NI_LOOKUPSERVICE)
|
||||
{
|
||||
if (niquery->family == AF_INET)
|
||||
service = lookup_service(niquery->addr.addr4.sin_port,
|
||||
niquery->flags, srvbuf, sizeof(srvbuf));
|
||||
else
|
||||
service = lookup_service(niquery->addr.addr6.sin6_port,
|
||||
niquery->flags, srvbuf, sizeof(srvbuf));
|
||||
}
|
||||
niquery->callback(niquery->arg, ARES_SUCCESS, niquery->timeouts, ipbuf, service);
|
||||
return;
|
||||
}
|
||||
niquery->callback(niquery->arg, status, niquery->timeouts, NULL, NULL);
|
||||
free(niquery);
|
||||
}
|
||||
|
||||
static char *lookup_service(unsigned short port, int flags,
|
||||
char *buf, size_t buflen)
|
||||
{
|
||||
const char *proto;
|
||||
struct servent *sep;
|
||||
#ifdef HAVE_GETSERVBYPORT_R
|
||||
struct servent se;
|
||||
#endif
|
||||
char tmpbuf[4096];
|
||||
|
||||
if (port)
|
||||
{
|
||||
if (flags & ARES_NI_NUMERICSERV)
|
||||
sep = NULL;
|
||||
else
|
||||
{
|
||||
if (flags & ARES_NI_UDP)
|
||||
proto = "udp";
|
||||
else if (flags & ARES_NI_SCTP)
|
||||
proto = "sctp";
|
||||
else if (flags & ARES_NI_DCCP)
|
||||
proto = "dccp";
|
||||
else
|
||||
proto = "tcp";
|
||||
#ifdef HAVE_GETSERVBYPORT_R
|
||||
sep = &se;
|
||||
memset(tmpbuf, 0, sizeof(tmpbuf));
|
||||
#if GETSERVBYPORT_R_ARGS == 6
|
||||
if (getservbyport_r(port, proto, &se, (void *)tmpbuf, sizeof(tmpbuf), &sep) != 0)
|
||||
sep = NULL;
|
||||
#elif GETSERVBYPORT_R_ARGS == 5
|
||||
sep = getservbyport_r(port, proto, &se, (void *)tmpbuf, sizeof(tmpbuf));
|
||||
#elif GETSERVBYPORT_R_ARGS == 4
|
||||
if (getservbyport_r(port, proto, &se, (void *)tmpbuf) != 0)
|
||||
sep = NULL;
|
||||
#else
|
||||
/* Lets just hope the OS uses TLS! */
|
||||
sep = getservbyport(port, proto);
|
||||
#endif
|
||||
#else
|
||||
/* Lets just hope the OS uses TLS! */
|
||||
#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
|
||||
sep = getservbyport(port, (char*)proto);
|
||||
#else
|
||||
sep = getservbyport(port, proto);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
if (sep && sep->s_name)
|
||||
/* get service name */
|
||||
strcpy(tmpbuf, sep->s_name);
|
||||
else
|
||||
/* get port as a string */
|
||||
sprintf(tmpbuf, "%u", (unsigned int)ntohs(port));
|
||||
if (strlen(tmpbuf) < buflen)
|
||||
/* return it if buffer big enough */
|
||||
strcpy(buf, tmpbuf);
|
||||
else
|
||||
/* avoid reusing previous one */
|
||||
buf[0] = '\0';
|
||||
return buf;
|
||||
}
|
||||
buf[0] = '\0';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int flags,
|
||||
char *buf, size_t buflen)
|
||||
{
|
||||
#ifdef HAVE_IF_INDEXTONAME
|
||||
int is_ll, is_mcll;
|
||||
#endif
|
||||
char fmt_u[] = "%u";
|
||||
char fmt_lu[] = "%lu";
|
||||
char tmpbuf[IF_NAMESIZE + 2];
|
||||
size_t bufl;
|
||||
char *fmt = (sizeof(addr6->sin6_scope_id) > sizeof(unsigned int))?fmt_lu:fmt_u;
|
||||
|
||||
tmpbuf[0] = '%';
|
||||
|
||||
#ifdef HAVE_IF_INDEXTONAME
|
||||
is_ll = IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr);
|
||||
is_mcll = IN6_IS_ADDR_MC_LINKLOCAL(&addr6->sin6_addr);
|
||||
if ((flags & ARES_NI_NUMERICSCOPE) ||
|
||||
(!is_ll && !is_mcll))
|
||||
{
|
||||
sprintf(&tmpbuf[1], fmt, addr6->sin6_scope_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (if_indextoname(addr6->sin6_scope_id, &tmpbuf[1]) == NULL)
|
||||
sprintf(&tmpbuf[1], fmt, addr6->sin6_scope_id);
|
||||
}
|
||||
#else
|
||||
sprintf(&tmpbuf[1], fmt, addr6->sin6_scope_id);
|
||||
(void) flags;
|
||||
#endif
|
||||
tmpbuf[IF_NAMESIZE + 1] = '\0';
|
||||
bufl = strlen(buf);
|
||||
|
||||
if(bufl + strlen(tmpbuf) < buflen)
|
||||
/* only append the scopeid string if it fits in the target buffer */
|
||||
strcpy(&buf[bufl], tmpbuf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Determines if s1 ends with the string in s2 (case-insensitive) */
|
||||
static char *ares_striendstr(const char *s1, const char *s2)
|
||||
{
|
||||
const char *c1, *c2, *c1_begin;
|
||||
int lo1, lo2;
|
||||
size_t s1_len = strlen(s1), s2_len = strlen(s2);
|
||||
|
||||
/* If the substr is longer than the full str, it can't match */
|
||||
if (s2_len > s1_len)
|
||||
return NULL;
|
||||
|
||||
/* Jump to the end of s1 minus the length of s2 */
|
||||
c1_begin = s1+s1_len-s2_len;
|
||||
c1 = (const char *)c1_begin;
|
||||
c2 = s2;
|
||||
while (c2 < s2+s2_len)
|
||||
{
|
||||
lo1 = tolower(*c1);
|
||||
lo2 = tolower(*c2);
|
||||
if (lo1 != lo2)
|
||||
return NULL;
|
||||
else
|
||||
{
|
||||
c1++;
|
||||
c2++;
|
||||
}
|
||||
}
|
||||
if (c2 == c1 && c2 == NULL)
|
||||
return (char *)c1_begin;
|
||||
return NULL;
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Original file name getopt.c Initial import into the c-ares source tree
|
||||
* on 2007-04-11. Lifted from version 5.2 of the 'Open Mash' project with
|
||||
* the modified BSD license, BSD license without the advertising clause.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* getopt.c --
|
||||
*
|
||||
* Standard UNIX getopt function. Code is from BSD.
|
||||
*
|
||||
* Copyright (c) 1987-2001 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* A. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* B. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* C. Neither the names of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
||||
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* #if !defined(lint)
|
||||
* static char sccsid[] = "@(#)getopt.c 8.2 (Berkeley) 4/2/94";
|
||||
* #endif
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "ares_getopt.h"
|
||||
|
||||
int opterr = 1, /* if error message should be printed */
|
||||
optind = 1; /* index into parent argv vector */
|
||||
int optopt = 0; /* character checked for validity */
|
||||
static int optreset; /* reset getopt */
|
||||
char *optarg; /* argument associated with option */
|
||||
|
||||
#define BADCH (int)'?'
|
||||
#define BADARG (int)':'
|
||||
#define EMSG (char *)""
|
||||
|
||||
/*
|
||||
* ares_getopt --
|
||||
* Parse argc/argv argument vector.
|
||||
*/
|
||||
int
|
||||
ares_getopt(int nargc, char * const nargv[], const char *ostr)
|
||||
{
|
||||
static char *place = EMSG; /* option letter processing */
|
||||
char *oli; /* option letter list index */
|
||||
|
||||
if (optreset || !*place) { /* update scanning pointer */
|
||||
optreset = 0;
|
||||
if (optind >= nargc || *(place = nargv[optind]) != '-') {
|
||||
place = EMSG;
|
||||
return (EOF);
|
||||
}
|
||||
if (place[1] && *++place == '-') { /* found "--" */
|
||||
++optind;
|
||||
place = EMSG;
|
||||
return (EOF);
|
||||
}
|
||||
} /* option letter okay? */
|
||||
if ((optopt = (int)*place++) == (int)':' ||
|
||||
(oli = strchr(ostr, optopt)) == NULL) {
|
||||
/*
|
||||
* if the user didn't specify '-' as an option,
|
||||
* assume it means EOF.
|
||||
*/
|
||||
if (optopt == (int)'-')
|
||||
return (EOF);
|
||||
if (!*place)
|
||||
++optind;
|
||||
if (opterr && *ostr != ':')
|
||||
(void)fprintf(stderr,
|
||||
"%s: illegal option -- %c\n", __FILE__, optopt);
|
||||
return (BADCH);
|
||||
}
|
||||
if (*++oli != ':') { /* don't need argument */
|
||||
optarg = NULL;
|
||||
if (!*place)
|
||||
++optind;
|
||||
}
|
||||
else { /* need an argument */
|
||||
if (*place) /* no white space */
|
||||
optarg = place;
|
||||
else if (nargc <= ++optind) { /* no arg */
|
||||
place = EMSG;
|
||||
if (*ostr == ':')
|
||||
return (BADARG);
|
||||
if (opterr)
|
||||
(void)fprintf(stderr,
|
||||
"%s: option requires an argument -- %c\n",
|
||||
__FILE__, optopt);
|
||||
return (BADCH);
|
||||
}
|
||||
else /* white space */
|
||||
optarg = nargv[optind];
|
||||
place = EMSG;
|
||||
++optind;
|
||||
}
|
||||
return (optopt); /* dump back option letter */
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
#ifndef ARES_GETOPT_H
|
||||
#define ARES_GETOPT_H
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987-2001 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* A. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* B. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* C. Neither the names of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
||||
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
int ares_getopt(int nargc, char * const nargv[], const char *ostr);
|
||||
|
||||
#undef optarg
|
||||
#undef optind
|
||||
#undef opterr
|
||||
#undef optopt
|
||||
#undef optreset
|
||||
|
||||
#define optarg ares_optarg
|
||||
#define optind ares_optind
|
||||
#define opterr ares_opterr
|
||||
#define optopt ares_optopt
|
||||
#define optreset ares_optreset
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
extern int opterr;
|
||||
extern int optopt;
|
||||
|
||||
#endif /* ARES_GETOPT_H */
|
@ -1,58 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by Daniel Stenberg
|
||||
.\"
|
||||
.\" 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_GETSOCK 3 "11 March 2010"
|
||||
.SH NAME
|
||||
ares_getsock \- get socket descriptors to wait on
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_getsock(ares_channel \fIchannel\fP, ares_socket_t *\fIsocks\fP,
|
||||
.B int \fInumsocks\fP);
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_getsock
|
||||
function retrieves the set of socket descriptors which the calling
|
||||
application should wait on for reading and/or writing for the
|
||||
processing of name service queries pending on the name service channel
|
||||
identified by
|
||||
.IR channel .
|
||||
Socket descriptors will be set in the socket descriptor array pointed to by
|
||||
\fIsocks\fP.
|
||||
\fInumsocks\fP is the size of the given array in number of ints.
|
||||
|
||||
This function can only return information about up to 16 sockets. If more are
|
||||
in use (however unlikely that is), they are simply not reported back.
|
||||
.SH RETURN VALUES
|
||||
\fBares_getsock\fP returns a bitmask for what actions to wait for on the
|
||||
different sockets. The ares.h header file provides these convenience macros to
|
||||
extract the information appropriately:
|
||||
|
||||
.nf
|
||||
#define ARES_GETSOCK_MAXNUM 16 /* ares_getsock() can return info about
|
||||
this many sockets */
|
||||
#define ARES_GETSOCK_READABLE(bits,num) (bits & (1<< (num)))
|
||||
#define ARES_GETSOCK_WRITABLE(bits,num) (bits & (1 << ((num) + \
|
||||
ARES_GETSOCK_MAXNUM)))
|
||||
.fi
|
||||
.SH NOTES
|
||||
This function was added in c-ares 1.3.1
|
||||
.SH SEE ALSO
|
||||
.BR ares_timeout (3),
|
||||
.BR ares_fds (3),
|
||||
.BR ares_process (3)
|
@ -1,73 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 2005 - 2010, Daniel Stenberg
|
||||
*
|
||||
* 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_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
int ares_getsock(ares_channel channel,
|
||||
ares_socket_t *socks,
|
||||
int numsocks) /* size of the 'socks' array */
|
||||
{
|
||||
struct server_state *server;
|
||||
int i;
|
||||
int sockindex=0;
|
||||
int bitmap = 0;
|
||||
unsigned int setbits = 0xffffffff;
|
||||
|
||||
/* Are there any active queries? */
|
||||
int active_queries = !ares__is_list_empty(&(channel->all_queries));
|
||||
|
||||
for (i = 0;
|
||||
(i < channel->nservers) && (sockindex < ARES_GETSOCK_MAXNUM);
|
||||
i++)
|
||||
{
|
||||
server = &channel->servers[i];
|
||||
/* We only need to register interest in UDP sockets if we have
|
||||
* outstanding queries.
|
||||
*/
|
||||
if (active_queries && server->udp_socket != ARES_SOCKET_BAD)
|
||||
{
|
||||
if(sockindex >= numsocks)
|
||||
break;
|
||||
socks[sockindex] = server->udp_socket;
|
||||
bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
|
||||
sockindex++;
|
||||
}
|
||||
/* We always register for TCP events, because we want to know
|
||||
* when the other side closes the connection, so we don't waste
|
||||
* time trying to use a broken connection.
|
||||
*/
|
||||
if (server->tcp_socket != ARES_SOCKET_BAD)
|
||||
{
|
||||
if(sockindex >= numsocks)
|
||||
break;
|
||||
socks[sockindex] = server->tcp_socket;
|
||||
bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
|
||||
|
||||
if (server->qhead && active_queries)
|
||||
/* then the tcp socket is also writable! */
|
||||
bitmap |= ARES_GETSOCK_WRITABLE(setbits, sockindex);
|
||||
|
||||
sockindex++;
|
||||
}
|
||||
}
|
||||
return bitmap;
|
||||
}
|
203
ares/ares_init.3
203
ares/ares_init.3
@ -1,203 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\" Copyright (C) 2004-2010 by Daniel Stenberg
|
||||
.\"
|
||||
.\" 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_INIT 3 "5 March 2010"
|
||||
.SH NAME
|
||||
ares_init, ares_init_options \- Initialize a resolver channel
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_init(ares_channel *\fIchannelptr\fP)
|
||||
.B int ares_init_options(ares_channel *\fIchannelptr\fP,
|
||||
.B struct ares_options *\fIoptions\fP, int \fIoptmask\fP)
|
||||
.PP
|
||||
.B cc file.c -lcares
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The \fBares_init\fP function initializes a communications channel for name
|
||||
service lookups. If it returns successfully, \fBares_init\fP will set the
|
||||
variable pointed to by \fIchannelptr\fP to a handle used to identify the name
|
||||
service channel. The caller should invoke
|
||||
.BR ares_destroy (3)
|
||||
on the handle when the channel is no longer needed.
|
||||
.PP
|
||||
The \fBares_init_options\fP function also initializes a name service channel,
|
||||
with additional options useful for applications requiring more control over
|
||||
name service configuration. The \fIoptmask\fP parameter specifies which fields
|
||||
in the structure pointed to by \fIoptions\fP are set, as follows:
|
||||
.TP 18
|
||||
.B ARES_OPT_FLAGS
|
||||
.B int \fIflags\fP;
|
||||
.br
|
||||
Flags controlling the behavior of the resolver. See below for a
|
||||
description of possible flag values.
|
||||
.TP 18
|
||||
.B ARES_OPT_TIMEOUT
|
||||
.B int \fItimeout\fP;
|
||||
.br
|
||||
The number of seconds each name server is given to respond to a query on the
|
||||
first try. (After the first try, the timeout algorithm becomes more
|
||||
complicated, but scales linearly with the value of \fItimeout\fP.) The
|
||||
default is five seconds. This option is being deprecated by
|
||||
\fIARES_OPT_TIMEOUTMS\fP starting in c-ares 1.5.2.
|
||||
.TP 18
|
||||
.B ARES_OPT_TIMEOUTMS
|
||||
.B int \fItimeout\fP;
|
||||
.br
|
||||
The number of milliseconds each name server is given to respond to a query on
|
||||
the first try. (After the first try, the timeout algorithm becomes more
|
||||
complicated, but scales linearly with the value of \fItimeout\fP.) The
|
||||
default is five seconds. Note that this option is specified with the same
|
||||
struct field as the former \fIARES_OPT_TIMEOUT\fP, it is but the option bits
|
||||
that tell c-ares how to interpret the number. This option was added in c-ares
|
||||
1.5.2.
|
||||
.TP 18
|
||||
.B ARES_OPT_TRIES
|
||||
.B int \fItries\fP;
|
||||
.br
|
||||
The number of tries the resolver will try contacting each name server
|
||||
before giving up. The default is four tries.
|
||||
.TP 18
|
||||
.B ARES_OPT_NDOTS
|
||||
.B int \fIndots\fP;
|
||||
.br
|
||||
The number of dots which must be present in a domain name for it to be
|
||||
queried for "as is" prior to querying for it with the default domain
|
||||
extensions appended. The default value is 1 unless set otherwise by
|
||||
resolv.conf or the RES_OPTIONS environment variable.
|
||||
.TP 18
|
||||
.B ARES_OPT_PORT
|
||||
.B unsigned short \fIport\fP;
|
||||
.br
|
||||
The port to use for queries (both TCP and UDP), in network byte order.
|
||||
The default value is 53 (in network byte order), the standard name
|
||||
service port.
|
||||
.TP 18
|
||||
.B ARES_OPT_SERVERS
|
||||
.B struct in_addr *\fIservers\fP;
|
||||
.br
|
||||
.B int \fInservers\fP;
|
||||
.br
|
||||
The list of IPv4 servers to contact, instead of the servers specified in
|
||||
resolv.conf or the local named. In order to allow specification of either
|
||||
IPv4 or IPv6 name servers, function
|
||||
.BR ares_set_servers(3)
|
||||
must be used instead.
|
||||
.TP 18
|
||||
.B ARES_OPT_DOMAINS
|
||||
.B char **\fIdomains\fP;
|
||||
.br
|
||||
.B int \fIndomains\fP;
|
||||
.br
|
||||
The domains to search, instead of the domains specified in resolv.conf
|
||||
or the domain derived from the kernel hostname variable.
|
||||
.TP 18
|
||||
.B ARES_OPT_LOOKUPS
|
||||
.B char *\fIlookups\fP;
|
||||
.br
|
||||
The lookups to perform for host queries.
|
||||
.I lookups
|
||||
should be set to a string of the characters "b" or "f", where "b"
|
||||
indicates a DNS lookup and "f" indicates a lookup in the hosts file.
|
||||
.TP 18
|
||||
.B ARES_OPT_SOCK_STATE_CB
|
||||
.B void (*\fIsock_state_cb\fP)(void *data, int s, int read, int write);
|
||||
.br
|
||||
.B void *\fIsock_state_cb_data\fP;
|
||||
.br
|
||||
A callback function to be invoked when a socket changes state.
|
||||
.I s
|
||||
will be passed the socket whose state has changed;
|
||||
.I read
|
||||
will be set to true if the socket should listen for read events, and
|
||||
.I write
|
||||
will be set to true if the socket should listen for write events.
|
||||
The value of
|
||||
.I sock_state_cb_data
|
||||
will be passed as the
|
||||
.I data
|
||||
argument.
|
||||
.PP
|
||||
The
|
||||
.I flags
|
||||
field should be the bitwise or of some subset of the following values:
|
||||
.TP 23
|
||||
.B ARES_FLAG_USEVC
|
||||
Always use TCP queries (the "virtual circuit") instead of UDP
|
||||
queries. Normally, TCP is only used if a UDP query yields a truncated
|
||||
result.
|
||||
.TP 23
|
||||
.B ARES_FLAG_PRIMARY
|
||||
Only query the first server in the list of servers to query.
|
||||
.TP 23
|
||||
.B ARES_FLAG_IGNTC
|
||||
If a truncated response to a UDP query is received, do not fall back
|
||||
to TCP; simply continue on with the truncated response.
|
||||
.TP 23
|
||||
.B ARES_FLAG_NORECURSE
|
||||
Do not set the "recursion desired" bit on outgoing queries, so that the name
|
||||
server being contacted will not try to fetch the answer from other servers if
|
||||
it doesn't know the answer locally. Be aware that ares will not do the
|
||||
recursion for you. Recursion must be handled by the application calling ares
|
||||
if \fIARES_FLAG_NORECURSE\fP is set.
|
||||
.TP 23
|
||||
.B ARES_FLAG_STAYOPEN
|
||||
Do not close communications sockets when the number of active queries
|
||||
drops to zero.
|
||||
.TP 23
|
||||
.B ARES_FLAG_NOSEARCH
|
||||
Do not use the default search domains; only query hostnames as-is or
|
||||
as aliases.
|
||||
.TP 23
|
||||
.B ARES_FLAG_NOALIASES
|
||||
Do not honor the HOSTALIASES environment variable, which normally
|
||||
specifies a file of hostname translations.
|
||||
.TP 23
|
||||
.B ARES_FLAG_NOCHECKRESP
|
||||
Do not discard responses with the SERVFAIL, NOTIMP, or REFUSED
|
||||
response code or responses whose questions don't match the questions
|
||||
in the request. Primarily useful for writing clients which might be
|
||||
used to test or debug name servers.
|
||||
.SH RETURN VALUES
|
||||
.I ares_init
|
||||
or
|
||||
.I ares_init_options
|
||||
can return any of the following values:
|
||||
.TP 14
|
||||
.B ARES_SUCCESS
|
||||
Initialization succeeded.
|
||||
.TP 14
|
||||
.B ARES_EFILE
|
||||
A configuration file could not be read.
|
||||
.TP 14
|
||||
.B ARES_ENOMEM
|
||||
The process's available memory was exhausted.
|
||||
.TP 14
|
||||
.B ARES_ENOTINITIALIZED
|
||||
c-ares library initialization not yet performed.
|
||||
.SH SEE ALSO
|
||||
.BR ares_destroy(3),
|
||||
.BR ares_dup(3),
|
||||
.BR ares_library_init(3),
|
||||
.BR ares_set_servers(3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.br
|
||||
Copyright (C) 2004-2010 by Daniel Stenberg.
|
1627
ares/ares_init.c
1627
ares/ares_init.c
File diff suppressed because it is too large
Load Diff
@ -1,2 +0,0 @@
|
||||
.so man3/ares_init.3
|
||||
.\" $Id$
|
@ -1,75 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 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.
|
||||
*/
|
||||
|
||||
#ifndef ARES_IPV6_H
|
||||
#define ARES_IPV6_H
|
||||
|
||||
#ifndef HAVE_PF_INET6
|
||||
#define PF_INET6 AF_INET6
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRUCT_SOCKADDR_IN6
|
||||
struct sockaddr_in6
|
||||
{
|
||||
unsigned short sin6_family;
|
||||
unsigned short sin6_port;
|
||||
unsigned long sin6_flowinfo;
|
||||
struct ares_in6_addr sin6_addr;
|
||||
unsigned int sin6_scope_id;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRUCT_ADDRINFO
|
||||
struct addrinfo
|
||||
{
|
||||
int ai_flags;
|
||||
int ai_family;
|
||||
int ai_socktype;
|
||||
int ai_protocol;
|
||||
ares_socklen_t ai_addrlen; /* Follow rfc3493 struct addrinfo */
|
||||
char *ai_canonname;
|
||||
struct sockaddr *ai_addr;
|
||||
struct addrinfo *ai_next;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef NS_IN6ADDRSZ
|
||||
#if SIZEOF_STRUCT_IN6_ADDR == 0
|
||||
/* We cannot have it set to zero, so we pick a fixed value here */
|
||||
#define NS_IN6ADDRSZ 16
|
||||
#else
|
||||
#define NS_IN6ADDRSZ SIZEOF_STRUCT_IN6_ADDR
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef NS_INADDRSZ
|
||||
#define NS_INADDRSZ SIZEOF_STRUCT_IN_ADDR
|
||||
#endif
|
||||
|
||||
#ifndef NS_INT16SZ
|
||||
#define NS_INT16SZ 2
|
||||
#endif
|
||||
|
||||
#ifndef IF_NAMESIZE
|
||||
#ifdef IFNAMSIZ
|
||||
#define IF_NAMESIZE IFNAMSIZ
|
||||
#else
|
||||
#define IF_NAMESIZE 256
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* ARES_IPV6_H */
|
@ -1,74 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\" Copyright (C) 2004-2009 by Daniel Stenberg
|
||||
.\"
|
||||
.\" 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_LIBRARY_CLEANUP 3 "19 May 2009"
|
||||
.SH NAME
|
||||
ares_library_cleanup \- c-ares library deinitialization
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B void ares_library_cleanup(void)
|
||||
.PP
|
||||
.B cc file.c -lcares
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
The
|
||||
.B ares_library_cleanup
|
||||
function uninitializes the c-ares library, freeing all resources
|
||||
previously aquired by \fIares_library_init(3)\fP when the library
|
||||
was initialized.
|
||||
.PP
|
||||
This function must be called when the program using c-ares will
|
||||
no longer need any c-ares function. Once the program has called
|
||||
\fIares_library_cleanup(3)\fP it shall not make any further call to any
|
||||
c-ares function.
|
||||
.PP
|
||||
This function does not cancel any pending c-ares lookups or requests
|
||||
previously done. Program must use \fIares_cancel(3)\fP for this purpose.
|
||||
.PP
|
||||
.B This function is not thread safe.
|
||||
You have to call it once the program is about to terminate, but this call must
|
||||
be done once the program has terminated every single thread that it could have
|
||||
initiated. This is required to avoid potential race conditions in library
|
||||
deinitialization, and also due to the fact that \fIares_library_cleanup(3)\fP
|
||||
might call functions from other libraries that are thread unsafe, and could
|
||||
conflict with any other thread that is already using these other libraries.
|
||||
.PP
|
||||
Win32/64 application DLLs shall not call \fIares_library_cleanup(3)\fP from
|
||||
the DllMain function. Doing so will produce deadlocks and other problems.
|
||||
.SH AVAILABILITY
|
||||
This function was first introduced in c-ares version 1.7.0 along with the
|
||||
definition of preprocessor symbol \fICARES_HAVE_ARES_LIBRARY_CLEANUP\fP as an
|
||||
indication of the availability of this function.
|
||||
.PP
|
||||
Since the introduction of this function, it is absolutely mandatory to call it
|
||||
for any Win32/64 program using c-ares.
|
||||
.PP
|
||||
Non-Win32/64 systems can still use c-ares version 1.7.0 without calling
|
||||
\fIares_library_cleanup(3)\fP due to the fact that \fIcurrently\fP it is nearly
|
||||
a do-nothing function on non-Win32/64 platforms.
|
||||
.SH SEE ALSO
|
||||
.BR ares_library_init(3),
|
||||
.BR ares_cancel(3)
|
||||
.SH AUTHOR
|
||||
Yang Tse
|
||||
.PP
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.br
|
||||
Copyright (C) 2004-2009 by Daniel Stenberg.
|
@ -1,97 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\" Copyright (C) 2004-2009 by Daniel Stenberg
|
||||
.\"
|
||||
.\" 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_LIBRARY_INIT 3 "19 May 2009"
|
||||
.SH NAME
|
||||
ares_library_init \- c-ares library initialization
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_library_init(int \fIflags\fP)
|
||||
.PP
|
||||
.B cc file.c -lcares
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
The
|
||||
.B ares_library_init
|
||||
function performs initializations internally required by the c-ares
|
||||
library that must take place before any other function provided by
|
||||
c-ares can be used in a program.
|
||||
.PP
|
||||
This function must be called one time within the life of a program,
|
||||
before the program actually executes any other c-ares library function.
|
||||
Initializations done by this function remain effective until a
|
||||
call to \fIares_library_cleanup(3)\fP is performed.
|
||||
.PP
|
||||
Successive calls to this function do nothing, only the first call done
|
||||
when c-ares is in an uninitialized state is actually effective.
|
||||
.PP
|
||||
The
|
||||
.I flags
|
||||
parameter is a bit pattern that tells c-ares exactly which features
|
||||
should be initialized, as described below. Set the desired bits by
|
||||
ORing the values together. In normal operation you should specify
|
||||
\fIARES_LIB_INIT_ALL\fP. Don't use any other value unless you are
|
||||
familiar with it and trying to control some internal c-ares feature.
|
||||
.PP
|
||||
.B This function is not thread safe.
|
||||
You have to call it once the program has started, but this call must be done
|
||||
before the program starts any other thread. This is required to avoid
|
||||
potential race conditions in library initialization, and also due to the fact
|
||||
that \fIares_library_init(3)\fP might call functions from other libraries that
|
||||
are thread unsafe, and could conflict with any other thread that is already
|
||||
using these other libraries.
|
||||
.PP
|
||||
Win32/64 application DLLs shall not call \fIares_library_init(3)\fP from the
|
||||
DllMain function. Doing so will produce deadlocks and other problems.
|
||||
.SH FLAGS
|
||||
.TP 5
|
||||
.B ARES_LIB_INIT_ALL
|
||||
Initialize everything possible. This sets all known bits.
|
||||
.TP
|
||||
.B ARES_LIB_INIT_WIN32
|
||||
Initialize Win32/64 specific libraries.
|
||||
.TP
|
||||
.B ARES_LIB_INIT_NONE
|
||||
Initialize nothing extra. This sets no bit.
|
||||
.SH RETURN VALUE
|
||||
Upon successful completion, ares_library_init() will return 0. Otherwise, a
|
||||
non-zero error number will be returned to indicate the error. Except for
|
||||
\fIares_strerror(3)\fP, you shall not call any other c-ares function upon
|
||||
\fIares_library_init(3)\fP failure.
|
||||
.SH AVAILABILITY
|
||||
This function was first introduced in c-ares version 1.7.0 along with the
|
||||
definition of preprocessor symbol \fICARES_HAVE_ARES_LIBRARY_INIT\fP as an
|
||||
indication of the availability of this function.
|
||||
.PP
|
||||
Since the introduction of this function it is absolutely mandatory to
|
||||
call it for any Win32/64 program using c-ares.
|
||||
.PP
|
||||
Non-Win32/64 systems can still use c-ares version 1.7.0 without calling
|
||||
\fIares_library_init(3)\fP due to the fact that \fIcurrently\fP it is nearly
|
||||
a do-nothing function on non-Win32/64 platforms at this point.
|
||||
.SH SEE ALSO
|
||||
.BR ares_library_cleanup(3),
|
||||
.BR ares_strerror(3)
|
||||
.SH AUTHOR
|
||||
Yang Tse
|
||||
.PP
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.br
|
||||
Copyright (C) 2004-2009 by Daniel Stenberg.
|
@ -1,133 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
* Copyright (C) 2004-2009 by Daniel Stenberg
|
||||
*
|
||||
* 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"
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_library_init.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
/* library-private global and unique instance vars */
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
fpGetNetworkParams_t ares_fpGetNetworkParams = ZERO_NULL;
|
||||
fpSystemFunction036_t ares_fpSystemFunction036 = ZERO_NULL;
|
||||
#endif
|
||||
|
||||
/* library-private global vars with source visibility restricted to this file */
|
||||
|
||||
static unsigned int ares_initialized;
|
||||
static int ares_init_flags;
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
static HMODULE hnd_iphlpapi;
|
||||
static HMODULE hnd_advapi32;
|
||||
#endif
|
||||
|
||||
|
||||
static int ares_win32_init(void)
|
||||
{
|
||||
#ifdef USE_WINSOCK
|
||||
|
||||
hnd_iphlpapi = 0;
|
||||
hnd_iphlpapi = LoadLibrary("iphlpapi.dll");
|
||||
if (!hnd_iphlpapi)
|
||||
return ARES_ELOADIPHLPAPI;
|
||||
|
||||
ares_fpGetNetworkParams = (fpGetNetworkParams_t)
|
||||
GetProcAddress(hnd_iphlpapi, "GetNetworkParams");
|
||||
if (!ares_fpGetNetworkParams)
|
||||
{
|
||||
FreeLibrary(hnd_iphlpapi);
|
||||
return ARES_EADDRGETNETWORKPARAMS;
|
||||
}
|
||||
|
||||
/*
|
||||
* When advapi32.dll is unavailable or advapi32.dll has no SystemFunction036,
|
||||
* also known as RtlGenRandom, which is the case for Windows versions prior
|
||||
* to WinXP then c-ares uses portable rand() function. Then don't error here.
|
||||
*/
|
||||
|
||||
hnd_advapi32 = 0;
|
||||
hnd_advapi32 = LoadLibrary("advapi32.dll");
|
||||
if (hnd_advapi32)
|
||||
{
|
||||
ares_fpSystemFunction036 = (fpSystemFunction036_t)
|
||||
GetProcAddress(hnd_advapi32, "SystemFunction036");
|
||||
}
|
||||
|
||||
#endif
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static void ares_win32_cleanup(void)
|
||||
{
|
||||
#ifdef USE_WINSOCK
|
||||
if (hnd_advapi32)
|
||||
FreeLibrary(hnd_advapi32);
|
||||
if (hnd_iphlpapi)
|
||||
FreeLibrary(hnd_iphlpapi);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int ares_library_init(int flags)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (ares_initialized)
|
||||
return ARES_SUCCESS;
|
||||
ares_initialized++;
|
||||
|
||||
if (flags & ARES_LIB_INIT_WIN32)
|
||||
{
|
||||
res = ares_win32_init();
|
||||
if (res != ARES_SUCCESS)
|
||||
return res;
|
||||
}
|
||||
|
||||
ares_init_flags = flags;
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void ares_library_cleanup(void)
|
||||
{
|
||||
if (!ares_initialized)
|
||||
return;
|
||||
ares_initialized--;
|
||||
|
||||
if (ares_init_flags & ARES_LIB_INIT_WIN32)
|
||||
ares_win32_cleanup();
|
||||
|
||||
ares_init_flags = ARES_LIB_INIT_NONE;
|
||||
}
|
||||
|
||||
|
||||
int ares_library_initialized(void)
|
||||
{
|
||||
#ifdef USE_WINSOCK
|
||||
if (!ares_initialized)
|
||||
return ARES_ENOTINITIALIZED;
|
||||
#endif
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1,40 +0,0 @@
|
||||
#ifndef HEADER_CARES_LIBRARY_INIT_H
|
||||
#define HEADER_CARES_LIBRARY_INIT_H
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
* Copyright (C) 2004-2009 by Daniel Stenberg
|
||||
*
|
||||
* 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 USE_WINSOCK
|
||||
|
||||
#include <iphlpapi.h>
|
||||
|
||||
typedef DWORD (WINAPI *fpGetNetworkParams_t) (FIXED_INFO*, DWORD*);
|
||||
typedef BOOLEAN (APIENTRY *fpSystemFunction036_t) (void*, ULONG);
|
||||
|
||||
/* Forward-declaration of variables defined in ares_library_init.c */
|
||||
/* that are global and unique instances for whole c-ares library. */
|
||||
|
||||
extern fpGetNetworkParams_t ares_fpGetNetworkParams;
|
||||
extern fpSystemFunction036_t ares_fpSystemFunction036;
|
||||
|
||||
#endif /* USE_WINSOCK */
|
||||
|
||||
#endif /* HEADER_CARES_LIBRARY_INIT_H */
|
||||
|
@ -1,87 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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"
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
/* Routines for managing doubly-linked circular linked lists with a
|
||||
* dummy head.
|
||||
*/
|
||||
|
||||
/* Initialize a new head node */
|
||||
void ares__init_list_head(struct list_node* head) {
|
||||
head->prev = head;
|
||||
head->next = head;
|
||||
head->data = NULL;
|
||||
}
|
||||
|
||||
/* Initialize a list node */
|
||||
void ares__init_list_node(struct list_node* node, void* d) {
|
||||
node->prev = NULL;
|
||||
node->next = NULL;
|
||||
node->data = d;
|
||||
}
|
||||
|
||||
/* Returns true iff the given list is empty */
|
||||
int ares__is_list_empty(struct list_node* head) {
|
||||
return ((head->next == head) && (head->prev == head));
|
||||
}
|
||||
|
||||
/* Inserts new_node before old_node */
|
||||
void ares__insert_in_list(struct list_node* new_node,
|
||||
struct list_node* old_node) {
|
||||
new_node->next = old_node;
|
||||
new_node->prev = old_node->prev;
|
||||
old_node->prev->next = new_node;
|
||||
old_node->prev = new_node;
|
||||
}
|
||||
|
||||
/* Removes the node from the list it's in, if any */
|
||||
void ares__remove_from_list(struct list_node* node) {
|
||||
if (node->next != NULL) {
|
||||
node->prev->next = node->next;
|
||||
node->next->prev = node->prev;
|
||||
node->prev = NULL;
|
||||
node->next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Swap the contents of two lists */
|
||||
void ares__swap_lists(struct list_node* head_a,
|
||||
struct list_node* head_b) {
|
||||
int is_a_empty = ares__is_list_empty(head_a);
|
||||
int is_b_empty = ares__is_list_empty(head_b);
|
||||
struct list_node old_a = *head_a;
|
||||
struct list_node old_b = *head_b;
|
||||
|
||||
if (is_a_empty) {
|
||||
ares__init_list_head(head_b);
|
||||
} else {
|
||||
*head_b = old_a;
|
||||
old_a.next->prev = head_b;
|
||||
old_a.prev->next = head_b;
|
||||
}
|
||||
if (is_b_empty) {
|
||||
ares__init_list_head(head_a);
|
||||
} else {
|
||||
*head_a = old_b;
|
||||
old_b.next->prev = head_a;
|
||||
old_b.prev->next = head_a;
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
#ifndef __ARES_LLIST_H
|
||||
#define __ARES_LLIST_H
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
/* Node definition for circular, doubly-linked list */
|
||||
struct list_node {
|
||||
struct list_node *prev;
|
||||
struct list_node *next;
|
||||
void* data;
|
||||
};
|
||||
|
||||
void ares__init_list_head(struct list_node* head);
|
||||
|
||||
void ares__init_list_node(struct list_node* node, void* d);
|
||||
|
||||
int ares__is_list_empty(struct list_node* head);
|
||||
|
||||
void ares__insert_in_list(struct list_node* new_node,
|
||||
struct list_node* old_node);
|
||||
|
||||
void ares__remove_from_list(struct list_node* node);
|
||||
|
||||
void ares__swap_lists(struct list_node* head_a,
|
||||
struct list_node* head_b);
|
||||
|
||||
#endif /* __ARES_LLIST_H */
|
@ -1,76 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998, 2000 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_MKQUERY 3 "20 Nov 2009"
|
||||
.SH NAME
|
||||
ares_mkquery \- Compose a single-question DNS query buffer
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_mkquery(const char *\fIname\fP, int \fIdnsclass\fP, int \fItype\fP,
|
||||
.B unsigned short \fIid\fP, int \fIrd\fP, unsigned char **\fIbuf\fP,
|
||||
.B int *\fIbuflen\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_mkquery
|
||||
function composes a DNS query with a single question.
|
||||
The parameter
|
||||
.I name
|
||||
gives the query name as a NUL-terminated C string of period-separated
|
||||
labels optionally ending with a period; periods and backslashes within
|
||||
a label must be escaped with a backlash. The parameters
|
||||
.I dnsclass
|
||||
and
|
||||
.I type
|
||||
give the class and type of the query using the values defined in
|
||||
.BR <arpa/nameser.h> .
|
||||
The parameter
|
||||
.I id
|
||||
gives a 16-bit identifier for the query. The parameter
|
||||
.I rd
|
||||
should be nonzero if recursion is desired, zero if not. The query
|
||||
will be placed in an allocated buffer, a pointer to which will be
|
||||
stored in the variable pointed to by
|
||||
.IR buf ,
|
||||
and the length of which will be stored in the variable pointed to by
|
||||
.IR buflen .
|
||||
It is the caller's responsibility to free this buffer using
|
||||
\fIares_free_string(3)\fP when it is no longer needed.
|
||||
.SH RETURN VALUES
|
||||
.B ares_mkquery
|
||||
can return any of the following values:
|
||||
.TP 15
|
||||
.B ARES_SUCCESS
|
||||
Construction of the DNS query succeeded.
|
||||
.TP 15
|
||||
.B ARES_EBADNAME
|
||||
The query name
|
||||
.I name
|
||||
could not be encoded as a domain name, either because it contained a
|
||||
zero-length label or because it contained a label of more than 63
|
||||
characters.
|
||||
.TP 15
|
||||
.B ARES_ENOMEM
|
||||
Memory was exhausted.
|
||||
.SH SEE ALSO
|
||||
.BR ares_expand_name (3),
|
||||
.BR ares_free_string (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998, 2000 by the Massachusetts Institute of Technology.
|
@ -1,196 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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_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_private.h"
|
||||
|
||||
/* Header format, from RFC 1035:
|
||||
* 1 1 1 1 1 1
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | ID |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* |QR| Opcode |AA|TC|RD|RA| Z | RCODE |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | QDCOUNT |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | ANCOUNT |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | NSCOUNT |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | ARCOUNT |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*
|
||||
* AA, TC, RA, and RCODE are only set in responses. Brief description
|
||||
* of the remaining fields:
|
||||
* ID Identifier to match responses with queries
|
||||
* QR Query (0) or response (1)
|
||||
* Opcode For our purposes, always QUERY
|
||||
* RD Recursion desired
|
||||
* Z Reserved (zero)
|
||||
* QDCOUNT Number of queries
|
||||
* ANCOUNT Number of answers
|
||||
* NSCOUNT Number of name server records
|
||||
* ARCOUNT Number of additional records
|
||||
*
|
||||
* Question format, from RFC 1035:
|
||||
* 1 1 1 1 1 1
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | |
|
||||
* / QNAME /
|
||||
* / /
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | QTYPE |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | QCLASS |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*
|
||||
* The query name is encoded as a series of labels, each represented
|
||||
* as a one-byte length (maximum 63) followed by the text of the
|
||||
* label. The list is terminated by a label of length zero (which can
|
||||
* be thought of as the root domain).
|
||||
*/
|
||||
|
||||
int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id,
|
||||
int rd, unsigned char **buf, int *buflen)
|
||||
{
|
||||
int len;
|
||||
unsigned char *q;
|
||||
const char *p;
|
||||
|
||||
/* Set our results early, in case we bail out early with an error. */
|
||||
*buflen = 0;
|
||||
*buf = NULL;
|
||||
|
||||
/* Compute the length of the encoded name so we can check buflen.
|
||||
* Start counting at 1 for the zero-length label at the end. */
|
||||
len = 1;
|
||||
for (p = name; *p; p++)
|
||||
{
|
||||
if (*p == '\\' && *(p + 1) != 0)
|
||||
p++;
|
||||
len++;
|
||||
}
|
||||
/* If there are n periods in the name, there are n + 1 labels, and
|
||||
* thus n + 1 length fields, unless the name is empty or ends with a
|
||||
* period. So add 1 unless name is empty or ends with a period.
|
||||
*/
|
||||
if (*name && *(p - 1) != '.')
|
||||
len++;
|
||||
|
||||
/* Immediately reject names that are longer than the maximum of 255
|
||||
* bytes that's specified in RFC 1035 ("To simplify implementations,
|
||||
* the total length of a domain name (i.e., label octets and label
|
||||
* length octets) is restricted to 255 octets or less."). We aren't
|
||||
* doing this just to be a stickler about RFCs. For names that are
|
||||
* too long, 'dnscache' closes its TCP connection to us immediately
|
||||
* (when using TCP) and ignores the request when using UDP, and
|
||||
* BIND's named returns ServFail (TCP or UDP). Sending a request
|
||||
* that we know will cause 'dnscache' to close the TCP connection is
|
||||
* painful, since that makes any other outstanding requests on that
|
||||
* connection fail. And sending a UDP request that we know
|
||||
* 'dnscache' will ignore is bad because resources will be tied up
|
||||
* until we time-out the request.
|
||||
*/
|
||||
if (len > MAXCDNAME)
|
||||
return ARES_EBADNAME;
|
||||
|
||||
*buflen = len + HFIXEDSZ + QFIXEDSZ;
|
||||
*buf = malloc(*buflen);
|
||||
if (!*buf)
|
||||
return ARES_ENOMEM;
|
||||
|
||||
/* Set up the header. */
|
||||
q = *buf;
|
||||
memset(q, 0, HFIXEDSZ);
|
||||
DNS_HEADER_SET_QID(q, id);
|
||||
DNS_HEADER_SET_OPCODE(q, QUERY);
|
||||
if (rd) {
|
||||
DNS_HEADER_SET_RD(q, 1);
|
||||
}
|
||||
else {
|
||||
DNS_HEADER_SET_RD(q, 0);
|
||||
}
|
||||
DNS_HEADER_SET_QDCOUNT(q, 1);
|
||||
|
||||
/* A name of "." is a screw case for the loop below, so adjust it. */
|
||||
if (strcmp(name, ".") == 0)
|
||||
name++;
|
||||
|
||||
/* Start writing out the name after the header. */
|
||||
q += HFIXEDSZ;
|
||||
while (*name)
|
||||
{
|
||||
if (*name == '.')
|
||||
return ARES_EBADNAME;
|
||||
|
||||
/* Count the number of bytes in this label. */
|
||||
len = 0;
|
||||
for (p = name; *p && *p != '.'; p++)
|
||||
{
|
||||
if (*p == '\\' && *(p + 1) != 0)
|
||||
p++;
|
||||
len++;
|
||||
}
|
||||
if (len > MAXLABEL)
|
||||
return ARES_EBADNAME;
|
||||
|
||||
/* Encode the length and copy the data. */
|
||||
*q++ = (unsigned char)len;
|
||||
for (p = name; *p && *p != '.'; p++)
|
||||
{
|
||||
if (*p == '\\' && *(p + 1) != 0)
|
||||
p++;
|
||||
*q++ = *p;
|
||||
}
|
||||
|
||||
/* Go to the next label and repeat, unless we hit the end. */
|
||||
if (!*p)
|
||||
break;
|
||||
name = p + 1;
|
||||
}
|
||||
|
||||
/* Add the zero-length label at the end. */
|
||||
*q++ = 0;
|
||||
|
||||
/* Finish off the question with the type and class. */
|
||||
DNS_QUESTION_SET_TYPE(q, type);
|
||||
DNS_QUESTION_SET_CLASS(q, dnsclass);
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 2010 by Daniel Stenberg
|
||||
*
|
||||
* 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"
|
||||
|
||||
#include "ares_nowarn.h"
|
||||
|
||||
#if (SIZEOF_INT == 2)
|
||||
# define CARES_MASK_SINT 0x7FFF
|
||||
# define CARES_MASK_UINT 0xFFFF
|
||||
#elif (SIZEOF_INT == 4)
|
||||
# define CARES_MASK_SINT 0x7FFFFFFF
|
||||
# define CARES_MASK_UINT 0xFFFFFFFF
|
||||
#elif (SIZEOF_INT == 8)
|
||||
# define CARES_MASK_SINT 0x7FFFFFFFFFFFFFFF
|
||||
# define CARES_MASK_UINT 0xFFFFFFFFFFFFFFFF
|
||||
#elif (SIZEOF_INT == 16)
|
||||
# define CARES_MASK_SINT 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
|
||||
# define CARES_MASK_UINT 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
|
||||
#endif
|
||||
|
||||
/*
|
||||
** size_t to signed int
|
||||
*/
|
||||
|
||||
int aresx_uztosi(size_t uznum)
|
||||
{
|
||||
#ifdef __INTEL_COMPILER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:810) /* conversion may lose significant bits */
|
||||
#endif
|
||||
|
||||
return (int)(uznum & (size_t) CARES_MASK_SINT);
|
||||
|
||||
#ifdef __INTEL_COMPILER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
#ifndef HEADER_CARES_NOWARN_H
|
||||
#define HEADER_CARES_NOWARN_H
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 2010 by Daniel Stenberg
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
int aresx_uztosi(size_t uznum);
|
||||
|
||||
#endif /* HEADER_CARES_NOWARN_H */
|
@ -1,128 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
* Copyright (C) 2008-2010 by Daniel Stenberg
|
||||
*
|
||||
* 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"
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_data.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
|
||||
int ares_get_servers(ares_channel channel,
|
||||
struct ares_addr_node **servers)
|
||||
{
|
||||
struct ares_addr_node *srvr_head = NULL;
|
||||
struct ares_addr_node *srvr_last = NULL;
|
||||
struct ares_addr_node *srvr_curr;
|
||||
int status = ARES_SUCCESS;
|
||||
int i;
|
||||
|
||||
if (!channel)
|
||||
return ARES_ENODATA;
|
||||
|
||||
for (i = 0; i < channel->nservers; i++)
|
||||
{
|
||||
/* Allocate storage for this server node appending it to the list */
|
||||
srvr_curr = ares_malloc_data(ARES_DATATYPE_ADDR_NODE);
|
||||
if (!srvr_curr)
|
||||
{
|
||||
status = ARES_ENOMEM;
|
||||
break;
|
||||
}
|
||||
if (srvr_last)
|
||||
{
|
||||
srvr_last->next = srvr_curr;
|
||||
}
|
||||
else
|
||||
{
|
||||
srvr_head = srvr_curr;
|
||||
}
|
||||
srvr_last = srvr_curr;
|
||||
|
||||
/* Fill this server node data */
|
||||
srvr_curr->family = channel->servers[i].addr.family;
|
||||
if (srvr_curr->family == AF_INET)
|
||||
memcpy(&srvr_curr->addrV4, &channel->servers[i].addr.addrV4,
|
||||
sizeof(srvr_curr->addrV4));
|
||||
else
|
||||
memcpy(&srvr_curr->addrV6, &channel->servers[i].addr.addrV6,
|
||||
sizeof(srvr_curr->addrV6));
|
||||
}
|
||||
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
if (srvr_head)
|
||||
{
|
||||
ares_free_data(srvr_head);
|
||||
srvr_head = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
*servers = srvr_head;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
int ares_set_servers(ares_channel channel,
|
||||
struct ares_addr_node *servers)
|
||||
{
|
||||
struct ares_addr_node *srvr;
|
||||
int num_srvrs = 0;
|
||||
int i;
|
||||
|
||||
if (ares_library_initialized() != ARES_SUCCESS)
|
||||
return ARES_ENOTINITIALIZED;
|
||||
|
||||
if (!channel)
|
||||
return ARES_ENODATA;
|
||||
|
||||
ares__destroy_servers_state(channel);
|
||||
|
||||
for (srvr = servers; srvr; srvr = srvr->next)
|
||||
{
|
||||
num_srvrs++;
|
||||
}
|
||||
|
||||
if (num_srvrs > 0)
|
||||
{
|
||||
/* Allocate storage for servers state */
|
||||
channel->servers = malloc(num_srvrs * sizeof(struct server_state));
|
||||
if (!channel->servers)
|
||||
{
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
channel->nservers = num_srvrs;
|
||||
/* Fill servers state address data */
|
||||
for (i = 0, srvr = servers; srvr; i++, srvr = srvr->next)
|
||||
{
|
||||
channel->servers[i].addr.family = srvr->family;
|
||||
if (srvr->family == AF_INET)
|
||||
memcpy(&channel->servers[i].addr.addrV4, &srvr->addrV4,
|
||||
sizeof(srvr->addrV4));
|
||||
else
|
||||
memcpy(&channel->servers[i].addr.addrV6, &srvr->addrV6,
|
||||
sizeof(srvr->addrV6));
|
||||
}
|
||||
/* Initialize servers state remaining data */
|
||||
ares__init_servers_state(channel);
|
||||
}
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_PARSE_A_REPLY 3 "25 July 1998"
|
||||
.SH NAME
|
||||
ares_parse_a_reply \- Parse a reply to a DNS query of type A
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_parse_a_reply(const unsigned char *\fIabuf\fP, int \fIalen\fP,
|
||||
.B struct hostent **\fIhost\fP,
|
||||
.B struct ares_addrttl *\fIaddrttls\fB, int *\fInaddrttls\fB);
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_parse_a_reply
|
||||
function parses the response to a query of type A into a
|
||||
.BR "struct hostent"
|
||||
and/or an array of
|
||||
.BR "struct ares_addrttls" .
|
||||
The parameters
|
||||
.I abuf
|
||||
and
|
||||
.I alen
|
||||
give the contents of the response. The result is stored in allocated
|
||||
memory and a pointer to it stored into the variable pointed to by
|
||||
.IR host ,
|
||||
if host is nonnull.
|
||||
It is the caller's responsibility to free the resulting host structure
|
||||
using
|
||||
.BR ares_free_hostent (3)
|
||||
when it is no longer needed.
|
||||
.PP
|
||||
If
|
||||
.IR addrttls
|
||||
and
|
||||
.IR naddrttls
|
||||
are both nonnull,
|
||||
then up to *naddrttls
|
||||
.BR "struct ares_addrttl"
|
||||
records are stored in the array pointed to by addrttls,
|
||||
and then *naddrttls is set to the number of records so stored.
|
||||
Note that the memory for these records is supplied by the caller.
|
||||
.SH RETURN VALUES
|
||||
.B ares_parse_a_reply
|
||||
can return any of the following values:
|
||||
.TP 15
|
||||
.B ARES_SUCCESS
|
||||
The response was successfully parsed.
|
||||
.TP 15
|
||||
.B ARES_EBADRESP
|
||||
The response was malformatted.
|
||||
.TP 15
|
||||
.B ARES_ENODATA
|
||||
The response did not contain an answer to the query.
|
||||
.TP 15
|
||||
.B ARES_ENOMEM
|
||||
Memory was exhausted.
|
||||
.SH SEE ALSO
|
||||
.BR ares_gethostbyname (3),
|
||||
.BR ares_free_hostent (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
@ -1,257 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_LIMITS_H
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_dns.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
int ares_parse_a_reply(const unsigned char *abuf, int alen,
|
||||
struct hostent **host,
|
||||
struct ares_addrttl *addrttls, int *naddrttls)
|
||||
{
|
||||
unsigned int qdcount, ancount;
|
||||
int status, i, rr_type, rr_class, rr_len, rr_ttl, naddrs;
|
||||
int cname_ttl = INT_MAX; /* the TTL imposed by the CNAME chain */
|
||||
int naliases;
|
||||
long len;
|
||||
const unsigned char *aptr;
|
||||
char *hostname, *rr_name, *rr_data, **aliases;
|
||||
struct in_addr *addrs;
|
||||
struct hostent *hostent;
|
||||
const int max_addr_ttls = (addrttls && naddrttls) ? *naddrttls : 0;
|
||||
|
||||
/* Set *host to NULL for all failure cases. */
|
||||
if (host)
|
||||
*host = NULL;
|
||||
/* Same with *naddrttls. */
|
||||
if (naddrttls)
|
||||
*naddrttls = 0;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Expand the name from the question, and skip past the question. */
|
||||
aptr = abuf + HFIXEDSZ;
|
||||
status = ares__expand_name_for_response(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;
|
||||
|
||||
if (host)
|
||||
{
|
||||
/* Allocate addresses and aliases; ancount gives an upper bound for
|
||||
both. */
|
||||
addrs = malloc(ancount * sizeof(struct in_addr));
|
||||
if (!addrs)
|
||||
{
|
||||
free(hostname);
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
aliases = malloc((ancount + 1) * sizeof(char *));
|
||||
if (!aliases)
|
||||
{
|
||||
free(hostname);
|
||||
free(addrs);
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
addrs = NULL;
|
||||
aliases = NULL;
|
||||
}
|
||||
|
||||
naddrs = 0;
|
||||
naliases = 0;
|
||||
|
||||
/* Examine each answer resource record (RR) in turn. */
|
||||
for (i = 0; i < (int)ancount; i++)
|
||||
{
|
||||
/* Decode the RR up to the data field. */
|
||||
status = ares__expand_name_for_response(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);
|
||||
rr_ttl = DNS_RR_TTL(aptr);
|
||||
aptr += RRFIXEDSZ;
|
||||
|
||||
if (rr_class == C_IN && rr_type == T_A
|
||||
&& rr_len == sizeof(struct in_addr)
|
||||
&& strcasecmp(rr_name, hostname) == 0)
|
||||
{
|
||||
if (addrs)
|
||||
{
|
||||
if (aptr + sizeof(struct in_addr) > abuf + alen)
|
||||
{
|
||||
status = ARES_EBADRESP;
|
||||
break;
|
||||
}
|
||||
memcpy(&addrs[naddrs], aptr, sizeof(struct in_addr));
|
||||
}
|
||||
if (naddrs < max_addr_ttls)
|
||||
{
|
||||
struct ares_addrttl * const at = &addrttls[naddrs];
|
||||
if (aptr + sizeof(struct in_addr) > abuf + alen)
|
||||
{
|
||||
status = ARES_EBADRESP;
|
||||
break;
|
||||
}
|
||||
memcpy(&at->ipaddr, aptr, sizeof(struct in_addr));
|
||||
at->ttl = rr_ttl;
|
||||
}
|
||||
naddrs++;
|
||||
status = ARES_SUCCESS;
|
||||
}
|
||||
|
||||
if (rr_class == C_IN && rr_type == T_CNAME)
|
||||
{
|
||||
/* Record the RR name as an alias. */
|
||||
if (aliases)
|
||||
aliases[naliases] = rr_name;
|
||||
else
|
||||
free(rr_name);
|
||||
naliases++;
|
||||
|
||||
/* Decode the RR data and replace the hostname with it. */
|
||||
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data,
|
||||
&len);
|
||||
if (status != ARES_SUCCESS)
|
||||
break;
|
||||
free(hostname);
|
||||
hostname = rr_data;
|
||||
|
||||
/* Take the min of the TTLs we see in the CNAME chain. */
|
||||
if (cname_ttl > rr_ttl)
|
||||
cname_ttl = rr_ttl;
|
||||
}
|
||||
else
|
||||
free(rr_name);
|
||||
|
||||
aptr += rr_len;
|
||||
if (aptr > abuf + alen)
|
||||
{
|
||||
status = ARES_EBADRESP;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (status == ARES_SUCCESS && naddrs == 0)
|
||||
status = ARES_ENODATA;
|
||||
if (status == ARES_SUCCESS)
|
||||
{
|
||||
/* We got our answer. */
|
||||
if (naddrttls)
|
||||
{
|
||||
const int n = naddrs < max_addr_ttls ? naddrs : max_addr_ttls;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
/* Ensure that each A TTL is no larger than the CNAME TTL. */
|
||||
if (addrttls[i].ttl > cname_ttl)
|
||||
addrttls[i].ttl = cname_ttl;
|
||||
}
|
||||
*naddrttls = n;
|
||||
}
|
||||
if (aliases)
|
||||
aliases[naliases] = NULL;
|
||||
if (host)
|
||||
{
|
||||
/* Allocate memory to build the host entry. */
|
||||
hostent = malloc(sizeof(struct hostent));
|
||||
if (hostent)
|
||||
{
|
||||
hostent->h_addr_list = malloc((naddrs + 1) * sizeof(char *));
|
||||
if (hostent->h_addr_list)
|
||||
{
|
||||
/* Fill in the hostent and return successfully. */
|
||||
hostent->h_name = hostname;
|
||||
hostent->h_aliases = aliases;
|
||||
hostent->h_addrtype = AF_INET;
|
||||
hostent->h_length = sizeof(struct in_addr);
|
||||
for (i = 0; i < naddrs; i++)
|
||||
hostent->h_addr_list[i] = (char *) &addrs[i];
|
||||
hostent->h_addr_list[naddrs] = NULL;
|
||||
*host = hostent;
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
free(hostent);
|
||||
}
|
||||
status = ARES_ENOMEM;
|
||||
}
|
||||
}
|
||||
if (aliases)
|
||||
{
|
||||
for (i = 0; i < naliases; i++)
|
||||
free(aliases[i]);
|
||||
free(aliases);
|
||||
}
|
||||
free(addrs);
|
||||
free(hostname);
|
||||
return status;
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
.\" $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_PARSE_AAAA_REPLY 3 "20 Nov 2009"
|
||||
.SH NAME
|
||||
ares_parse_aaaa_reply \- Parse a reply to a DNS query of type AAAA
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_parse_aaaa_reply(const unsigned char *\fIabuf\fP, int \fIalen\fP,
|
||||
.B struct hostent **\fIhost\fP,
|
||||
.B struct ares_addr6ttl *\fIaddrttls\fB, int *\fInaddrttls\fB);
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_parse_aaaa_reply
|
||||
function parses the response to a query of type AAAA into a
|
||||
.BR "struct hostent"
|
||||
and/or an array of
|
||||
.BR "struct ares_addr6ttl" .
|
||||
The parameters
|
||||
.I abuf
|
||||
and
|
||||
.I alen
|
||||
give the contents of the response. The result is stored in allocated
|
||||
memory and a pointer to it stored into the variable pointed to by
|
||||
.IR host ,
|
||||
if host is nonnull.
|
||||
It is the caller's responsibility to free the resulting host structure
|
||||
using
|
||||
.BR ares_free_hostent (3)
|
||||
when it is no longer needed.
|
||||
.PP
|
||||
If
|
||||
.IR addrttls
|
||||
and
|
||||
.IR naddrttls
|
||||
are both nonnull,
|
||||
then up to *naddrttls
|
||||
.BR "struct ares_addr6ttl"
|
||||
records are stored in the array pointed to by addrttls,
|
||||
and then *naddrttls is set to the number of records so stored.
|
||||
Note that the memory for these records is supplied by the caller.
|
||||
.SH RETURN VALUES
|
||||
.B ares_parse_aaaa_reply
|
||||
can return any of the following values:
|
||||
.TP 15
|
||||
.B ARES_SUCCESS
|
||||
The response was successfully parsed.
|
||||
.TP 15
|
||||
.B ARES_EBADRESP
|
||||
The response was malformatted.
|
||||
.TP 15
|
||||
.B ARES_ENODATA
|
||||
The response did not contain an answer to the query.
|
||||
.TP 15
|
||||
.B ARES_ENOMEM
|
||||
Memory was exhausted.
|
||||
.SH SEE ALSO
|
||||
.BR ares_gethostbyname (3),
|
||||
.BR ares_free_hostent (3)
|
||||
.SH AUTHOR
|
||||
Dominick Meglio
|
||||
.br
|
||||
Copyright 2005 by Dominick Meglio.
|
@ -1,257 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
* Copyright 2005 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.
|
||||
*/
|
||||
|
||||
#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
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_LIMITS_H
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_dns.h"
|
||||
#include "inet_net_pton.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
|
||||
struct hostent **host, struct ares_addr6ttl *addrttls,
|
||||
int *naddrttls)
|
||||
{
|
||||
unsigned int qdcount, ancount;
|
||||
int status, i, rr_type, rr_class, rr_len, rr_ttl, naddrs;
|
||||
int cname_ttl = INT_MAX; /* the TTL imposed by the CNAME chain */
|
||||
int naliases;
|
||||
long len;
|
||||
const unsigned char *aptr;
|
||||
char *hostname, *rr_name, *rr_data, **aliases;
|
||||
struct ares_in6_addr *addrs;
|
||||
struct hostent *hostent;
|
||||
const int max_addr_ttls = (addrttls && naddrttls) ? *naddrttls : 0;
|
||||
|
||||
/* Set *host to NULL for all failure cases. */
|
||||
if (host)
|
||||
*host = NULL;
|
||||
/* Same with *naddrttls. */
|
||||
if (naddrttls)
|
||||
*naddrttls = 0;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Expand the name from the question, and skip past the question. */
|
||||
aptr = abuf + HFIXEDSZ;
|
||||
status = ares__expand_name_for_response(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;
|
||||
|
||||
/* Allocate addresses and aliases; ancount gives an upper bound for both. */
|
||||
if (host)
|
||||
{
|
||||
addrs = malloc(ancount * sizeof(struct ares_in6_addr));
|
||||
if (!addrs)
|
||||
{
|
||||
free(hostname);
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
aliases = malloc((ancount + 1) * sizeof(char *));
|
||||
if (!aliases)
|
||||
{
|
||||
free(hostname);
|
||||
free(addrs);
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
addrs = NULL;
|
||||
aliases = NULL;
|
||||
}
|
||||
naddrs = 0;
|
||||
naliases = 0;
|
||||
|
||||
/* Examine each answer resource record (RR) in turn. */
|
||||
for (i = 0; i < (int)ancount; i++)
|
||||
{
|
||||
/* Decode the RR up to the data field. */
|
||||
status = ares__expand_name_for_response(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);
|
||||
rr_ttl = DNS_RR_TTL(aptr);
|
||||
aptr += RRFIXEDSZ;
|
||||
|
||||
if (rr_class == C_IN && rr_type == T_AAAA
|
||||
&& rr_len == sizeof(struct ares_in6_addr)
|
||||
&& strcasecmp(rr_name, hostname) == 0)
|
||||
{
|
||||
if (addrs)
|
||||
{
|
||||
if (aptr + sizeof(struct ares_in6_addr) > abuf + alen)
|
||||
{
|
||||
status = ARES_EBADRESP;
|
||||
break;
|
||||
}
|
||||
memcpy(&addrs[naddrs], aptr, sizeof(struct ares_in6_addr));
|
||||
}
|
||||
if (naddrs < max_addr_ttls)
|
||||
{
|
||||
struct ares_addr6ttl * const at = &addrttls[naddrs];
|
||||
if (aptr + sizeof(struct ares_in6_addr) > abuf + alen)
|
||||
{
|
||||
status = ARES_EBADRESP;
|
||||
break;
|
||||
}
|
||||
memcpy(&at->ip6addr, aptr, sizeof(struct ares_in6_addr));
|
||||
at->ttl = rr_ttl;
|
||||
}
|
||||
naddrs++;
|
||||
status = ARES_SUCCESS;
|
||||
}
|
||||
|
||||
if (rr_class == C_IN && rr_type == T_CNAME)
|
||||
{
|
||||
/* Record the RR name as an alias. */
|
||||
if (aliases)
|
||||
aliases[naliases] = rr_name;
|
||||
else
|
||||
free(rr_name);
|
||||
naliases++;
|
||||
|
||||
/* Decode the RR data and replace the hostname with it. */
|
||||
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data,
|
||||
&len);
|
||||
if (status != ARES_SUCCESS)
|
||||
break;
|
||||
free(hostname);
|
||||
hostname = rr_data;
|
||||
|
||||
/* Take the min of the TTLs we see in the CNAME chain. */
|
||||
if (cname_ttl > rr_ttl)
|
||||
cname_ttl = rr_ttl;
|
||||
}
|
||||
else
|
||||
free(rr_name);
|
||||
|
||||
aptr += rr_len;
|
||||
if (aptr > abuf + alen)
|
||||
{
|
||||
status = ARES_EBADRESP;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (status == ARES_SUCCESS && naddrs == 0)
|
||||
status = ARES_ENODATA;
|
||||
if (status == ARES_SUCCESS)
|
||||
{
|
||||
/* We got our answer. */
|
||||
if (naddrttls)
|
||||
{
|
||||
const int n = naddrs < max_addr_ttls ? naddrs : max_addr_ttls;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
/* Ensure that each A TTL is no larger than the CNAME TTL. */
|
||||
if (addrttls[i].ttl > cname_ttl)
|
||||
addrttls[i].ttl = cname_ttl;
|
||||
}
|
||||
*naddrttls = n;
|
||||
}
|
||||
if (aliases)
|
||||
aliases[naliases] = NULL;
|
||||
if (host)
|
||||
{
|
||||
/* Allocate memory to build the host entry. */
|
||||
hostent = malloc(sizeof(struct hostent));
|
||||
if (hostent)
|
||||
{
|
||||
hostent->h_addr_list = malloc((naddrs + 1) * sizeof(char *));
|
||||
if (hostent->h_addr_list)
|
||||
{
|
||||
/* Fill in the hostent and return successfully. */
|
||||
hostent->h_name = hostname;
|
||||
hostent->h_aliases = aliases;
|
||||
hostent->h_addrtype = AF_INET6;
|
||||
hostent->h_length = sizeof(struct ares_in6_addr);
|
||||
for (i = 0; i < naddrs; i++)
|
||||
hostent->h_addr_list[i] = (char *) &addrs[i];
|
||||
hostent->h_addr_list[naddrs] = NULL;
|
||||
*host = hostent;
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
free(hostent);
|
||||
}
|
||||
status = ARES_ENOMEM;
|
||||
}
|
||||
}
|
||||
if (aliases)
|
||||
{
|
||||
for (i = 0; i < naliases; i++)
|
||||
free(aliases[i]);
|
||||
free(aliases);
|
||||
}
|
||||
free(addrs);
|
||||
free(hostname);
|
||||
return status;
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_PARSE_NS_REPLY 3 "10 February 2007"
|
||||
.SH NAME
|
||||
ares_parse_ns_reply \- Parse a reply to a DNS query of type NS into a hostent
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_parse_ns_reply(const unsigned char *\fIabuf\fP, int \fIalen\fP,
|
||||
.B struct hostent **\fIhost\fP);
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_parse_ns_reply
|
||||
function parses the response to a query of type NS into a
|
||||
.BR "struct hostent" .
|
||||
The parameters
|
||||
.I abuf
|
||||
and
|
||||
.I alen
|
||||
give the contents of the response. The result is stored in allocated
|
||||
memory and a pointer to it stored into the variable pointed to by
|
||||
.IR host .
|
||||
The nameservers are stored into the
|
||||
.BR aliases
|
||||
field of the
|
||||
.IR host
|
||||
structure.
|
||||
It is the caller's responsibility to free the resulting host structure
|
||||
using
|
||||
.BR ares_free_hostent (3)
|
||||
when it is no longer needed.
|
||||
.SH RETURN VALUES
|
||||
.B ares_parse_ns_reply
|
||||
can return any of the following values:
|
||||
.TP 15
|
||||
.B ARES_SUCCESS
|
||||
The response was successfully parsed.
|
||||
.TP 15
|
||||
.B ARES_EBADRESP
|
||||
The response was malformatted.
|
||||
.TP 15
|
||||
.B ARES_ENODATA
|
||||
The response did not contain an answer to the query.
|
||||
.TP 15
|
||||
.B ARES_ENOMEM
|
||||
Memory was exhausted.
|
||||
.SH SEE ALSO
|
||||
.BR ares_query (3),
|
||||
.BR ares_free_hostent (3)
|
||||
.SH AUTHOR
|
||||
Written by Vlad Dinulescu <vlad.dinulescu@avira.com>, on behalf of AVIRA Gmbh http://www.avira.com
|
@ -1,182 +0,0 @@
|
||||
/* $Id */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ares_parse_ns_reply created by Vlad Dinulescu <vlad.dinulescu@avira.com>
|
||||
* on behalf of AVIRA Gmbh - http://www.avira.com
|
||||
*/
|
||||
|
||||
#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_private.h"
|
||||
|
||||
int ares_parse_ns_reply( const unsigned char* abuf, int alen,
|
||||
struct hostent** host )
|
||||
{
|
||||
unsigned int qdcount, ancount;
|
||||
int status, i, rr_type, rr_class, rr_len;
|
||||
int nameservers_num;
|
||||
long len;
|
||||
const unsigned char *aptr;
|
||||
char* hostname, *rr_name, *rr_data, **nameservers;
|
||||
struct hostent *hostent;
|
||||
|
||||
/* Set *host to NULL for all failure cases. */
|
||||
*host = 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;
|
||||
|
||||
/* Expand the name from the question, and skip past the question. */
|
||||
aptr = abuf + HFIXEDSZ;
|
||||
status = ares__expand_name_for_response( 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;
|
||||
|
||||
/* Allocate nameservers array; ancount gives an upper bound */
|
||||
nameservers = malloc( ( ancount + 1 ) * sizeof( char * ) );
|
||||
if ( !nameservers )
|
||||
{
|
||||
free( hostname );
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
nameservers_num = 0;
|
||||
|
||||
/* Examine each answer resource record (RR) in turn. */
|
||||
for ( i = 0; i < ( int ) ancount; i++ )
|
||||
{
|
||||
/* Decode the RR up to the data field. */
|
||||
status = ares__expand_name_for_response( 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;
|
||||
|
||||
if ( rr_class == C_IN && rr_type == T_NS )
|
||||
{
|
||||
/* Decode the RR data and add it to the nameservers list */
|
||||
status = ares__expand_name_for_response( aptr, abuf, alen, &rr_data,
|
||||
&len);
|
||||
if ( status != ARES_SUCCESS )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
nameservers[nameservers_num] = malloc(strlen(rr_data)+1);
|
||||
|
||||
if (nameservers[nameservers_num]==NULL)
|
||||
{
|
||||
free(rr_name);
|
||||
free(rr_data);
|
||||
status=ARES_ENOMEM;
|
||||
break;
|
||||
}
|
||||
strcpy(nameservers[nameservers_num],rr_data);
|
||||
free(rr_data);
|
||||
|
||||
nameservers_num++;
|
||||
}
|
||||
|
||||
free( rr_name );
|
||||
|
||||
aptr += rr_len;
|
||||
if ( aptr > abuf + alen )
|
||||
{
|
||||
status = ARES_EBADRESP;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( status == ARES_SUCCESS && nameservers_num == 0 )
|
||||
{
|
||||
status = ARES_ENODATA;
|
||||
}
|
||||
if ( status == ARES_SUCCESS )
|
||||
{
|
||||
/* We got our answer. Allocate memory to build the host entry. */
|
||||
nameservers[nameservers_num] = NULL;
|
||||
hostent = malloc( sizeof( struct hostent ) );
|
||||
if ( hostent )
|
||||
{
|
||||
hostent->h_addr_list = malloc( 1 * sizeof( char * ) );
|
||||
if ( hostent->h_addr_list )
|
||||
{
|
||||
/* Fill in the hostent and return successfully. */
|
||||
hostent->h_name = hostname;
|
||||
hostent->h_aliases = nameservers;
|
||||
hostent->h_addrtype = AF_INET;
|
||||
hostent->h_length = sizeof( struct in_addr );
|
||||
hostent->h_addr_list[0] = NULL;
|
||||
*host = hostent;
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
free( hostent );
|
||||
}
|
||||
status = ARES_ENOMEM;
|
||||
}
|
||||
for ( i = 0; i < nameservers_num; i++ )
|
||||
free( nameservers[i] );
|
||||
free( nameservers );
|
||||
free( hostname );
|
||||
return status;
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_PARSE_PTR_REPLY 3 "25 July 1998"
|
||||
.SH NAME
|
||||
ares_parse_ptr_reply \- Parse a reply to a DNS query of type PTR into a hostent
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_parse_ptr_reply(const unsigned char *\fIabuf\fP, int \fIalen\fP,
|
||||
.B const void *\fIaddr\fP, int \fIaddrlen\fP, int \fIfamily\fP,
|
||||
.B struct hostent **\fIhost\fP);
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_parse_ptr_reply
|
||||
function parses the response to a query of type PTR into a
|
||||
.BR "struct hostent" .
|
||||
The parameters
|
||||
.I abuf
|
||||
and
|
||||
.I alen
|
||||
give the contents of the response. The parameters
|
||||
.IR addr ,
|
||||
.IR addrlen ,
|
||||
and
|
||||
.I family
|
||||
specify which address was queried for; they are not used to verify the
|
||||
response, merely used to fill in the address of the
|
||||
.BR "struct hostent" .
|
||||
The resulting
|
||||
.B struct hostent
|
||||
is stored in allocated memory and a pointer to it stored into the
|
||||
variable pointed to by
|
||||
.IR host .
|
||||
It is the caller's responsibility to free the resulting host structure
|
||||
using
|
||||
.BR ares_free_hostent (3)
|
||||
when it is no longer needed.
|
||||
.SH RETURN VALUES
|
||||
.B ares_parse_ptr_reply
|
||||
can return any of the following values:
|
||||
.TP 15
|
||||
.B ARES_SUCCESS
|
||||
The response was successfully parsed.
|
||||
.TP 15
|
||||
.B ARES_EBADRESP
|
||||
The response was malformatted.
|
||||
.TP 15
|
||||
.B ARES_ENODATA
|
||||
The response did not contain an answer to the query.
|
||||
.TP 15
|
||||
.B ARES_ENOMEM
|
||||
Memory was exhausted.
|
||||
.SH SEE ALSO
|
||||
.BR ares_gethostbyaddr (3),
|
||||
.BR ares_free_hostent (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
@ -1,209 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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_NAMESER_H
|
||||
# include <arpa/nameser.h>
|
||||
#else
|
||||
# include "nameser.h"
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
|
||||
# include <arpa/nameser_compat.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "ares.h"
|
||||
#include "ares_dns.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
|
||||
int addrlen, int family, struct hostent **host)
|
||||
{
|
||||
unsigned int qdcount, ancount;
|
||||
int status, i, rr_type, rr_class, rr_len;
|
||||
long len;
|
||||
const unsigned char *aptr;
|
||||
char *ptrname, *hostname, *rr_name, *rr_data;
|
||||
struct hostent *hostent;
|
||||
int aliascnt = 0;
|
||||
int alias_alloc = 8;
|
||||
char ** aliases;
|
||||
|
||||
/* Set *host to NULL for all failure cases. */
|
||||
*host = 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;
|
||||
|
||||
/* Expand the name from the question, and skip past the question. */
|
||||
aptr = abuf + HFIXEDSZ;
|
||||
status = ares__expand_name_for_response(aptr, abuf, alen, &ptrname, &len);
|
||||
if (status != ARES_SUCCESS)
|
||||
return status;
|
||||
if (aptr + len + QFIXEDSZ > abuf + alen)
|
||||
{
|
||||
free(ptrname);
|
||||
return ARES_EBADRESP;
|
||||
}
|
||||
aptr += len + QFIXEDSZ;
|
||||
|
||||
/* Examine each answer resource record (RR) in turn. */
|
||||
hostname = NULL;
|
||||
aliases = malloc(alias_alloc * sizeof(char *));
|
||||
if (!aliases)
|
||||
{
|
||||
free(ptrname);
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
for (i = 0; i < (int)ancount; i++)
|
||||
{
|
||||
/* Decode the RR up to the data field. */
|
||||
status = ares__expand_name_for_response(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;
|
||||
|
||||
if (rr_class == C_IN && rr_type == T_PTR
|
||||
&& strcasecmp(rr_name, ptrname) == 0)
|
||||
{
|
||||
/* Decode the RR data and set hostname to it. */
|
||||
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data,
|
||||
&len);
|
||||
if (status != ARES_SUCCESS)
|
||||
break;
|
||||
if (hostname)
|
||||
free(hostname);
|
||||
hostname = rr_data;
|
||||
aliases[aliascnt] = malloc((strlen(rr_data)+1) * sizeof(char *));
|
||||
if (!aliases[aliascnt])
|
||||
{
|
||||
status = ARES_ENOMEM;
|
||||
break;
|
||||
}
|
||||
strncpy(aliases[aliascnt], rr_data, strlen(rr_data)+1);
|
||||
aliascnt++;
|
||||
if (aliascnt >= alias_alloc) {
|
||||
char **ptr;
|
||||
alias_alloc *= 2;
|
||||
ptr = realloc(aliases, alias_alloc * sizeof(char *));
|
||||
if(!ptr) {
|
||||
status = ARES_ENOMEM;
|
||||
break;
|
||||
}
|
||||
aliases = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (rr_class == C_IN && rr_type == T_CNAME)
|
||||
{
|
||||
/* Decode the RR data and replace ptrname with it. */
|
||||
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data,
|
||||
&len);
|
||||
if (status != ARES_SUCCESS)
|
||||
break;
|
||||
free(ptrname);
|
||||
ptrname = rr_data;
|
||||
}
|
||||
|
||||
free(rr_name);
|
||||
aptr += rr_len;
|
||||
if (aptr > abuf + alen)
|
||||
{
|
||||
status = ARES_EBADRESP;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (status == ARES_SUCCESS && !hostname)
|
||||
status = ARES_ENODATA;
|
||||
if (status == ARES_SUCCESS)
|
||||
{
|
||||
/* We got our answer. Allocate memory to build the host entry. */
|
||||
hostent = malloc(sizeof(struct hostent));
|
||||
if (hostent)
|
||||
{
|
||||
hostent->h_addr_list = malloc(2 * sizeof(char *));
|
||||
if (hostent->h_addr_list)
|
||||
{
|
||||
hostent->h_addr_list[0] = malloc(addrlen);
|
||||
if (hostent->h_addr_list[0])
|
||||
{
|
||||
hostent->h_aliases = malloc((aliascnt+1) * sizeof (char *));
|
||||
if (hostent->h_aliases)
|
||||
{
|
||||
/* Fill in the hostent and return successfully. */
|
||||
hostent->h_name = hostname;
|
||||
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;
|
||||
memcpy(hostent->h_addr_list[0], addr, addrlen);
|
||||
hostent->h_addr_list[1] = NULL;
|
||||
*host = hostent;
|
||||
free(aliases);
|
||||
free(ptrname);
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
free(hostent->h_addr_list[0]);
|
||||
}
|
||||
free(hostent->h_addr_list);
|
||||
}
|
||||
free(hostent);
|
||||
}
|
||||
status = ARES_ENOMEM;
|
||||
}
|
||||
for (i=0 ; i<aliascnt ; i++)
|
||||
if (aliases[i])
|
||||
free(aliases[i]);
|
||||
free(aliases);
|
||||
if (hostname)
|
||||
free(hostname);
|
||||
free(ptrname);
|
||||
return status;
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_PARSE_SRV_REPLY 3 "4 August 2009"
|
||||
.SH NAME
|
||||
ares_parse_srv_reply \- Parse a reply to a DNS query of type SRV
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_parse_srv_reply(const unsigned char* \fIabuf\fP, int \fIalen\fP,
|
||||
.B struct ares_srv_reply** \fIsrv_out\fP);
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_parse_srv_reply
|
||||
function parses the response to a query of type SRV into a
|
||||
linked list of
|
||||
.I struct ares_srv_reply
|
||||
The parameters
|
||||
.I abuf
|
||||
and
|
||||
.I alen
|
||||
give the contents of the response. The result is stored in allocated
|
||||
memory and a pointer to it stored into the variable pointed to by
|
||||
.IR srv_out .
|
||||
It is the caller's responsibility to free the resulting
|
||||
.IR srv_out
|
||||
structure when it is no longer needed using the function
|
||||
.B ares_free_data
|
||||
.PP
|
||||
The structure
|
||||
.I ares_srv_reply
|
||||
contains the following fields:
|
||||
.sp
|
||||
.in +4n
|
||||
.nf
|
||||
struct ares_srv_reply {
|
||||
struct ares_srv_reply *next;
|
||||
unsigned short weight;
|
||||
unsigned short priority;
|
||||
unsigned short port;
|
||||
char *host;
|
||||
};
|
||||
.fi
|
||||
.in
|
||||
.PP
|
||||
.SH RETURN VALUES
|
||||
.B ares_parse_srv_reply
|
||||
can return any of the following values:
|
||||
.TP 15
|
||||
.B ARES_SUCCESS
|
||||
The response was successfully parsed.
|
||||
.TP 15
|
||||
.B ARES_EBADRESP
|
||||
The response was malformatted.
|
||||
.TP 15
|
||||
.B ARES_ENODATA
|
||||
The response did not contain an answer to the query.
|
||||
.TP 15
|
||||
.B ARES_ENOMEM
|
||||
Memory was exhausted.
|
||||
.SH AVAILABILITY
|
||||
This function was first introduced in c-ares version 1.7.0.
|
||||
.SH SEE ALSO
|
||||
.BR ares_query (3)
|
||||
.BR ares_free_data (3)
|
||||
.SH AUTHOR
|
||||
Written by Jakub Hrozek <jhrozek@redhat.com>, on behalf of Red Hat, Inc http://www.redhat.com
|
@ -1,180 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* 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_SRV
|
||||
# define T_SRV 33 /* server selection */
|
||||
#endif
|
||||
|
||||
int
|
||||
ares_parse_srv_reply (const unsigned char *abuf, int alen,
|
||||
struct ares_srv_reply **srv_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_srv_reply *srv_head = NULL;
|
||||
struct ares_srv_reply *srv_last = NULL;
|
||||
struct ares_srv_reply *srv_curr;
|
||||
|
||||
/* Set *srv_out to NULL for all failure cases. */
|
||||
*srv_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 SRV record */
|
||||
if (rr_class == C_IN && rr_type == T_SRV)
|
||||
{
|
||||
/* parse the SRV record itself */
|
||||
if (rr_len < 6)
|
||||
{
|
||||
status = ARES_EBADRESP;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Allocate storage for this SRV answer appending it to the list */
|
||||
srv_curr = ares_malloc_data(ARES_DATATYPE_SRV_REPLY);
|
||||
if (!srv_curr)
|
||||
{
|
||||
status = ARES_ENOMEM;
|
||||
break;
|
||||
}
|
||||
if (srv_last)
|
||||
{
|
||||
srv_last->next = srv_curr;
|
||||
}
|
||||
else
|
||||
{
|
||||
srv_head = srv_curr;
|
||||
}
|
||||
srv_last = srv_curr;
|
||||
|
||||
vptr = aptr;
|
||||
srv_curr->priority = ntohs (*((unsigned short *)vptr));
|
||||
vptr += sizeof(unsigned short);
|
||||
srv_curr->weight = ntohs (*((unsigned short *)vptr));
|
||||
vptr += sizeof(unsigned short);
|
||||
srv_curr->port = ntohs (*((unsigned short *)vptr));
|
||||
vptr += sizeof(unsigned short);
|
||||
|
||||
status = ares_expand_name (vptr, abuf, alen, &srv_curr->host, &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 (srv_head)
|
||||
ares_free_data (srv_head);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* everything looks fine, return the data */
|
||||
*srv_out = srv_head;
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_PARSE_TXT_REPLY 3 "27 October 2009"
|
||||
.SH NAME
|
||||
ares_parse_txt_reply \- Parse a reply to a DNS query of type TXT
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_parse_txt_reply(const unsigned char* \fIabuf\fP, int \fIalen\fP,
|
||||
.B struct ares_txt_reply **\fItxt_out\fP);
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_parse_txt_reply
|
||||
function parses the response to a query of type TXT into a
|
||||
linked list of
|
||||
.I struct ares_txt_reply
|
||||
The parameters
|
||||
.I abuf
|
||||
and
|
||||
.I alen
|
||||
give the contents of the response. The result is stored in allocated
|
||||
memory and a pointer to it stored into the variable pointed to by
|
||||
.IR txt_out .
|
||||
It is the caller's responsibility to free the resulting
|
||||
.IR txt_out
|
||||
structure when it is no longer needed using the function
|
||||
.B ares_free_data
|
||||
.PP
|
||||
The structure
|
||||
.I ares_txt_reply
|
||||
contains the following fields:
|
||||
.sp
|
||||
.in +4n
|
||||
.nf
|
||||
struct ares_txt_reply {
|
||||
struct ares_txt_reply *next;
|
||||
unsigned int length;
|
||||
unsigned char *txt;
|
||||
};
|
||||
.fi
|
||||
.in
|
||||
.PP
|
||||
.SH RETURN VALUES
|
||||
.B ares_parse_txt_reply
|
||||
can return any of the following values:
|
||||
.TP 15
|
||||
.B ARES_SUCCESS
|
||||
The response was successfully parsed.
|
||||
.TP 15
|
||||
.B ARES_EBADRESP
|
||||
The response was malformatted.
|
||||
.TP 15
|
||||
.B ARES_ENODATA
|
||||
The response did not contain an answer to the query.
|
||||
.TP 15
|
||||
.B ARES_ENOMEM
|
||||
Memory was exhausted.
|
||||
.SH AVAILABILITY
|
||||
This function was first introduced in c-ares version 1.7.0.
|
||||
.SH SEE ALSO
|
||||
.BR ares_query (3)
|
||||
.BR ares_free_data (3)
|
||||
.SH AUTHOR
|
||||
Written by Jakub Hrozek <jhrozek@redhat.com>, on behalf of Red Hat, Inc http://www.redhat.com
|
||||
|
@ -1,202 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* 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
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.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_txt_reply (const unsigned char *abuf, int alen,
|
||||
struct ares_txt_reply **txt_out)
|
||||
{
|
||||
size_t substr_len, str_len;
|
||||
unsigned int qdcount, ancount, i;
|
||||
const unsigned char *aptr;
|
||||
const unsigned char *strptr;
|
||||
int status, rr_type, rr_class, rr_len;
|
||||
long len;
|
||||
char *hostname = NULL, *rr_name = NULL;
|
||||
struct ares_txt_reply *txt_head = NULL;
|
||||
struct ares_txt_reply *txt_last = NULL;
|
||||
struct ares_txt_reply *txt_curr;
|
||||
|
||||
/* Set *txt_out to NULL for all failure cases. */
|
||||
*txt_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 TXT record */
|
||||
if (rr_class == C_IN && rr_type == T_TXT)
|
||||
{
|
||||
/* Allocate storage for this TXT answer appending it to the list */
|
||||
txt_curr = ares_malloc_data(ARES_DATATYPE_TXT_REPLY);
|
||||
if (!txt_curr)
|
||||
{
|
||||
status = ARES_ENOMEM;
|
||||
break;
|
||||
}
|
||||
if (txt_last)
|
||||
{
|
||||
txt_last->next = txt_curr;
|
||||
}
|
||||
else
|
||||
{
|
||||
txt_head = txt_curr;
|
||||
}
|
||||
txt_last = txt_curr;
|
||||
|
||||
/*
|
||||
* There may be multiple substrings in a single TXT record. Each
|
||||
* substring may be up to 255 characters in length, with a
|
||||
* "length byte" indicating the size of the substring payload.
|
||||
* RDATA contains both the length-bytes and payloads of all
|
||||
* substrings contained therein.
|
||||
*/
|
||||
|
||||
/* Compute total length to allow a single memory allocation */
|
||||
strptr = aptr;
|
||||
while (strptr < (aptr + rr_len))
|
||||
{
|
||||
substr_len = (unsigned char)*strptr;
|
||||
txt_curr->length += substr_len;
|
||||
strptr += substr_len + 1;
|
||||
}
|
||||
|
||||
/* Including null byte */
|
||||
txt_curr->txt = malloc (txt_curr->length + 1);
|
||||
if (txt_curr->txt == NULL)
|
||||
{
|
||||
status = ARES_ENOMEM;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Step through the list of substrings, concatenating them */
|
||||
str_len = 0;
|
||||
strptr = aptr;
|
||||
while (strptr < (aptr + rr_len))
|
||||
{
|
||||
substr_len = (unsigned char)*strptr;
|
||||
strptr++;
|
||||
memcpy ((char *) txt_curr->txt + str_len, strptr, substr_len);
|
||||
str_len += substr_len;
|
||||
strptr += substr_len;
|
||||
}
|
||||
/* Make sure we NULL-terminate */
|
||||
*((char *) txt_curr->txt + txt_curr->length) = '\0';
|
||||
}
|
||||
|
||||
/* 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 (txt_head)
|
||||
ares_free_data (txt_head);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* everything looks fine, return the data */
|
||||
*txt_out = txt_head;
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
@ -1,345 +0,0 @@
|
||||
#ifndef __ARES_PRIVATE_H
|
||||
#define __ARES_PRIVATE_H
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
* Copyright (C) 2004-2010 by Daniel Stenberg
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Define WIN32 when build target is Win32 API
|
||||
*/
|
||||
|
||||
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
|
||||
#define WIN32
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#ifdef WATT32
|
||||
#include <tcp.h>
|
||||
#include <sys/ioctl.h>
|
||||
#define writev(s,v,c) writev_s(s,v,c)
|
||||
#define HAVE_WRITEV 1
|
||||
#endif
|
||||
|
||||
#ifdef NETWARE
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#define DEFAULT_TIMEOUT 5000 /* milliseconds */
|
||||
#define DEFAULT_TRIES 4
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE 0xffffffff
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) && !defined(WATT32)
|
||||
|
||||
#define IS_NT() ((int)GetVersion() > 0)
|
||||
#define WIN_NS_9X "System\\CurrentControlSet\\Services\\VxD\\MSTCP"
|
||||
#define WIN_NS_NT_KEY "System\\CurrentControlSet\\Services\\Tcpip\\Parameters"
|
||||
#define NAMESERVER "NameServer"
|
||||
#define DHCPNAMESERVER "DhcpNameServer"
|
||||
#define DATABASEPATH "DatabasePath"
|
||||
#define WIN_PATH_HOSTS "\\hosts"
|
||||
|
||||
#elif defined(WATT32)
|
||||
|
||||
#define PATH_RESOLV_CONF "/dev/ENV/etc/resolv.conf"
|
||||
|
||||
#elif defined(NETWARE)
|
||||
|
||||
#define PATH_RESOLV_CONF "sys:/etc/resolv.cfg"
|
||||
#define PATH_HOSTS "sys:/etc/hosts"
|
||||
|
||||
#elif defined(__riscos__)
|
||||
|
||||
#define PATH_HOSTS "InetDBase:Hosts"
|
||||
|
||||
#else
|
||||
|
||||
#define PATH_RESOLV_CONF "/etc/resolv.conf"
|
||||
#ifdef ETC_INET
|
||||
#define PATH_HOSTS "/etc/inet/hosts"
|
||||
#else
|
||||
#define PATH_HOSTS "/etc/hosts"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define ARES_ID_KEY_LEN 31
|
||||
|
||||
#include "ares_ipv6.h"
|
||||
#include "ares_llist.h"
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
# include "ares_strdup.h"
|
||||
# define strdup(ptr) ares_strdup(ptr)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRCASECMP
|
||||
# include "ares_strcasecmp.h"
|
||||
# define strcasecmp(p1,p2) ares_strcasecmp(p1,p2)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRNCASECMP
|
||||
# include "ares_strcasecmp.h"
|
||||
# define strncasecmp(p1,p2,n) ares_strncasecmp(p1,p2,n)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_WRITEV
|
||||
# include "ares_writev.h"
|
||||
# define writev(s,ptr,cnt) ares_writev(s,ptr,cnt)
|
||||
#endif
|
||||
|
||||
struct ares_addr {
|
||||
int family;
|
||||
union {
|
||||
struct in_addr addr4;
|
||||
struct ares_in6_addr addr6;
|
||||
} addr;
|
||||
};
|
||||
#define addrV4 addr.addr4
|
||||
#define addrV6 addr.addr6
|
||||
|
||||
struct query;
|
||||
|
||||
struct send_request {
|
||||
/* Remaining data to send */
|
||||
const unsigned char *data;
|
||||
size_t len;
|
||||
|
||||
/* The query for which we're sending this data */
|
||||
struct query* owner_query;
|
||||
/* The buffer we're using, if we have our own copy of the packet */
|
||||
unsigned char *data_storage;
|
||||
|
||||
/* Next request in queue */
|
||||
struct send_request *next;
|
||||
};
|
||||
|
||||
struct server_state {
|
||||
struct ares_addr addr;
|
||||
ares_socket_t udp_socket;
|
||||
ares_socket_t tcp_socket;
|
||||
|
||||
/* Mini-buffer for reading the length word */
|
||||
unsigned char tcp_lenbuf[2];
|
||||
int tcp_lenbuf_pos;
|
||||
int tcp_length;
|
||||
|
||||
/* Buffer for reading actual TCP data */
|
||||
unsigned char *tcp_buffer;
|
||||
int tcp_buffer_pos;
|
||||
|
||||
/* TCP output queue */
|
||||
struct send_request *qhead;
|
||||
struct send_request *qtail;
|
||||
|
||||
/* Which incarnation of this connection is this? We don't want to
|
||||
* retransmit requests into the very same socket, but if the server
|
||||
* closes on us and we re-open the connection, then we do want to
|
||||
* re-send. */
|
||||
int tcp_connection_generation;
|
||||
|
||||
/* Circular, doubly-linked list of outstanding queries to this server */
|
||||
struct list_node queries_to_server;
|
||||
|
||||
/* Link back to owning channel */
|
||||
ares_channel channel;
|
||||
|
||||
/* Is this server broken? We mark connections as broken when a
|
||||
* request that is queued for sending times out.
|
||||
*/
|
||||
int is_broken;
|
||||
};
|
||||
|
||||
/* State to represent a DNS query */
|
||||
struct query {
|
||||
/* Query ID from qbuf, for faster lookup, and current timeout */
|
||||
unsigned short qid;
|
||||
struct timeval timeout;
|
||||
|
||||
/*
|
||||
* Links for the doubly-linked lists in which we insert a query.
|
||||
* These circular, doubly-linked lists that are hash-bucketed based
|
||||
* the attributes we care about, help making most important
|
||||
* operations O(1).
|
||||
*/
|
||||
struct list_node queries_by_qid; /* hopefully in same cache line as qid */
|
||||
struct list_node queries_by_timeout;
|
||||
struct list_node queries_to_server;
|
||||
struct list_node all_queries;
|
||||
|
||||
/* Query buf with length at beginning, for TCP transmission */
|
||||
unsigned char *tcpbuf;
|
||||
int tcplen;
|
||||
|
||||
/* Arguments passed to ares_send() (qbuf points into tcpbuf) */
|
||||
const unsigned char *qbuf;
|
||||
int qlen;
|
||||
ares_callback callback;
|
||||
void *arg;
|
||||
|
||||
/* Query status */
|
||||
int try; /* Number of times we tried this query already. */
|
||||
int server; /* Server this query has last been sent to. */
|
||||
struct query_server_info *server_info; /* per-server state */
|
||||
int using_tcp;
|
||||
int error_status;
|
||||
int timeouts; /* number of timeouts we saw for this request */
|
||||
};
|
||||
|
||||
/* Per-server state for a query */
|
||||
struct query_server_info {
|
||||
int skip_server; /* should we skip server, due to errors, etc? */
|
||||
int tcp_connection_generation; /* into which TCP connection did we send? */
|
||||
};
|
||||
|
||||
/* An IP address pattern; matches an IP address X if X & mask == addr */
|
||||
#define PATTERN_MASK 0x1
|
||||
#define PATTERN_CIDR 0x2
|
||||
|
||||
struct apattern {
|
||||
union
|
||||
{
|
||||
struct in_addr addr4;
|
||||
struct ares_in6_addr addr6;
|
||||
} addr;
|
||||
union
|
||||
{
|
||||
struct in_addr addr4;
|
||||
struct ares_in6_addr addr6;
|
||||
unsigned short bits;
|
||||
} mask;
|
||||
int family;
|
||||
unsigned short type;
|
||||
};
|
||||
|
||||
typedef struct rc4_key
|
||||
{
|
||||
unsigned char state[256];
|
||||
unsigned char x;
|
||||
unsigned char y;
|
||||
} rc4_key;
|
||||
|
||||
struct ares_channeldata {
|
||||
/* Configuration data */
|
||||
int flags;
|
||||
int timeout; /* in milliseconds */
|
||||
int tries;
|
||||
int ndots;
|
||||
int rotate; /* if true, all servers specified are used */
|
||||
int udp_port;
|
||||
int tcp_port;
|
||||
int socket_send_buffer_size;
|
||||
int socket_receive_buffer_size;
|
||||
char **domains;
|
||||
int ndomains;
|
||||
struct apattern *sortlist;
|
||||
int nsort;
|
||||
char *lookups;
|
||||
|
||||
int optmask; /* the option bitfield passed in at init time */
|
||||
|
||||
/* Server addresses and communications state */
|
||||
struct server_state *servers;
|
||||
int nservers;
|
||||
|
||||
/* ID to use for next query */
|
||||
unsigned short next_id;
|
||||
/* key to use when generating new ids */
|
||||
rc4_key id_key;
|
||||
|
||||
/* Generation number to use for the next TCP socket open/close */
|
||||
int tcp_connection_generation;
|
||||
|
||||
/* The time at which we last called process_timeouts(). Uses integer seconds
|
||||
just to draw the line somewhere. */
|
||||
time_t last_timeout_processed;
|
||||
|
||||
/* Last server we sent a query to. */
|
||||
int last_server;
|
||||
|
||||
/* Circular, doubly-linked list of queries, bucketed various ways.... */
|
||||
/* All active queries in a single list: */
|
||||
struct list_node all_queries;
|
||||
/* Queries bucketed by qid, for quickly dispatching DNS responses: */
|
||||
#define ARES_QID_TABLE_SIZE 2048
|
||||
struct list_node queries_by_qid[ARES_QID_TABLE_SIZE];
|
||||
/* Queries bucketed by timeout, for quickly handling timeouts: */
|
||||
#define ARES_TIMEOUT_TABLE_SIZE 1024
|
||||
struct list_node queries_by_timeout[ARES_TIMEOUT_TABLE_SIZE];
|
||||
|
||||
ares_sock_state_cb sock_state_cb;
|
||||
void *sock_state_cb_data;
|
||||
|
||||
ares_sock_create_callback sock_create_cb;
|
||||
void *sock_create_cb_data;
|
||||
};
|
||||
|
||||
/* return true if now is exactly check time or later */
|
||||
int ares__timedout(struct timeval *now,
|
||||
struct timeval *check);
|
||||
/* add the specific number of milliseconds to the time in the first argument */
|
||||
int ares__timeadd(struct timeval *now,
|
||||
int millisecs);
|
||||
/* return time offset between now and (future) check, in milliseconds */
|
||||
long ares__timeoffset(struct timeval *now,
|
||||
struct timeval *check);
|
||||
/* returns ARES_SUCCESS if library has been initialized */
|
||||
int ares_library_initialized(void);
|
||||
void ares__rc4(rc4_key* key,unsigned char *buffer_ptr, int buffer_len);
|
||||
void ares__send_query(ares_channel channel, struct query *query,
|
||||
struct timeval *now);
|
||||
void ares__close_sockets(ares_channel channel, struct server_state *server);
|
||||
int ares__get_hostent(FILE *fp, int family, struct hostent **host);
|
||||
int ares__read_line(FILE *fp, char **buf, size_t *bufsize);
|
||||
void ares__free_query(struct query *query);
|
||||
unsigned short ares__generate_new_id(rc4_key* key);
|
||||
struct timeval ares__tvnow(void);
|
||||
int ares__expand_name_for_response(const unsigned char *encoded,
|
||||
const unsigned char *abuf, int alen,
|
||||
char **s, long *enclen);
|
||||
void ares__init_servers_state(ares_channel channel);
|
||||
void ares__destroy_servers_state(ares_channel channel);
|
||||
#if 0 /* Not used */
|
||||
long ares__tvdiff(struct timeval t1, struct timeval t2);
|
||||
#endif
|
||||
|
||||
#define ARES_SWAP_BYTE(a,b) \
|
||||
{ unsigned char swapByte = *(a); *(a) = *(b); *(b) = swapByte; }
|
||||
|
||||
#define SOCK_STATE_CALLBACK(c, s, r, w) \
|
||||
do { \
|
||||
if ((c)->sock_state_cb) \
|
||||
(c)->sock_state_cb((c)->sock_state_cb_data, (s), (r), (w)); \
|
||||
} while (0)
|
||||
|
||||
#ifdef CURLDEBUG
|
||||
/* This is low-level hard-hacking memory leak tracking and similar. Using the
|
||||
libcurl lowlevel code from within library is ugly and only works when
|
||||
c-ares is built and linked with a similarly curldebug-enabled libcurl,
|
||||
but we do this anyway for convenience. */
|
||||
#include "../lib/memdebug.h"
|
||||
#endif
|
||||
|
||||
#endif /* __ARES_PRIVATE_H */
|
@ -1,81 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_PROCESS 3 "25 July 1998"
|
||||
.SH NAME
|
||||
ares_process \- Process events for name resolution
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B void ares_process(ares_channel \fIchannel\fP, fd_set *\fIread_fds\fP,
|
||||
.B fd_set *\fIwrite_fds\fP)
|
||||
.fi
|
||||
.PP
|
||||
.B void ares_process_fd(ares_channel \fIchannel\fP,
|
||||
.B ares_socket_t \fIread_fd\fP,
|
||||
.B ares_socket_t \fIwrite_fd\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The \fBares_process(3)\fP function handles input/output events and timeouts
|
||||
associated with queries pending on the name service channel identified by
|
||||
.IR channel .
|
||||
The file descriptor sets pointed to by \fIread_fds\fP and \fIwrite_fds\fP
|
||||
should have file descriptors set in them according to whether the file
|
||||
descriptors specified by \fIares_fds(3)\fP are ready for reading and writing.
|
||||
(The easiest way to determine this information is to invoke
|
||||
.B select
|
||||
with a timeout no greater than the timeout given by \fIares_timeout(3)\fP ).
|
||||
.PP
|
||||
The
|
||||
.B ares_process
|
||||
function will invoke callbacks for pending queries if they complete
|
||||
successfully or fail.
|
||||
|
||||
\fBares_process_fd(3)\fP works the same way but acts and operates only on the
|
||||
specific file descriptors (sockets) you pass in to the function. Use
|
||||
ARES_SOCKET_BAD for "no action". This function is of course provided to allow
|
||||
users of c-ares to void select() in their applications and within c-ares.
|
||||
.SS EXAMPLE
|
||||
The following code fragment waits for all pending queries on a channel
|
||||
to complete:
|
||||
.PP
|
||||
.RS
|
||||
.nf
|
||||
int nfds, count;
|
||||
fd_set readers, writers;
|
||||
struct timeval tv, *tvp;
|
||||
|
||||
while (1)
|
||||
{
|
||||
FD_ZERO(&readers);
|
||||
FD_ZERO(&writers);
|
||||
nfds = ares_fds(channel, &readers, &writers);
|
||||
if (nfds == 0)
|
||||
break;
|
||||
tvp = ares_timeout(channel, NULL, &tv);
|
||||
count = select(nfds, &readers, &writers, NULL, tvp);
|
||||
ares_process(channel, &readers, &writers);
|
||||
}
|
||||
.fi
|
||||
.RE
|
||||
.SH SEE ALSO
|
||||
.BR ares_fds (3),
|
||||
.BR ares_timeout (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
1262
ares/ares_process.c
1262
ares/ares_process.c
File diff suppressed because it is too large
Load Diff
@ -1,147 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_QUERY 3 "24 July 1998"
|
||||
.SH NAME
|
||||
ares_query \- Initiate a single-question DNS query
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B typedef void (*ares_callback)(void *\fIarg\fP, int \fIstatus\fP,
|
||||
.B int \fItimeouts\fP, unsigned char *\fIabuf\fP, int \fIalen\fP)
|
||||
.PP
|
||||
.B void ares_query(ares_channel \fIchannel\fP, const char *\fIname\fP,
|
||||
.B int \fIdnsclass\fP, int \fItype\fP, ares_callback \fIcallback\fP,
|
||||
.B void *\fIarg\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_query
|
||||
function initiates a single-question DNS query on the name service
|
||||
channel identified by
|
||||
.IR channel .
|
||||
The parameter
|
||||
.I name
|
||||
gives the query name as a NUL-terminated C string of period-separated
|
||||
labels optionally ending with a period; periods and backslashes within
|
||||
a label must be escaped with a backslash. The parameters
|
||||
.I dnsclass
|
||||
and
|
||||
.I type
|
||||
give the class and type of the query using the values defined in
|
||||
.BR <arpa/nameser.h> .
|
||||
When the query is complete or has failed, the ares library will invoke
|
||||
.IR callback .
|
||||
Completion or failure of the query may happen immediately, or may
|
||||
happen during a later call to
|
||||
.BR ares_process (3)
|
||||
or
|
||||
.BR ares_destroy (3).
|
||||
.PP
|
||||
The callback argument
|
||||
.I arg
|
||||
is copied from the
|
||||
.B ares_query
|
||||
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 query completed successfully.
|
||||
.TP 19
|
||||
.B ARES_ENODATA
|
||||
The query completed but contains no answers.
|
||||
.TP 19
|
||||
.B ARES_EFORMERR
|
||||
The query completed but the server claims that the query was
|
||||
malformatted.
|
||||
.TP 19
|
||||
.B ARES_ESERVFAIL
|
||||
The query completed but the server claims to have experienced a
|
||||
failure. (This code can only occur if the
|
||||
.B ARES_FLAG_NOCHECKRESP
|
||||
flag was specified at channel initialization time; otherwise, such
|
||||
responses are ignored at the
|
||||
.BR ares_send (3)
|
||||
level.)
|
||||
.TP 19
|
||||
.B ARES_ENOTFOUND
|
||||
The query completed but the queried-for domain name was not found.
|
||||
.TP 19
|
||||
.B ARES_ENOTIMP
|
||||
The query completed but the server does not implement the operation
|
||||
requested by the query. (This code can only occur if the
|
||||
.B ARES_FLAG_NOCHECKRESP
|
||||
flag was specified at channel initialization time; otherwise, such
|
||||
responses are ignored at the
|
||||
.BR ares_send (3)
|
||||
level.)
|
||||
.TP 19
|
||||
.B ARES_EREFUSED
|
||||
The query completed but the server refused the query. (This code can
|
||||
only occur if the
|
||||
.B ARES_FLAG_NOCHECKRESP
|
||||
flag was specified at channel initialization time; otherwise, such
|
||||
responses are ignored at the
|
||||
.BR ares_send (3)
|
||||
level.)
|
||||
.TP 19
|
||||
.B ARES_EBADNAME
|
||||
The query name
|
||||
.I name
|
||||
could not be encoded as a domain name, either because it contained a
|
||||
zero-length label or because it contained a label of more than 63
|
||||
characters.
|
||||
.TP 19
|
||||
.B ARES_ETIMEOUT
|
||||
No name servers responded within the timeout period.
|
||||
.TP 19
|
||||
.B ARES_ECONNREFUSED
|
||||
No name servers could be contacted.
|
||||
.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.
|
||||
.PP
|
||||
The callback argument
|
||||
.I timeouts
|
||||
reports how many times a query timed out during the execution of the
|
||||
given request.
|
||||
.PP
|
||||
If the query completed (even if there was something wrong with it, as
|
||||
indicated by some of the above error codes), the callback argument
|
||||
.I abuf
|
||||
points to a result buffer of length
|
||||
.IR alen .
|
||||
If the query did not complete,
|
||||
.I abuf
|
||||
will be NULL and
|
||||
.I alen
|
||||
will be 0.
|
||||
.SH SEE ALSO
|
||||
.BR ares_process (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
@ -1,184 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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_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 "ares.h"
|
||||
#include "ares_dns.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
struct qquery {
|
||||
ares_callback callback;
|
||||
void *arg;
|
||||
};
|
||||
|
||||
static void qcallback(void *arg, int status, int timeouts, unsigned char *abuf, int alen);
|
||||
|
||||
void ares__rc4(rc4_key* key, unsigned char *buffer_ptr, int buffer_len)
|
||||
{
|
||||
unsigned char x;
|
||||
unsigned char y;
|
||||
unsigned char* state;
|
||||
unsigned char xorIndex;
|
||||
short counter;
|
||||
|
||||
x = key->x;
|
||||
y = key->y;
|
||||
|
||||
state = &key->state[0];
|
||||
for(counter = 0; counter < buffer_len; counter ++)
|
||||
{
|
||||
x = (unsigned char)((x + 1) % 256);
|
||||
y = (unsigned char)((state[x] + y) % 256);
|
||||
ARES_SWAP_BYTE(&state[x], &state[y]);
|
||||
|
||||
xorIndex = (unsigned char)((state[x] + state[y]) % 256);
|
||||
|
||||
buffer_ptr[counter] = (unsigned char)(buffer_ptr[counter]^state[xorIndex]);
|
||||
}
|
||||
key->x = x;
|
||||
key->y = y;
|
||||
}
|
||||
|
||||
static struct query* find_query_by_id(ares_channel channel, unsigned short id)
|
||||
{
|
||||
unsigned short qid;
|
||||
struct list_node* list_head;
|
||||
struct list_node* list_node;
|
||||
DNS_HEADER_SET_QID(((unsigned char*)&qid), id);
|
||||
|
||||
/* Find the query corresponding to this packet. */
|
||||
list_head = &(channel->queries_by_qid[qid % ARES_QID_TABLE_SIZE]);
|
||||
for (list_node = list_head->next; list_node != list_head;
|
||||
list_node = list_node->next)
|
||||
{
|
||||
struct query *q = list_node->data;
|
||||
if (q->qid == qid)
|
||||
return q;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* a unique query id is generated using an rc4 key. Since the id may already
|
||||
be used by a running query (as infrequent as it may be), a lookup is
|
||||
performed per id generation. In practice this search should happen only
|
||||
once per newly generated id
|
||||
*/
|
||||
static unsigned short generate_unique_id(ares_channel channel)
|
||||
{
|
||||
unsigned short id;
|
||||
|
||||
do {
|
||||
id = ares__generate_new_id(&channel->id_key);
|
||||
} while (find_query_by_id(channel, id));
|
||||
|
||||
return (unsigned short)id;
|
||||
}
|
||||
|
||||
void ares_query(ares_channel channel, const char *name, int dnsclass,
|
||||
int type, ares_callback callback, void *arg)
|
||||
{
|
||||
struct qquery *qquery;
|
||||
unsigned char *qbuf;
|
||||
int qlen, rd, status;
|
||||
|
||||
/* Compose the query. */
|
||||
rd = !(channel->flags & ARES_FLAG_NORECURSE);
|
||||
status = ares_mkquery(name, dnsclass, type, channel->next_id, rd, &qbuf,
|
||||
&qlen);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
if (qbuf != NULL) free(qbuf);
|
||||
callback(arg, status, 0, NULL, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
channel->next_id = generate_unique_id(channel);
|
||||
|
||||
/* Allocate and fill in the query structure. */
|
||||
qquery = malloc(sizeof(struct qquery));
|
||||
if (!qquery)
|
||||
{
|
||||
ares_free_string(qbuf);
|
||||
callback(arg, ARES_ENOMEM, 0, NULL, 0);
|
||||
return;
|
||||
}
|
||||
qquery->callback = callback;
|
||||
qquery->arg = arg;
|
||||
|
||||
/* Send it off. qcallback will be called when we get an answer. */
|
||||
ares_send(channel, qbuf, qlen, qcallback, qquery);
|
||||
ares_free_string(qbuf);
|
||||
}
|
||||
|
||||
static void qcallback(void *arg, int status, int timeouts, unsigned char *abuf, int alen)
|
||||
{
|
||||
struct qquery *qquery = (struct qquery *) arg;
|
||||
unsigned int ancount;
|
||||
int rcode;
|
||||
|
||||
if (status != ARES_SUCCESS)
|
||||
qquery->callback(qquery->arg, status, timeouts, abuf, alen);
|
||||
else
|
||||
{
|
||||
/* Pull the response code and answer count from the packet. */
|
||||
rcode = DNS_HEADER_RCODE(abuf);
|
||||
ancount = DNS_HEADER_ANCOUNT(abuf);
|
||||
|
||||
/* Convert errors. */
|
||||
switch (rcode)
|
||||
{
|
||||
case NOERROR:
|
||||
status = (ancount > 0) ? ARES_SUCCESS : ARES_ENODATA;
|
||||
break;
|
||||
case FORMERR:
|
||||
status = ARES_EFORMERR;
|
||||
break;
|
||||
case SERVFAIL:
|
||||
status = ARES_ESERVFAIL;
|
||||
break;
|
||||
case NXDOMAIN:
|
||||
status = ARES_ENOTFOUND;
|
||||
break;
|
||||
case NOTIMP:
|
||||
status = ARES_ENOTIMP;
|
||||
break;
|
||||
case REFUSED:
|
||||
status = ARES_EREFUSED;
|
||||
break;
|
||||
}
|
||||
qquery->callback(qquery->arg, status, timeouts, abuf, alen);
|
||||
}
|
||||
free(qquery);
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
#ifndef __CARES_RULES_H
|
||||
#define __CARES_RULES_H
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 2009 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ================================================================ */
|
||||
/* COMPILE TIME SANITY CHECKS */
|
||||
/* ================================================================ */
|
||||
|
||||
/*
|
||||
* NOTE 1:
|
||||
* -------
|
||||
*
|
||||
* All checks done in this file are intentionally placed in a public
|
||||
* header file which is pulled by ares.h when an application is
|
||||
* being built using an already built c-ares library. Additionally
|
||||
* this file is also included and used when building the library.
|
||||
*
|
||||
* If compilation fails on this file it is certainly sure that the
|
||||
* problem is elsewhere. It could be a problem in the ares_build.h
|
||||
* header file, or simply that you are using different compilation
|
||||
* settings than those used to build the library.
|
||||
*
|
||||
* Nothing in this file is intended to be modified or adjusted by the
|
||||
* c-ares library user nor by the c-ares library builder.
|
||||
*
|
||||
* Do not deactivate any check, these are done to make sure that the
|
||||
* library is properly built and used.
|
||||
*
|
||||
* You can find further help on the c-ares development mailing list:
|
||||
* http://cool.haxx.se/mailman/listinfo/c-ares/
|
||||
*
|
||||
* NOTE 2
|
||||
* ------
|
||||
*
|
||||
* Some of the following compile time checks are based on the fact
|
||||
* that the dimension of a constant array can not be a negative one.
|
||||
* In this way if the compile time verification fails, the compilation
|
||||
* will fail issuing an error. The error description wording is compiler
|
||||
* dependent but it will be quite similar to one of the following:
|
||||
*
|
||||
* "negative subscript or subscript is too large"
|
||||
* "array must have at least one element"
|
||||
* "-1 is an illegal array size"
|
||||
* "size of array is negative"
|
||||
*
|
||||
* If you are building an application which tries to use an already
|
||||
* built c-ares library and you are getting this kind of errors on
|
||||
* this file, it is a clear indication that there is a mismatch between
|
||||
* how the library was built and how you are trying to use it for your
|
||||
* application. Your already compiled or binary library provider is the
|
||||
* only one who can give you the details you need to properly use it.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Verify that some macros are actually defined.
|
||||
*/
|
||||
|
||||
#ifndef CARES_SIZEOF_LONG
|
||||
# error "CARES_SIZEOF_LONG definition is missing!"
|
||||
Error Compilation_aborted_CARES_SIZEOF_LONG_is_missing
|
||||
#endif
|
||||
|
||||
#ifndef CARES_TYPEOF_ARES_SOCKLEN_T
|
||||
# error "CARES_TYPEOF_ARES_SOCKLEN_T definition is missing!"
|
||||
Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_is_missing
|
||||
#endif
|
||||
|
||||
#ifndef CARES_SIZEOF_ARES_SOCKLEN_T
|
||||
# error "CARES_SIZEOF_ARES_SOCKLEN_T definition is missing!"
|
||||
Error Compilation_aborted_CARES_SIZEOF_ARES_SOCKLEN_T_is_missing
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Macros private to this header file.
|
||||
*/
|
||||
|
||||
#define CareschkszEQ(t, s) sizeof(t) == s ? 1 : -1
|
||||
|
||||
#define CareschkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1
|
||||
|
||||
/*
|
||||
* Verify that the size previously defined and expected for long
|
||||
* is the same as the one reported by sizeof() at compile time.
|
||||
*/
|
||||
|
||||
typedef char
|
||||
__cares_rule_01__
|
||||
[CareschkszEQ(long, CARES_SIZEOF_LONG)];
|
||||
|
||||
/*
|
||||
* Verify that the size previously defined and expected for
|
||||
* ares_socklen_t is actually the the same as the one reported
|
||||
* by sizeof() at compile time.
|
||||
*/
|
||||
|
||||
typedef char
|
||||
__cares_rule_02__
|
||||
[CareschkszEQ(ares_socklen_t, CARES_SIZEOF_ARES_SOCKLEN_T)];
|
||||
|
||||
/*
|
||||
* Verify at compile time that the size of ares_socklen_t as reported
|
||||
* by sizeof() is greater or equal than the one reported for int for
|
||||
* the current compilation.
|
||||
*/
|
||||
|
||||
typedef char
|
||||
__cares_rule_03__
|
||||
[CareschkszGE(ares_socklen_t, int)];
|
||||
|
||||
/* ================================================================ */
|
||||
/* EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS */
|
||||
/* ================================================================ */
|
||||
|
||||
/*
|
||||
* Get rid of macros private to this header file.
|
||||
*/
|
||||
|
||||
#undef CareschkszEQ
|
||||
#undef CareschkszGE
|
||||
|
||||
/*
|
||||
* Get rid of macros not intended to exist beyond this point.
|
||||
*/
|
||||
|
||||
#undef CARES_PULL_WS2TCPIP_H
|
||||
#undef CARES_PULL_SYS_TYPES_H
|
||||
#undef CARES_PULL_SYS_SOCKET_H
|
||||
|
||||
#undef CARES_TYPEOF_ARES_SOCKLEN_T
|
||||
|
||||
#endif /* __CARES_RULES_H */
|
@ -1,75 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_SAVE_OPTIONS 3 "5 March 2010"
|
||||
.SH NAME
|
||||
ares_save_options \- Save configuration values obtained from initialized ares_channel
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_save_options(ares_channel \fIchannel\fP, struct ares_options *\fIoptions\fP, int *\fIoptmask\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The \fBares_save_options(3)\fP function saves the channel data identified by
|
||||
.IR channel ,
|
||||
into the options struct identified by
|
||||
.IR options ,
|
||||
and saves the mask of options which are set to the integer
|
||||
pointer (passed by reference) identified by
|
||||
.IR optmask .
|
||||
|
||||
The resultant options and optmask are then able to be
|
||||
passed directly to ares_init_options. When the options
|
||||
are no longer needed, ares_destroy_options should be called
|
||||
to free any associated memory.
|
||||
.SH RETURN VALUES
|
||||
.B ares_save_options(3)
|
||||
can return any of the following values:
|
||||
.TP 15
|
||||
.B ARES_SUCCESS
|
||||
The channel data was successfuly stored
|
||||
.TP 15
|
||||
.B ARES_ENOMEM
|
||||
The memory was exhausted
|
||||
.TP 15
|
||||
.B ARES_ENODATA
|
||||
The channel data identified by
|
||||
.IR channel
|
||||
were invalid.
|
||||
.SH NOTE
|
||||
Since c-ares 1.6.0 the ares_options struct has been "locked" meaning that it
|
||||
won't be extended to cover new functions. This function will remain
|
||||
functioning, but it can only return config data that can be represented in
|
||||
this config struct, which may no longer be the complete set of config
|
||||
options. \fBares_dup(3)\fP will not have that restriction.
|
||||
|
||||
The ares_options struct can not handle potential IPv6 name servers the
|
||||
ares_channel might be configured to use. Function \fBares_save_options(3)\fP
|
||||
will only return IPv4 servers if any. In order to retrieve all name servers
|
||||
an ares_channel might be using, function \fBares_get_servers(3)\fP must be
|
||||
used instead.
|
||||
.SH SEE ALSO
|
||||
.BR ares_destroy_options (3),
|
||||
.BR ares_init_options (3),
|
||||
.BR ares_get_servers (3),
|
||||
.BR ares_dup (3)
|
||||
.SH AVAILABILITY
|
||||
ares_save_options(3) was added in c-ares 1.4.0
|
||||
.SH AUTHOR
|
||||
Brad House
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
@ -1,149 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_SEARCH 3 "24 July 1998"
|
||||
.SH NAME
|
||||
ares_search \- Initiate a DNS query with domain search
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B typedef void (*ares_callback)(void *\fIarg\fP, int \fIstatus\fP,
|
||||
.B int \fItimeouts\fP, unsigned char *\fIabuf\fP, int \fIalen\fP)
|
||||
.PP
|
||||
.B void ares_search(ares_channel \fIchannel\fP, const char *\fIname\fP,
|
||||
.B int \fIdnsclass\fP, int \fItype\fP, ares_callback \fIcallback\fP,
|
||||
.B void *\fIarg\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_search
|
||||
function initiates a series of single-question DNS queries on the name
|
||||
service channel identified by
|
||||
.IR channel ,
|
||||
using the channel's search domains as well as a host alias file given
|
||||
by the HOSTALIAS environment variable. The parameter
|
||||
.I name
|
||||
gives the alias name or the base of the query name as a NUL-terminated
|
||||
C string of period-separated labels; if it ends with a period, the
|
||||
channel's search domains will not be used. Periods and backslashes
|
||||
within a label must be escaped with a backslash. The parameters
|
||||
.I dnsclass
|
||||
and
|
||||
.I type
|
||||
give the class and type of the query using the values defined in
|
||||
.BR <arpa/nameser.h> .
|
||||
When the query sequence is complete or has failed, the ares library
|
||||
will invoke
|
||||
.IR callback .
|
||||
Completion or failure of the query sequence may happen immediately, or
|
||||
may happen during a later call to
|
||||
.BR ares_process (3)
|
||||
or
|
||||
.BR ares_destroy (3).
|
||||
.PP
|
||||
The callback argument
|
||||
.I arg
|
||||
is copied from the
|
||||
.B ares_search
|
||||
argument
|
||||
.IR arg .
|
||||
The callback argument
|
||||
.I status
|
||||
indicates whether the query sequence ended with a successful query
|
||||
and, if not, how the query sequence failed. It may have any of the
|
||||
following values:
|
||||
.TP 19
|
||||
.B ARES_SUCCESS
|
||||
A query completed successfully.
|
||||
.TP 19
|
||||
.B ARES_ENODATA
|
||||
No query completed successfully; when the query was tried without a
|
||||
search domain appended, a response was returned with no answers.
|
||||
.TP 19
|
||||
.B ARES_EFORMERR
|
||||
A query completed but the server claimed that the query was
|
||||
malformatted.
|
||||
.TP 19
|
||||
.B ARES_ESERVFAIL
|
||||
No query completed successfully; when the query was tried without a
|
||||
search domain appended, the server claimed to have experienced a
|
||||
failure. (This code can only occur if the
|
||||
.B ARES_FLAG_NOCHECKRESP
|
||||
flag was specified at channel initialization time; otherwise, such
|
||||
responses are ignored at the
|
||||
.BR ares_send (3)
|
||||
level.)
|
||||
.TP 19
|
||||
.B ARES_ENOTFOUND
|
||||
No query completed successfully; when the query was tried without a
|
||||
search domain appended, the server reported that the queried-for
|
||||
domain name was not found.
|
||||
.TP 19
|
||||
.B ARES_ENOTIMP
|
||||
A query completed but the server does not implement the operation
|
||||
requested by the query. (This code can only occur if the
|
||||
.B ARES_FLAG_NOCHECKRESP
|
||||
flag was specified at channel initialization time; otherwise, such
|
||||
responses are ignored at the
|
||||
.BR ares_send (3)
|
||||
level.)
|
||||
.TP 19
|
||||
.B ARES_EREFUSED
|
||||
A query completed but the server refused the query. (This code can
|
||||
only occur returned if the
|
||||
.B ARES_FLAG_NOCHECKRESP
|
||||
flag was specified at channel initialization time; otherwise, such
|
||||
responses are ignored at the
|
||||
.BR ares_send (3)
|
||||
level.)
|
||||
.TP 19
|
||||
.B ARES_TIMEOUT
|
||||
No name servers responded to a query within the timeout period.
|
||||
.TP 19
|
||||
.B ARES_ECONNREFUSED
|
||||
No name servers could be contacted.
|
||||
.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.
|
||||
.PP
|
||||
The callback argument
|
||||
.I timeouts
|
||||
reports how many times a query timed out during the execution of the
|
||||
given request.
|
||||
.PP
|
||||
If a query completed successfully, the callback argument
|
||||
.I abuf
|
||||
points to a result buffer of length
|
||||
.IR alen .
|
||||
If the query did not complete successfully,
|
||||
.I abuf
|
||||
will usually be NULL and
|
||||
.I alen
|
||||
will usually be 0, but in some cases an unsuccessful query result may
|
||||
be placed in
|
||||
.IR abuf .
|
||||
.SH SEE ALSO
|
||||
.BR ares_process (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
@ -1,323 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
struct search_query {
|
||||
/* Arguments passed to ares_search */
|
||||
ares_channel channel;
|
||||
char *name; /* copied into an allocated buffer */
|
||||
int dnsclass;
|
||||
int type;
|
||||
ares_callback callback;
|
||||
void *arg;
|
||||
|
||||
int status_as_is; /* error status from trying as-is */
|
||||
int next_domain; /* next search domain to try */
|
||||
int trying_as_is; /* current query is for name as-is */
|
||||
int timeouts; /* number of timeouts we saw for this request */
|
||||
int ever_got_nodata; /* did we ever get ARES_ENODATA along the way? */
|
||||
};
|
||||
|
||||
static void search_callback(void *arg, int status, int timeouts,
|
||||
unsigned char *abuf, int alen);
|
||||
static void end_squery(struct search_query *squery, int status,
|
||||
unsigned char *abuf, int alen);
|
||||
static int cat_domain(const char *name, const char *domain, char **s);
|
||||
static int single_domain(ares_channel channel, const char *name, char **s);
|
||||
|
||||
void ares_search(ares_channel channel, const char *name, int dnsclass,
|
||||
int type, ares_callback callback, void *arg)
|
||||
{
|
||||
struct search_query *squery;
|
||||
char *s;
|
||||
const char *p;
|
||||
int status, ndots;
|
||||
|
||||
/* If name only yields one domain to search, then we don't have
|
||||
* to keep extra state, so just do an ares_query().
|
||||
*/
|
||||
status = single_domain(channel, name, &s);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
callback(arg, status, 0, NULL, 0);
|
||||
return;
|
||||
}
|
||||
if (s)
|
||||
{
|
||||
ares_query(channel, s, dnsclass, type, callback, arg);
|
||||
free(s);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Allocate a search_query structure to hold the state necessary for
|
||||
* doing multiple lookups.
|
||||
*/
|
||||
squery = malloc(sizeof(struct search_query));
|
||||
if (!squery)
|
||||
{
|
||||
callback(arg, ARES_ENOMEM, 0, NULL, 0);
|
||||
return;
|
||||
}
|
||||
squery->channel = channel;
|
||||
squery->name = strdup(name);
|
||||
if (!squery->name)
|
||||
{
|
||||
free(squery);
|
||||
callback(arg, ARES_ENOMEM, 0, NULL, 0);
|
||||
return;
|
||||
}
|
||||
squery->dnsclass = dnsclass;
|
||||
squery->type = type;
|
||||
squery->status_as_is = -1;
|
||||
squery->callback = callback;
|
||||
squery->arg = arg;
|
||||
squery->timeouts = 0;
|
||||
squery->ever_got_nodata = 0;
|
||||
|
||||
/* Count the number of dots in name. */
|
||||
ndots = 0;
|
||||
for (p = name; *p; p++)
|
||||
{
|
||||
if (*p == '.')
|
||||
ndots++;
|
||||
}
|
||||
|
||||
/* If ndots is at least the channel ndots threshold (usually 1),
|
||||
* then we try the name as-is first. Otherwise, we try the name
|
||||
* as-is last.
|
||||
*/
|
||||
if (ndots >= channel->ndots)
|
||||
{
|
||||
/* Try the name as-is first. */
|
||||
squery->next_domain = 0;
|
||||
squery->trying_as_is = 1;
|
||||
ares_query(channel, name, dnsclass, type, search_callback, squery);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Try the name as-is last; start with the first search domain. */
|
||||
squery->next_domain = 1;
|
||||
squery->trying_as_is = 0;
|
||||
status = cat_domain(name, channel->domains[0], &s);
|
||||
if (status == ARES_SUCCESS)
|
||||
{
|
||||
ares_query(channel, s, dnsclass, type, search_callback, squery);
|
||||
free(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* failed, free the malloc()ed memory */
|
||||
free(squery->name);
|
||||
free(squery);
|
||||
callback(arg, status, 0, NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void search_callback(void *arg, int status, int timeouts,
|
||||
unsigned char *abuf, int alen)
|
||||
{
|
||||
struct search_query *squery = (struct search_query *) arg;
|
||||
ares_channel channel = squery->channel;
|
||||
char *s;
|
||||
|
||||
squery->timeouts += timeouts;
|
||||
|
||||
/* Stop searching unless we got a non-fatal error. */
|
||||
if (status != ARES_ENODATA && status != ARES_ESERVFAIL
|
||||
&& status != ARES_ENOTFOUND)
|
||||
end_squery(squery, status, abuf, alen);
|
||||
else
|
||||
{
|
||||
/* Save the status if we were trying as-is. */
|
||||
if (squery->trying_as_is)
|
||||
squery->status_as_is = status;
|
||||
|
||||
/*
|
||||
* If we ever get ARES_ENODATA along the way, record that; if the search
|
||||
* should run to the very end and we got at least one ARES_ENODATA,
|
||||
* then callers like ares_gethostbyname() may want to try a T_A search
|
||||
* even if the last domain we queried for T_AAAA resource records
|
||||
* returned ARES_ENOTFOUND.
|
||||
*/
|
||||
if (status == ARES_ENODATA)
|
||||
squery->ever_got_nodata = 1;
|
||||
|
||||
if (squery->next_domain < channel->ndomains)
|
||||
{
|
||||
/* Try the next domain. */
|
||||
status = cat_domain(squery->name,
|
||||
channel->domains[squery->next_domain], &s);
|
||||
if (status != ARES_SUCCESS)
|
||||
end_squery(squery, status, NULL, 0);
|
||||
else
|
||||
{
|
||||
squery->trying_as_is = 0;
|
||||
squery->next_domain++;
|
||||
ares_query(channel, s, squery->dnsclass, squery->type,
|
||||
search_callback, squery);
|
||||
free(s);
|
||||
}
|
||||
}
|
||||
else if (squery->status_as_is == -1)
|
||||
{
|
||||
/* Try the name as-is at the end. */
|
||||
squery->trying_as_is = 1;
|
||||
ares_query(channel, squery->name, squery->dnsclass, squery->type,
|
||||
search_callback, squery);
|
||||
}
|
||||
else {
|
||||
if (squery->status_as_is == ARES_ENOTFOUND && squery->ever_got_nodata) {
|
||||
end_squery(squery, ARES_ENODATA, NULL, 0);
|
||||
}
|
||||
else
|
||||
end_squery(squery, squery->status_as_is, NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void end_squery(struct search_query *squery, int status,
|
||||
unsigned char *abuf, int alen)
|
||||
{
|
||||
squery->callback(squery->arg, status, squery->timeouts, abuf, alen);
|
||||
free(squery->name);
|
||||
free(squery);
|
||||
}
|
||||
|
||||
/* Concatenate two domains. */
|
||||
static int cat_domain(const char *name, const char *domain, char **s)
|
||||
{
|
||||
size_t nlen = strlen(name);
|
||||
size_t dlen = strlen(domain);
|
||||
|
||||
*s = malloc(nlen + 1 + dlen + 1);
|
||||
if (!*s)
|
||||
return ARES_ENOMEM;
|
||||
memcpy(*s, name, nlen);
|
||||
(*s)[nlen] = '.';
|
||||
memcpy(*s + nlen + 1, domain, dlen);
|
||||
(*s)[nlen + 1 + dlen] = 0;
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
/* Determine if this name only yields one query. If it does, set *s to
|
||||
* the string we should query, in an allocated buffer. If not, set *s
|
||||
* to NULL.
|
||||
*/
|
||||
static int single_domain(ares_channel channel, const char *name, char **s)
|
||||
{
|
||||
size_t len = strlen(name);
|
||||
const char *hostaliases;
|
||||
FILE *fp;
|
||||
char *line = NULL;
|
||||
int status;
|
||||
size_t linesize;
|
||||
const char *p, *q;
|
||||
int error;
|
||||
|
||||
/* If the name contains a trailing dot, then the single query is the name
|
||||
* sans the trailing dot.
|
||||
*/
|
||||
if (name[len - 1] == '.')
|
||||
{
|
||||
*s = strdup(name);
|
||||
return (*s) ? ARES_SUCCESS : ARES_ENOMEM;
|
||||
}
|
||||
|
||||
if (!(channel->flags & ARES_FLAG_NOALIASES) && !strchr(name, '.'))
|
||||
{
|
||||
/* The name might be a host alias. */
|
||||
hostaliases = getenv("HOSTALIASES");
|
||||
if (hostaliases)
|
||||
{
|
||||
fp = fopen(hostaliases, "r");
|
||||
if (fp)
|
||||
{
|
||||
while ((status = ares__read_line(fp, &line, &linesize))
|
||||
== ARES_SUCCESS)
|
||||
{
|
||||
if (strncasecmp(line, name, len) != 0 ||
|
||||
!ISSPACE(line[len]))
|
||||
continue;
|
||||
p = line + len;
|
||||
while (ISSPACE(*p))
|
||||
p++;
|
||||
if (*p)
|
||||
{
|
||||
q = p + 1;
|
||||
while (*q && !ISSPACE(*q))
|
||||
q++;
|
||||
*s = malloc(q - p + 1);
|
||||
if (*s)
|
||||
{
|
||||
memcpy(*s, p, q - p);
|
||||
(*s)[q - p] = 0;
|
||||
}
|
||||
free(line);
|
||||
fclose(fp);
|
||||
return (*s) ? ARES_SUCCESS : ARES_ENOMEM;
|
||||
}
|
||||
}
|
||||
free(line);
|
||||
fclose(fp);
|
||||
if (status != ARES_SUCCESS)
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
error = errno;
|
||||
switch(error)
|
||||
{
|
||||
case ENOENT:
|
||||
case ESRCH:
|
||||
break;
|
||||
default:
|
||||
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
|
||||
error, strerror(error)));
|
||||
DEBUGF(fprintf(stderr, "Error opening file: %s\n",
|
||||
hostaliases));
|
||||
*s = NULL;
|
||||
return ARES_EFILE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (channel->flags & ARES_FLAG_NOSEARCH || channel->ndomains == 0)
|
||||
{
|
||||
/* No domain search to do; just try the name as-is. */
|
||||
*s = strdup(name);
|
||||
return (*s) ? ARES_SUCCESS : ARES_ENOMEM;
|
||||
}
|
||||
|
||||
*s = NULL;
|
||||
return ARES_SUCCESS;
|
||||
}
|
121
ares/ares_send.3
121
ares/ares_send.3
@ -1,121 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\"
|
||||
.\" 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_SEND 3 "25 July 1998"
|
||||
.SH NAME
|
||||
ares_send \- Initiate a DNS query
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B typedef void (*ares_callback)(void *\fIarg\fP, int \fIstatus\fP,
|
||||
.B int \fItimeouts\fP, unsigned char *\fIabuf\fP, int \fIalen\fP)
|
||||
.PP
|
||||
.B void ares_send(ares_channel \fIchannel\fP, const unsigned char *\fIqbuf\fP,
|
||||
.B int \fIqlen\fP, ares_callback \fIcallback\fP, void *\fIarg\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B ares_send
|
||||
function initiates a DNS query on the name service channel identified
|
||||
by
|
||||
.IR channel .
|
||||
The parameters
|
||||
.I qbuf
|
||||
and
|
||||
.I qlen
|
||||
give the DNS query, which should already have been formatted according
|
||||
to the DNS protocol. When the query is complete or has failed, the
|
||||
ares library will invoke
|
||||
.IR callback .
|
||||
Completion or failure of the query may happen immediately, or may
|
||||
happen during a later call to
|
||||
.BR ares_process (3)
|
||||
or
|
||||
.BR ares_destroy (3).
|
||||
.PP
|
||||
The callback argument
|
||||
.I arg
|
||||
is copied from the
|
||||
.B ares_send
|
||||
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 query completed.
|
||||
.TP 19
|
||||
.B ARES_EBADQUERY
|
||||
The query buffer was poorly formed (was not long enough for a DNS
|
||||
header or was too long for TCP transmission).
|
||||
.TP 19
|
||||
.B ARES_ETIMEOUT
|
||||
No name servers responded within the timeout period.
|
||||
.TP 19
|
||||
.B ARES_ECONNREFUSED
|
||||
No name servers could be contacted.
|
||||
.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.
|
||||
.PP
|
||||
The callback argument
|
||||
.I timeouts
|
||||
reports how many times a query timed out during the execution of the
|
||||
given request.
|
||||
.PP
|
||||
If the query completed, the callback argument
|
||||
.I abuf
|
||||
points to a result buffer of length
|
||||
.IR alen .
|
||||
If the query did not complete,
|
||||
.I abuf
|
||||
will be NULL and
|
||||
.I alen
|
||||
will be 0.
|
||||
.PP
|
||||
Unless the flag
|
||||
.B ARES_FLAG_NOCHECKRESP
|
||||
was set at channel initialization time,
|
||||
.B ares_send
|
||||
will normally ignore responses whose questions do not match the
|
||||
questions in
|
||||
.IR qbuf ,
|
||||
as well as responses with reply codes of
|
||||
.BR SERVFAIL ,
|
||||
.BR NOTIMP ,
|
||||
and
|
||||
.BR REFUSED .
|
||||
Unlike other query functions in the ares library, however,
|
||||
.B ares_send
|
||||
does not inspect the header of the reply packet to determine the error
|
||||
status, so a callback status of
|
||||
.B ARES_SUCCESS
|
||||
does not reflect as much about the response as for other query
|
||||
functions.
|
||||
.SH SEE ALSO
|
||||
.BR ares_process (3)
|
||||
.SH AUTHOR
|
||||
Greg Hudson, MIT Information Systems
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
135
ares/ares_send.c
135
ares/ares_send.c
@ -1,135 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* 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_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 <time.h>
|
||||
#include "ares.h"
|
||||
#include "ares_dns.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
|
||||
ares_callback callback, void *arg)
|
||||
{
|
||||
struct query *query;
|
||||
int i;
|
||||
struct timeval now;
|
||||
|
||||
/* Verify that the query is at least long enough to hold the header. */
|
||||
if (qlen < HFIXEDSZ || qlen >= (1 << 16))
|
||||
{
|
||||
callback(arg, ARES_EBADQUERY, 0, NULL, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Allocate space for query and allocated fields. */
|
||||
query = malloc(sizeof(struct query));
|
||||
if (!query)
|
||||
{
|
||||
callback(arg, ARES_ENOMEM, 0, NULL, 0);
|
||||
return;
|
||||
}
|
||||
query->tcpbuf = malloc(qlen + 2);
|
||||
if (!query->tcpbuf)
|
||||
{
|
||||
free(query);
|
||||
callback(arg, ARES_ENOMEM, 0, NULL, 0);
|
||||
return;
|
||||
}
|
||||
query->server_info = malloc(channel->nservers *
|
||||
sizeof(query->server_info[0]));
|
||||
if (!query->server_info)
|
||||
{
|
||||
free(query->tcpbuf);
|
||||
free(query);
|
||||
callback(arg, ARES_ENOMEM, 0, NULL, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Compute the query ID. Start with no timeout. */
|
||||
query->qid = (unsigned short)DNS_HEADER_QID(qbuf);
|
||||
query->timeout.tv_sec = 0;
|
||||
query->timeout.tv_usec = 0;
|
||||
|
||||
/* Form the TCP query buffer by prepending qlen (as two
|
||||
* network-order bytes) to qbuf.
|
||||
*/
|
||||
query->tcpbuf[0] = (unsigned char)((qlen >> 8) & 0xff);
|
||||
query->tcpbuf[1] = (unsigned char)(qlen & 0xff);
|
||||
memcpy(query->tcpbuf + 2, qbuf, qlen);
|
||||
query->tcplen = qlen + 2;
|
||||
|
||||
/* Fill in query arguments. */
|
||||
query->qbuf = query->tcpbuf + 2;
|
||||
query->qlen = qlen;
|
||||
query->callback = callback;
|
||||
query->arg = arg;
|
||||
|
||||
/* Initialize query status. */
|
||||
query->try = 0;
|
||||
|
||||
/* Choose the server to send the query to. If rotation is enabled, keep track
|
||||
* of the next server we want to use. */
|
||||
query->server = channel->last_server;
|
||||
if (channel->rotate == 1)
|
||||
channel->last_server = (channel->last_server + 1) % channel->nservers;
|
||||
|
||||
for (i = 0; i < channel->nservers; i++)
|
||||
{
|
||||
query->server_info[i].skip_server = 0;
|
||||
query->server_info[i].tcp_connection_generation = 0;
|
||||
}
|
||||
query->using_tcp = (channel->flags & ARES_FLAG_USEVC) || qlen > PACKETSZ;
|
||||
query->error_status = ARES_ECONNREFUSED;
|
||||
query->timeouts = 0;
|
||||
|
||||
/* Initialize our list nodes. */
|
||||
ares__init_list_node(&(query->queries_by_qid), query);
|
||||
ares__init_list_node(&(query->queries_by_timeout), query);
|
||||
ares__init_list_node(&(query->queries_to_server), query);
|
||||
ares__init_list_node(&(query->all_queries), query);
|
||||
|
||||
/* Chain the query into the list of all queries. */
|
||||
ares__insert_in_list(&(query->all_queries), &(channel->all_queries));
|
||||
/* Keep track of queries bucketed by qid, so we can process DNS
|
||||
* responses quickly.
|
||||
*/
|
||||
ares__insert_in_list(
|
||||
&(query->queries_by_qid),
|
||||
&(channel->queries_by_qid[query->qid % ARES_QID_TABLE_SIZE]));
|
||||
|
||||
/* Perform the first query action. */
|
||||
now = ares__tvnow();
|
||||
ares__send_query(channel, query, &now);
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.\" Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.\" Copyright (C) 2008-2010 by Daniel Stenberg
|
||||
.\"
|
||||
.\" 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_SET_SERVERS 3 "5 March 2010"
|
||||
.SH NAME
|
||||
ares_set_servers \- Initialize an ares_channel name servers configuration
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B int ares_set_servers(ares_channel \fIchannel\fP, struct ares_addr_node *\fIservers\fP)
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The \fBares_set_servers(3)\fP function initializes name servers configuration
|
||||
for the channel data identified by
|
||||
.IR channel ,
|
||||
from a
|
||||
.IR servers
|
||||
pointer to a linked list of ares_addr_node structs holding name servers
|
||||
address data.
|
||||
|
||||
The name server linked list pointer argument may be the result of a previous
|
||||
call to \fBares_get_servers(3)\fP or a linked list of ares_addr_node structs
|
||||
setup by other means.
|
||||
|
||||
This function replaces any potentially previously configured name servers
|
||||
with the ones given in the linked list. So, in order to configure a channel
|
||||
with more than one name server all the desired ones must be specified in a
|
||||
single list.
|
||||
|
||||
\fBares_set_servers(3)\fP does not take ownership of the linked list argument.
|
||||
The caller is responsible to free the linked list when no longer needed.
|
||||
|
||||
This function is capable of handling IPv4 and IPv6 name server
|
||||
addresses simultaneously, rendering \fBares_init_options(3)\fP with
|
||||
optmask \fBARES_OPT_SERVERS\fP functionally obsolete except for
|
||||
IPv4-only name server usage.
|
||||
|
||||
.SH RETURN VALUES
|
||||
.B ares_set_servers(3)
|
||||
may return any of the following values:
|
||||
.TP 15
|
||||
.B ARES_SUCCESS
|
||||
The name servers configuration was successfuly initialized.
|
||||
.TP 15
|
||||
.B ARES_ENOMEM
|
||||
The process's available memory was exhausted.
|
||||
.TP 15
|
||||
.B ARES_ENODATA
|
||||
The channel data identified by
|
||||
.IR channel
|
||||
was invalid.
|
||||
.TP 15
|
||||
.B ARES_ENOTINITIALIZED
|
||||
c-ares library initialization not yet performed.
|
||||
.SH SEE ALSO
|
||||
.BR ares_get_servers (3),
|
||||
.BR ares_init_options (3),
|
||||
.BR ares_dup(3)
|
||||
.SH AVAILABILITY
|
||||
ares_set_servers(3) was added in c-ares 1.7.1
|
||||
.SH AUTHOR
|
||||
Implementation of this function and associated library internals are based
|
||||
on code, comments and feedback provided November and December of 2008 by
|
||||
Daniel Stenberg, Gregor Jasny, Phil Blundell and Yang Tse, December 2009
|
||||
by Cedric Bail, February 2010 by Jakub Hrozek. On March 2010 Yang Tse
|
||||
shuffled all the bits and this function popped out.
|
||||
.br
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
.br
|
||||
Copyright (C) 2008-2010 by Daniel Stenberg
|
@ -1,29 +0,0 @@
|
||||
.\" $Id$
|
||||
.\"
|
||||
.TH ARES_SET_SOCKET_CALLBACK 3 "20 Nov 2009"
|
||||
.SH NAME
|
||||
ares_set_socket_callback \- Set a socket creation callback
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ares.h>
|
||||
.PP
|
||||
.B void ares_set_socket_callback(ares_channel \fIchannel\fP,
|
||||
ares_sock_create_callback \fIcallback\fP,
|
||||
void *\fIuserdata\fP)
|
||||
.PP
|
||||
.B cc file.c -lcares
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
This function sets a \fIcallback\fP in the given ares channel handle. This
|
||||
callback function will be invoked after the socket has been created, and
|
||||
connected to the remote server. The callback must return ARES_SUCCESS if
|
||||
things are fine, or use the standard ares error codes to signal errors
|
||||
back. Returned errors will abort the ares operation.
|
||||
.SH SEE ALSO
|
||||
.BR ares_init_options (3)
|
||||
.SH AVAILABILITY
|
||||
ares_set_socket_callback(3) was added in c-ares 1.6.0
|
||||
.SH AUTHOR
|
||||
Gregor Jasny
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user