1
0
mirror of https://frontier.innolan.net/rainlance/amiga-dnstracer.git synced 2025-11-22 16:39:48 +00:00

Initial commit

This commit is contained in:
Carsten
2016-02-22 19:36:59 +01:00
commit 42c7b62b68
19 changed files with 3599 additions and 0 deletions

88
CHANGES Normal file
View File

@ -0,0 +1,88 @@
$Id: CHANGES,v 1.26 2004/07/08 08:19:58 mavetju Exp $
Version 1.9:
- With the rollout of IPv6 for a.root-servers.net, it always
took the IPv6 address even if you used the -4 option.
- Fix false lame server issues with domains which have the
higher domain in it (command.com for example).
Version 1.8.1:
- Put back timeout command line parameter, it will be the
maximum time to wait instead of an increasing one.
Version 1.8:
- Better handling of timeout (instead of a static value,
start with five seconds and double it each retry)
- Warnings are printed if you receive a different RR type
than the one you asked for (for example when you ask for
an A record and receive a CNAME)
- Fixed problems when records received in the authority
field are shorter than the domain the nameserver is
authoritative for.
- When compiled without IPv6 support on an IPv6 capable
machine the machine tried to query the IPv6 translated
IPv5 address anyway.
- -C caches hosts which haven't answered too.
Version 1.7.1:
- Fix display of SOA serial number, by Janne Snabb
<snabb@epipe.com>
- Non-IPv6 builds should not use gethostbyname2()
Version 1.7:
- Removed a debug-line while doing PTR requests.
- Now IPv6 servers are traced too. Use -4 to disable it.
- Added -S option for specifying source IP address.
version 1.6:
- Added SOA record tracing
- Fixed a debug duplicate variable printing.
version 1.5:
- Sometimes it happened while tracing a name without
specifying a server it would return immediatly without
printing any information.
- names with a trailing dot are now handled correctly.
- warning from Kris Kennaway <kris@obsecurity.org> regarding
sprintf()'s without format-strings (yes, I feel ashamed).
- On request of Anthony DeRobertis <asd@suespammers.org>,
via Thomas Seyrat <tomasera@debian.org>, support for PTR
records.
version 1.4:
- Added -Wall to Makefile.am so at least I would get warnings
from my C compiler thank you. Removed some stupid unused
variables.
- Fixed big/little endian problem in the structs so that the
flags are looking allright now.
- Answers are displayed as authoritative or normal.
- Digging goes on until we have hit an authorative server.
- Info about which zone is being queried now.
version 1.3:
- added win32 support by Mike Black <mblack@csihq.com>
- fixed bug where the IP addresses in the resource records
wouldn't be used.
- when an authority NS record wouldn't have an additional
A record it can get multiple IP addresses when it resolves
the hostname in the gethostbyname(). This is now handled
correctly.
version 1.2:
- renamed into dnstracer due to clash with DJBDNS's dnstracer.
- dnstracer would segfault if nameserver name couldn't be
resolved (by Vilhelm Bergman <d96v@dtek.chalmers.se>)
- support for /etc/resolv.conf via a patch from Moritz
Barsnick <moritz@barsnick.net>
- -s . will take A.ROOT-SERVERS.NET
- autoconf/automake support... *shudder*
- support for different query-classes.
- Gerd v. Egidy <egidy@deam.de> gave it RPM capabilities
and checked the automake/autoconf construction.
version 1.1:
- fixed problems for big-endian little-endian machines.
- fixed linking problem on Solaris. Use Makefile.sun for them.
version 1.0:
- initial release

15
CONTACT Normal file
View File

@ -0,0 +1,15 @@
$Id: CONTACT,v 1.1 2002/01/21 00:40:23 mavetju Exp $
HOW TO CONTACT
Via email: edwin@mavetju.org
Via snail-mail: Edwin Groothuis
7 Islington Crescent
Greenacre NSW2190
AUSTRALIA
I have two mailing-lists:
announce@lists.mavetju.org <- low traffic announcements only
questions@lists.mavetju.org <- general questions
See http://www.mavetju.org/contacts.php on how to subscribe to them.

40
FILES Normal file
View File

@ -0,0 +1,40 @@
$Id: FILES,v 1.1 2002/01/25 01:40:09 mavetju Exp $
General
-------
CHANGES - Change log
CONTACT - How to contact me
FILES - This file
LICENSE - License under which this software is distributed
README - Small manual
Auto-configuration
------------------
Makefile.am - My Makefile-template
configure.in - My configure-template
Makefile.in - (Created by automake)
aclocal.m4 - (Needed by autoconf)
config.guess - (Needed by configure)
config.sub - (Needed by configure)
configure - Configure-file
depcomp - (Needed by configure)
install-sh - (Needed by configure)
missing - (Needed by configure)
mkinstalldirs - (Needed by configure)
Source-file
-----------
dnstracer.8 - Man-page, obtained from dnstracer.pod
dnstracer.c - The source-file
dnstracer.pod - The original man-file
dnstracer.spec - Needed for RPM creation
dnstracer_broken.h - Contains values for enumerations in case they
are not defined in arpa/nameser.h
WIN32 compatibility
-------------------
MSVC.BAT - Microsoft Visual C++ mini-makefile
getopt.c - Visual C++ doesn't provide these routines
getopt.h - Visual C++ doesn't provide these routines
(between brackets: not important, part of autoconfigure)

24
LICENSE Normal file
View File

@ -0,0 +1,24 @@
Copyright 2002, 2003, 2004 by Edwin Groothuis, edwin@mavetju.org
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. 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.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.

26
Makefile Normal file
View File

@ -0,0 +1,26 @@
# Portable Makefile generated by configure
all: dnstracer
CC = m68k-amigaos-gcc
CFLAGS = -O2 -noixemul -DAOS3 -I. -I.. -Iinclude -Wall -Werror
LDLIBS = -liberty -lm
config.h: inet_getaddrinfo.h
touch config.h
dnstracer.o: dnstracer.c config.h dnstracer_broken.h
dnstracer_amiga.o: dnstracer_amiga.c config.h
inet_getaddrinfo.o: inet_getaddrinfo.c config.h inet_getaddrinfo.h
dnstracer: dnstracer.o dnstracer_amiga.o inet_getaddrinfo.o
${CC} ${CFLAGS} -s -o dnstracer dnstracer.o dnstracer_amiga.o inet_getaddrinfo.o ${LDLIBS}
clean:
rm -f dnstracer.o dnstracer_amiga.o inet_getaddrinfo.o dnstracer
depend:
@echo Dependencies already done

33
README Normal file
View File

@ -0,0 +1,33 @@
$Id: README,v 1.8 2003/01/06 22:40:31 mavetju Exp $
WHAT IS DNSTRACER?
Dnstracer determines where a given Domain Name Server (DNS) gets
its information from, and follows the chain of DNS servers back to
the servers which know the data.
Its behaviour is similair to ntptrace(8), which does it for the
NTP protocol.
HOW TO INSTALL?
In theory, run 'configure', 'make' and 'make install' should be
enough to install the binary and the man-page. I've developed it
under FreeBSD 4.4 and tested it on Debian, SunOS and Solaris. Due
to the nature of autoconf and friends, you need GNU Make.
If you don't want to have IPv6 support in it, run configure with
the --disable-ipv6 option.
Windows users with Microsoft Visual C++ please use MSVB.BAT (supplied
by Mike Black <mblack@csihq.com>)
LICENSE
BSD license. See the file LICENSE for more information.
CONTACT
My email address is edwin@mavetju.org
My website is http://www.mavetju.org
Mailing-lists are available: http://www.mavetju.org/contacts.php

100
config.h Normal file
View File

@ -0,0 +1,100 @@
/* config.h. Generated by configure. */
/* config.h.in. Generated from configure.in by autoheader. */
/* Define to 1 if you have the <arpa/inet.h> header file. */
#define HAVE_ARPA_INET_H 1
/* Define to 1 if you have the `gethostbyname' function. */
#define HAVE_GETHOSTBYNAME 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1
/* Define to 1 if you have the <netdb.h> header file. */
#define HAVE_NETDB_H 1
/* Define to 1 if you have the <netinet/in.h> header file. */
#define HAVE_NETINET_IN_H 1
/* Define to 1 if you have the <resolv.h> header file. */
#define HAVE_RESOLV_H 1
/* Define to 1 if you have the `select' function. */
#define HAVE_SELECT 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strcasecmp' function. */
#define HAVE_STRCASECMP 1
/* Define to 1 if you have the `strchr' function. */
#define HAVE_STRCHR 1
/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/param.h> header file. */
#define HAVE_SYS_PARAM_H 1
/* Define to 1 if you have the <sys/socket.h> header file. */
#define HAVE_SYS_SOCKET_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to the full name of this package. */
#define PACKAGE_NAME "DNS Tracer"
/* Define to the version of this package. */
#define PACKAGE_VERSION "1.9"
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
#define WORDS_BIGENDIAN 1
#define NOIPV6 1
struct sockaddr_in6;
#ifndef PF_INET6
#define PF_INET6 10 /* IP version 6. */
#endif
#ifndef AF_INET6
#define AF_INET6 PF_INET6
#endif
int open_libs();
extern struct Library *SocketBase;
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#ifdef AOS3
#include <clib/exec_protos.h>
#include <clib/amitcp_protos.h>
#endif
#include "inet_getaddrinfo.h"

111
configure vendored Executable file
View File

@ -0,0 +1,111 @@
#!/bin/sh
#
# Copyright (c) 2016 Carsten Larsen
# Copyright (c) 2014 Poul-Henning Kamp
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. 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.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
#
set -e
HDRS='
config.h
inet_getaddrinfo.h
'
SRCS='
dnstracer.c
dnstracer_amiga.c
inet_getaddrinfo.c
'
if make -v 2>&1 | grep GNU > /dev/null 2>&1 ; then
echo "make is GNU make."
VALID=true
#else
# echo "Wrong version of make."
# VALID=false
fi
if $VALID ; then
(
echo '# Portable Makefile generated by configure'
echo ''
echo 'all: dnstracer'
echo ''
if [ -n "$1" ] && [ $1 = "AMIGA" ] ; then
echo 'CC = m68k-amigaos-gcc'
echo "CFLAGS = -O2 -noixemul -DAOS3 -I. -I.. -Iinclude -Wall -Werror"
echo "LDLIBS = -liberty -lm"
elif [ -n "$1" ] && [ $1 = "AROS" ] ; then
echo 'CC = gcc'
echo "CFLAGS = -O2 -DAROS -I. -Iinclude -Wall -Werror"
echo "LDLIBS = -lm"
else
echo "CFLAGS = -O2 -Wall -Werror"
echo "LDLIBS = -lm"
fi
echo ''
for f in ${HDRS}
do
b=`basename $f .h`
i=`sed -n -e '/#include.*"/{
s/"$//
s/.*"//
p
}' $f | sort -u`
if [ "x${i}" != "x" ] ; then
echo "${b}.h: " ${i}
echo " touch ${b}.h"
echo
fi
done
l=""
for f in ${SRCS}
do
b=`basename $f .c`
i=`sed -n -e '/#include.*"/{
s/"$//
s/.*"//
p
}' $f | sort -u`
echo "${b}.o: ${b}.c" ${i}
echo
l="${l} ${b}.o"
done
echo
echo "dnstracer: ${l}"
echo " \${CC} \${CFLAGS} -s -o dnstracer ${l} \${LDLIBS}"
echo
echo "clean:"
echo " rm -f ${l} dnstracer"
echo
echo "depend:"
echo " @echo Dependencies already done"
) > Makefile
echo "Makefile generated"
fi

225
dnstracer.8 Normal file
View File

@ -0,0 +1,225 @@
.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "DNSTRACER 8"
.TH DNSTRACER 8 "February 10, 2008" "February 10, 2008" "General Commands Manual"
.SH "NAME"
\&\fBdnstracer\fR \- trace a chain of DNS servers to the source
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
\&\fBdnstracer\fR [\fBoptions\fR] \fIname\fR
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
\&\fBdnstracer\fR determines where a given Domain Name Server (\s-1DNS\s0) gets
its information from, and follows the chain of \s-1DNS\s0 servers back to
the servers which know the data.
.PP
Options are:
.IP "\fB\-c\fR" 8
.IX Item "-c"
Disable local caching.
.IP "\fB\-C\fR" 8
.IX Item "-C"
Enable negative caching.
.IP "\fB\-o\fR" 8
.IX Item "-o"
Enable overview of received answers at the end.
.IP "\fB\-q \f(BIqueryclass\fB\fR" 8
.IX Item "-q queryclass"
Change the query\-class, default is A. You can either specify a
number of the type (if you're brave) or one of the following strings:
a, aaaa, a6, soa, cname, hinfo, mx, ns, txt and ptr.
.IP "\fB\-r \f(BIretries\fB\fR" 8
.IX Item "-r retries"
Number of retries for \s-1DNS\s0 requests, default 3.
.IP "\fB\-s \f(BIserver\fB\fR" 8
.IX Item "-s server"
\&\s-1DNS\s0 server to use for the initial request, default is aquired from
the system. If a dot is specified (.), A.ROOT\-SERVERS.NET will be
used.
.IP "\fB\-v\fR" 8
.IX Item "-v"
Be verbose on what sent or received.
.IP "\fB\-4\fR" 8
.IX Item "-4"
Use only IPv4 servers, don't query IPv6 servers (only available
when IPv6 support hasn't been disabled)
.IP "\fB\-S \f(BIsourceaddress\fB\fR" 8
.IX Item "-S sourceaddress"
Use this as source-address for the outgoing packets.
.SH "HOW IT WORKS"
.IX Header "HOW IT WORKS"
It sends the specified name-server a non-recursive request for the
name.
.PP
Non-recursive means: if the name-server knows it, it will return
the data requested. If the name-server doesn't know it, it will
return pointers to name-servers that are authoritive for the domain
part in the name or it will return the addresses of the root
name\-servers.
.PP
If the name server does returns an authoritative answer for the name,
the next server is queried. If it returns an non-authoritative
answer for the name, the name servers in the authority records will
be queried.
.PP
The program stops if all name-servers are queried.
.PP
Make sure the server you're querying doesn't do forwarding towards
other servers, as dnstracer is not able to detect this for you.
.PP
It detects so called lame servers, which are name-servers which has
been told to have information about a certain domain, but don't
have this information.
.SH "EXAMPLES"
.IX Header "EXAMPLES"
Search for the A record of www.mavetju.org on your local nameserver:
.PP
dnstracer www.mavetju.org
.PP
Search for the \s-1MX\s0 record of mavetju.org on the root\-nameservers:
.PP
dnstracer \f(CW\*(C`\-s\*(C'\fR . \f(CW\*(C`\-q\*(C'\fR mx mavetju.org
.PP
Search for the \s-1PTR\s0 record (hostname) of 212.204.230.141:
.PP
dnstracer \f(CW\*(C`\-q\*(C'\fR ptr 141.230.204.212.in\-addr.arpa
.PP
And for IPv6 addresses:
.PP
dnstracer \f(CW\*(C`\-q\*(C'\fR ptr \f(CW\*(C`\-s\*(C'\fR . \f(CW\*(C`\-o\*(C'\fR 2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.6.4.0.2.0.0.0.0.8.b.0.e.f.f.3.ip6.int
.SH "SEE ALSO"
.IX Header "SEE ALSO"
\&\fIntptrace\fR\|(8), \fItraceroute\fR\|(8), \fIdig\fR\|(1)
.SH "AUTHOR"
.IX Header "AUTHOR"
Edwin Groothuis, edwin@mavetju.org (http://www.mavetju.org)
.PP
See http://www.mavetju.org/contacts.php for mailing\-lists.

1682
dnstracer.c Normal file

File diff suppressed because it is too large Load Diff

3
dnstracer.kdev4 Normal file
View File

@ -0,0 +1,3 @@
[Project]
Manager=KDevCustomMakeManager
Name=dnstracer

38
dnstracer.spec Normal file
View File

@ -0,0 +1,38 @@
Summary: a tool to trace dns queries
Name: dnstracer
Version: 1.2.20020124
Release: 1
Copyright: BSD
Group: Applications/Internet
URL: http://www.mavetju.org/unix/general.php
Source: %{name}-%{version}.tar.gz
Patch0: dnstracer-1.2-am_req.patch
Buildroot: /tmp/%{name}-%{version}-root
BuildPrereq: automake autoconf perl
%description
dnstracer determines where a given Domain Name Server (DNS) gets
its information from, and follows the chain of DNS servers back to
the servers which know the data.
%prep
%setup -q
%patch0 -p1
%build
aclocal
automake
autoconf
./configure --prefix=%{_prefix} --mandir=%{_mandir}
make
%install
make install DESTDIR=$RPM_BUILD_ROOT
%clean
rm -fr $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%{_prefix}/bin
%{_mandir}/*

67
dnstracer_amiga.c Normal file
View File

@ -0,0 +1,67 @@
/*
* Written by Carsten Larsen.
* Public domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#define OPEN_ERROR "Cannot open %s.\n"
#define OPEN_VER_ERROR "Cannot open %s (%d.0)\n"
#define DOSLIB_NAME "dos.library"
#define DOSLIB_REV 37L
#define BSDLIB_NAME "bsdsocket.library"
#define BSDLIB_REV 03L
#include "config.h"
const char *vers = "\0$VER: " PACKAGE_NAME " " PACKAGE_VERSION " (18.02.2016)";
#ifdef AOS3
int h_errno;
#endif
struct Library *DOSBase = NULL;
struct Library *SocketBase = NULL;
void amiga_open_error(char *name)
{
printf(OPEN_ERROR, name);
}
void amiga_open_lib_error(char *name, int version)
{
printf(OPEN_VER_ERROR, name, version);
}
void close_libs()
{
if (DOSBase != NULL) {
CloseLibrary(DOSBase);
DOSBase = NULL;
}
if (SocketBase != NULL) {
CloseLibrary(SocketBase);
SocketBase = NULL;
}
}
int open_libs()
{
atexit(close_libs);
InitSemaphore(&GetaddrinfoSemaphore);
if(!(DOSBase = OpenLibrary((STRPTR)DOSLIB_NAME, DOSLIB_REV))) {
amiga_open_lib_error(DOSLIB_NAME, DOSLIB_REV);
return 5;
}
if(!(SocketBase = OpenLibrary((STRPTR)BSDLIB_NAME, BSDLIB_REV))) {
amiga_open_lib_error(BSDLIB_NAME, BSDLIB_REV);
return 5;
}
return 0;
}

61
dnstracer_broken.h Normal file
View File

@ -0,0 +1,61 @@
//
// $Id: dnstracer_broken.h,v 1.2 2002/01/22 01:54:46 mavetju Exp $
//
//
// Just when I thought life was good and everything was sweet, I found
// out that the /usr/include/arpa/nameserv.h on my FreeBSD box was a
// little bit different than that file on a Debian box.
//
// Let's assume that this is enough to convince everybody that these
// variables do exist.
//
#ifndef ns_t_a
#define ns_t_a 1
#endif
#ifndef ns_t_ns
#define ns_t_ns 2
#endif
#ifndef ns_t_cname
#define ns_t_cname 5
#endif
#ifndef ns_t_soa
#define ns_t_soa 6
#endif
#ifndef ns_t_ptr
#define ns_t_ptr 12
#endif
#ifndef ns_t_hinfo
#define ns_t_hinfo 13
#endif
#ifndef ns_t_mx
#define ns_t_mx 15
#endif
#ifndef ns_t_txt
#define ns_t_txt 16
#endif
#ifndef ns_t_aaaa
#define ns_t_aaaa 28
#endif
#ifndef ns_c_in
#define ns_c_in 1
#endif
#ifndef ns_c_chaos
#define ns_c_chaos 3
#endif
#ifndef ns_c_hs
#define ns_c_hs 4
#endif
#ifndef ns_c_none
#define ns_c_none 254
#endif
#ifndef ns_c_any
#define ns_c_any 255
#endif
#ifndef NS_MAXDNAME
#define NS_MAXDNAME 1024
#endif

View File

@ -0,0 +1,116 @@
/*
* Copyright (c) 2015 Carsten Larsen
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
*/
#ifndef _SOCKET_AMITCP_H
#define _SOCKET_AMITCP_H
//--------------------------------------------------------------------------//
#define AMITCP_BASE_NAME SocketBase
#include "inline/amitcp.h"
//--------------------------------------------------------------------------//
#define socket Socket
#define bind Bind
#define listen Listen
#define accept Accept
#define connect Connect
#define send Send
#define sendto SendTo
#define sendmsg SendMsg
#define recv Recv
#define recvfrom RecvFrom
#define recvmsg RecvMsg
#define select Select
#define shutdown ShutDown
#define setsockopt SetSockOpt
#define getsockopt GetSockOpt
#define getsockname GetSockName
#define getpeername GetPeerName
#define inet_addr Inet_Addr
#define inet_network Inet_Network
#define inet_ntoa Inet_NtoA
#define gethostbyname GetHostByName
#define gethostbyaddr GetHostByAddr
#define getnetbyname GetNetByName
#define getnetbyaddr GetNetByAddr
#define getservbyname GetServByName
#define getservbyport GetServByPort
#define getprotobyname GetProtoByName
#define getprotobynumber GetProtoByNumber
#define getdtablesize GetDTableSize
#define gethostname GetHostName
#define gethostid GetHostId
#define vsyslog SyslogA
#define syslog Syslog
//--------------------------------------------------------------------------//
#define Accept TCP_Accept
#define Bind TCP_Bind
#define CloseSocket TCP_CloseSocket
#define Connect TCP_Connect
#define Dup2Socket TCP_Dup2Socket
#define Errno TCP_Errno
#define GetDTableSize TCP_GetDTableSize
#define GetHostByAddr TCP_GetHostByAddr
#define GetHostByName TCP_GetHostByName
#define GetHostId TCP_GetHostId
#define GetHostName TCP_GetHostName
#define GetNetByAddr TCP_GetNetByAddr
#define GetNetByName TCP_GetNetByName
#define GetPeerName TCP_GetPeerName
#define GetProtoByName TCP_GetProtoByName
#define GetProtoByNumber TCP_GetProtoByNumber
#define GetServByName TCP_GetServByName
#define GetServByPort TCP_GetServByPort
#define GetSockName TCP_GetSockName
#define GetSockOpt TCP_GetSockOpt
#define GetSocketEvents TCP_GetSocketEvents
#define Inet_Addr TCP_Inet_Addr
#define Inet_LnaOf TCP_Inet_LnaOf
#define Inet_MakeAddr TCP_Inet_MakeAddr
#define Inet_NetOf TCP_Inet_NetOf
#define Inet_Network TCP_Inet_Network
#define Inet_NtoA(x) TCP_Inet_NtoA((x).s_addr)
#define IoctlSocket TCP_IoctlSocket
#define Listen TCP_Listen
#define ObtainSocket TCP_ObtainSocket
#define Recv TCP_Recv
#define RecvFrom TCP_RecvFrom
#define RecvMsg TCP_RecvMsg
#define ReleaseCopyOfSocket TCP_ReleaseCopyOfSocket
#define ReleaseSocket TCP_ReleaseSocket
#define Send TCP_Send
#define SendMsg TCP_SendMsg
#define SendTo TCP_SendTo
#define SetErrnoPtr TCP_SetErrnoPtr
#define SetSockOpt TCP_SetSockOpt
#define SetSocketSignals TCP_SetSocketSignals
#define ShutDown TCP_ShutDown
#define Socket TCP_Socket
#define SocketBaseTagList TCP_SocketBaseTagList
#define SocketBaseTags TCP_SocketBaseTags
#define SyslogA TCP_SyslogA
#define WaitSelect TCP_WaitSelect
#define Select(n,r,w,e,t) TCP_WaitSelect(n,r,w,e,t,0)
//--------------------------------------------------------------------------//
#endif

203
include/inline/amitcp.h Normal file
View File

@ -0,0 +1,203 @@
/* Automatically generated header! Do not edit! */
#ifndef _INLINE_AMITCP_H
#define _INLINE_AMITCP_H
#ifndef __INLINE_MACROS_H
#include <inline/macros.h>
#endif /* !__INLINE_MACROS_H */
#ifndef AMITCP_BASE_NAME
#define AMITCP_BASE_NAME lss->lx_BsdSocketBase
#endif /* !AMITCP_BASE_NAME */
#define TCP_Accept(s, addr, addrlen) \
LP3(0x30, LONG, TCP_Accept, LONG, s, d0, struct sockaddr *, addr, a0, int *, addrlen, a1, \
, AMITCP_BASE_NAME)
#define TCP_Bind(s, name, namelen) \
LP3(0x24, LONG, TCP_Bind, LONG, s, d0, const struct sockaddr *, name, a0, LONG, namelen, d1, \
, AMITCP_BASE_NAME)
#define TCP_CloseSocket(d) \
LP1(0x78, LONG, TCP_CloseSocket, LONG, d, d0, \
, AMITCP_BASE_NAME)
#define TCP_Connect(s, name, namelen) \
LP3(0x36, LONG, TCP_Connect, LONG, s, d0, const struct sockaddr *, name, a0, LONG, namelen, d1, \
, AMITCP_BASE_NAME)
#define TCP_Dup2Socket(fd1, fd2) \
LP2(0x108, LONG, TCP_Dup2Socket, LONG, fd1, d0, LONG, fd2, d1, \
, AMITCP_BASE_NAME)
#define TCP_Errno() \
LP0(0xa2, LONG, TCP_Errno, \
, AMITCP_BASE_NAME)
#define TCP_GetDTableSize() \
LP0(0x8a, LONG, TCP_GetDTableSize, \
, AMITCP_BASE_NAME)
#define TCP_GetHostByAddr(addr, len, type) \
LP3(0xd8, struct hostent *, TCP_GetHostByAddr, const UBYTE *, addr, a0, LONG, len, d0, LONG, type, d1, \
, AMITCP_BASE_NAME)
#define TCP_GetHostByName(name) \
LP1(0xd2, struct hostent *, TCP_GetHostByName, const UBYTE *, name, a0, \
, AMITCP_BASE_NAME)
#define TCP_GetHostId() \
LP0(0x120, ULONG, TCP_GetHostId, \
, AMITCP_BASE_NAME)
#define TCP_GetHostName(hostname, size) \
LP2(0x11a, LONG, TCP_GetHostName, STRPTR, hostname, a0, LONG, size, d0, \
, AMITCP_BASE_NAME)
#define TCP_GetNetByAddr(net, type) \
LP2(0xe4, struct netent *, TCP_GetNetByAddr, LONG, net, d0, LONG, type, d1, \
, AMITCP_BASE_NAME)
#define TCP_GetNetByName(name) \
LP1(0xde, struct netent *, TCP_GetNetByName, const UBYTE *, name, a0, \
, AMITCP_BASE_NAME)
#define TCP_GetPeerName(s, hostname, namelen) \
LP3(0x6c, LONG, TCP_GetPeerName, LONG, s, d0, struct sockaddr *, hostname, a0, int *, namelen, a1, \
, AMITCP_BASE_NAME)
#define TCP_GetProtoByName(name) \
LP1(0xf6, struct protoent *, TCP_GetProtoByName, const UBYTE *, name, a0, \
, AMITCP_BASE_NAME)
#define TCP_GetProtoByNumber(proto) \
LP1(0xfc, struct protoent *, TCP_GetProtoByNumber, LONG, proto, d0, \
, AMITCP_BASE_NAME)
#define TCP_GetServByName(name, proto) \
LP2(0xea, struct servent *, TCP_GetServByName, const UBYTE *, name, a0, const UBYTE *, proto, a1, \
, AMITCP_BASE_NAME)
#define TCP_GetServByPort(port, proto) \
LP2(0xf0, struct servent *, TCP_GetServByPort, LONG, port, d0, const UBYTE *, proto, a0, \
, AMITCP_BASE_NAME)
#define TCP_GetSockName(s, hostname, namelen) \
LP3(0x66, LONG, TCP_GetSockName, LONG, s, d0, struct sockaddr *, hostname, a0, int *, namelen, a1, \
, AMITCP_BASE_NAME)
#define TCP_GetSockOpt(s, level, optname, optval, optlen) \
LP5(0x60, LONG, TCP_GetSockOpt, LONG, s, d0, LONG, level, d1, LONG, optname, d2, void *, optval, a0, int *, optlen, a1, \
, AMITCP_BASE_NAME)
#define TCP_GetSocketEvents(eventmaskp) \
LP1(0x12c, LONG, TCP_GetSocketEvents, ULONG *, eventmaskp, a0, \
, AMITCP_BASE_NAME)
#define TCP_Inet_Addr(cp) \
LP1(0xb4, ULONG, TCP_Inet_Addr, const UBYTE *, cp, a0, \
, AMITCP_BASE_NAME)
#define TCP_Inet_LnaOf(in) \
LP1(0xba, ULONG, TCP_Inet_LnaOf, LONG, in, d0, \
, AMITCP_BASE_NAME)
#define TCP_Inet_MakeAddr(net, host) \
LP2(0xc6, ULONG, TCP_Inet_MakeAddr, ULONG, net, d0, ULONG, host, d1, \
, AMITCP_BASE_NAME)
#define TCP_Inet_NetOf(in) \
LP1(0xc0, ULONG, TCP_Inet_NetOf, LONG, in, d0, \
, AMITCP_BASE_NAME)
#define TCP_Inet_Network(cp) \
LP1(0xcc, ULONG, TCP_Inet_Network, const UBYTE *, cp, a0, \
, AMITCP_BASE_NAME)
#define TCP_Inet_NtoA(in) \
LP1(0xae, char *, TCP_Inet_NtoA, ULONG, in, d0, \
, AMITCP_BASE_NAME)
#define TCP_IoctlSocket(d, request, argp) \
LP3(0x72, LONG, TCP_IoctlSocket, LONG, d, d0, ULONG, request, d1, char *, argp, a0, \
, AMITCP_BASE_NAME)
#define TCP_Listen(s, backlog) \
LP2(0x2a, LONG, TCP_Listen, LONG, s, d0, LONG, backlog, d1, \
, AMITCP_BASE_NAME)
#define TCP_ObtainSocket(id, domain, type, protocol) \
LP4(0x90, LONG, TCP_ObtainSocket, LONG, id, d0, LONG, domain, d1, LONG, type, d2, LONG, protocol, d3, \
, AMITCP_BASE_NAME)
#define TCP_Recv(s, buf, len, flags) \
LP4(0x4e, LONG, TCP_Recv, LONG, s, d0, UBYTE *, buf, a0, LONG, len, d1, LONG, flags, d2, \
, AMITCP_BASE_NAME)
#define TCP_RecvFrom(s, buf, len, flags, from, fromlen) \
LP6(0x48, LONG, TCP_RecvFrom, LONG, s, d0, UBYTE *, buf, a0, LONG, len, d1, LONG, flags, d2, struct sockaddr *, from, a1, int *, fromlen, a2, \
, AMITCP_BASE_NAME)
#define TCP_RecvMsg(s, msg, flags) \
LP3(0x114, LONG, TCP_RecvMsg, LONG, s, d0, struct msghdr *, msg, a0, LONG, flags, d1, \
, AMITCP_BASE_NAME)
#define TCP_ReleaseCopyOfSocket(fd, id) \
LP2(0x9c, LONG, TCP_ReleaseCopyOfSocket, LONG, fd, d0, LONG, id, d1, \
, AMITCP_BASE_NAME)
#define TCP_ReleaseSocket(fd, id) \
LP2(0x96, LONG, TCP_ReleaseSocket, LONG, fd, d0, LONG, id, d1, \
, AMITCP_BASE_NAME)
#define TCP_Send(s, msg, len, flags) \
LP4(0x42, LONG, TCP_Send, LONG, s, d0, const UBYTE *, msg, a0, LONG, len, d1, LONG, flags, d2, \
, AMITCP_BASE_NAME)
#define TCP_SendMsg(s, msg, flags) \
LP3(0x10e, LONG, TCP_SendMsg, LONG, s, d0, const struct msghdr *, msg, a0, LONG, flags, d1, \
, AMITCP_BASE_NAME)
#define TCP_SendTo(s, msg, len, flags, to, tolen) \
LP6(0x3c, LONG, TCP_SendTo, LONG, s, d0, const UBYTE *, msg, a0, LONG, len, d1, LONG, flags, d2, const struct sockaddr *, to, a1, LONG, tolen, d3, \
, AMITCP_BASE_NAME)
#define TCP_SetErrnoPtr(errno_p, size) \
LP2(0xa8, LONG, TCP_SetErrnoPtr, void *, errno_p, a0, LONG, size, d0, \
, AMITCP_BASE_NAME)
#define TCP_SetSockOpt(s, level, optname, optval, optlen) \
LP5(0x5a, LONG, TCP_SetSockOpt, LONG, s, d0, LONG, level, d1, LONG, optname, d2, const void *, optval, a0, LONG, optlen, d3, \
, AMITCP_BASE_NAME)
#define TCP_SetSocketSignals(SIGINTR, SIGIO, SIGURG) \
LP3NR(0x84, TCP_SetSocketSignals, ULONG, SIGINTR, d0, ULONG, SIGIO, d1, ULONG, SIGURG, d2, \
, AMITCP_BASE_NAME)
#define TCP_ShutDown(s, how) \
LP2(0x54, LONG, TCP_ShutDown, LONG, s, d0, LONG, how, d1, \
, AMITCP_BASE_NAME)
#define TCP_Socket(domain, type, protocol) \
LP3(0x1e, LONG, TCP_Socket, LONG, domain, d0, LONG, type, d1, LONG, protocol, d2, \
, AMITCP_BASE_NAME)
#define TCP_SocketBaseTagList(taglist) \
LP1(0x126, LONG, TCP_SocketBaseTagList, struct TagItem *, taglist, a0, \
, AMITCP_BASE_NAME)
#ifndef NO_INLINE_STDARG
#define TCP_SocketBaseTags(tags...) \
({ULONG _tags[] = { tags }; TCP_SocketBaseTagList((struct TagItem *)_tags);})
#endif
#define TCP_SyslogA(level, format, ap) \
LP3NR(0x102, TCP_SyslogA, ULONG, level, d0, const char *, format, a0, va_list, ap, a1, \
, AMITCP_BASE_NAME)
#define TCP_WaitSelect(nfds, readfds, writefds, execptfds, timeout, maskp) \
LP6(0x7e, LONG, TCP_WaitSelect, LONG, nfds, d0, fd_set *, readfds, a0, fd_set *, writefds, a1, fd_set *, execptfds, a2, struct timeval *, timeout, a3, ULONG *, maskp, d1, \
, AMITCP_BASE_NAME)
#endif /* !_INLINE_AMITCP_H */

507
inet_getaddrinfo.c Normal file
View File

@ -0,0 +1,507 @@
/*
* Copyright (c) 2015 Carsten Larsen
* Copyright (c) 2001, 02 Motoyuki Kasahara
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name of the project 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 PROJECT 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 PROJECT 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.
*/
/*
* This program provides getaddrinfo() and getnameinfo() described in
* RFC2133, 2553 and 3493. These functions are mainly used for IPv6
* application to resolve hostname or address.
*
* This program is designed to be working on traditional IPv4 systems
* which don't have those functions. Therefore, this implementation
* supports IPv4 only.
*
* This program is useful for application which should support both IPv6
* and traditional IPv4 systems. Use genuine getaddrinfo() and getnameinfo()
* provided by system if the system supports IPv6. Otherwise, use this
* implementation.
*
* This program also provides freeaddrinfo() and gai_strerror().
*
* Restriction:
* getaddrinfo() and getnameinfo() of this program are NOT thread
* safe, unless the cpp macro ENABLE_PTHREAD is defined.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "config.h"
#include "inet_getaddrinfo.h"
#ifdef ENABLE_NLS
#include <libintl.h>
#endif
#ifdef ENABLE_NLS
#define _(string) gettext(string)
#ifdef gettext_noop
#define N_(string) gettext_noop(string)
#else
#define N_(string) (string)
#endif
#else
#define gettext(string) (string)
#define _(string) (string)
#define N_(string) (string)
#endif
/*
* Error messages for gai_strerror().
*/
static char *eai_errlist[] = {
N_("Success"),
/* EAI_ADDRFAMILY */
N_("Address family for hostname not supported"),
/* EAI_AGAIN */
N_("Temporary failure in name resolution"),
/* EAI_BADFLAGS */
N_("Invalid value for ai_flags"),
/* EAI_FAIL */
N_("Non-recoverable failure in name resolution"),
/* EAI_FAMILY */
N_("ai_family not supported"),
/* EAI_MEMORY */
N_("Memory allocation failure"),
/* EAI_NONAME */
N_("hostname nor servname provided, or not known"),
/* EAI_OVERFLOW */
N_("An argument buffer overflowed"),
/* EAI_SERVICE */
N_("servname not supported for ai_socktype"),
/* EAI_SOCKTYPE */
N_("ai_socktype not supported"),
/* EAI_SYSTEM */
N_("System error returned in errno")
};
/*
* Default hints for getaddrinfo().
*/
static struct addrinfo default_hints = {
0, PF_UNSPEC, 0, 0, 0, NULL, NULL, NULL
};
/*
* Mutex.
*/
struct SignalSemaphore GetaddrinfoSemaphore;
/*
* Declaration of static functions.
*/
#ifdef __STDC__
static int is_integer(const char *);
static int is_address(const char *);
static int itoa_length(int);
#else
static int is_integer();
static int is_address();
static int itoa_length();
#endif
/*
* gai_strerror().
*/
const char *
gai_strerror(ecode)
int ecode;
{
if (ecode < 0 || ecode > EAI_SYSTEM)
return _("Unknown error");
return gettext(eai_errlist[ecode]);
}
/*
* freeaddrinfo().
*/
void
freeaddrinfo(ai)
struct addrinfo *ai;
{
struct addrinfo *next_ai;
while (ai != NULL) {
if (ai->ai_canonname != NULL)
free(ai->ai_canonname);
if (ai->ai_addr != NULL)
free(ai->ai_addr);
next_ai = ai->ai_next;
free(ai);
ai = next_ai;
}
}
/*
* Return 1 if the string `s' represents an integer.
*/
static int
is_integer(s)
const char *s;
{
if (*s == '-' || *s == '+')
s++;
if (*s < '0' || '9' < *s)
return 0;
s++;
while ('0' <= *s && *s <= '9')
s++;
return (*s == '\0');
}
/*
* Return 1 if the string `s' represents an IPv4 address.
* Unlike inet_addr(), it doesn't permit malformed nortation such
* as "192.168".
*/
static int
is_address(s)
const char *s;
{
const static char delimiters[] = {'.', '.', '.', '\0'};
int i, j;
int octet;
for (i = 0; i < 4; i++) {
if (*s == '0' && *(s + 1) != delimiters[i])
return 0;
for (j = 0, octet = 0; '0' <= *s && *s <= '9' && j < 3; s++, j++)
octet = octet * 10 + (*s - '0');
if (j == 0 || octet > 255 || *s != delimiters[i])
return 0;
s++;
}
return 1;
}
/*
* Calcurate length of the string `s', where `s' is set by
* sprintf(s, "%d", n).
*/
static int
itoa_length(n)
int n;
{
int result = 1;
if (n < 0) {
n = -n;
result++;
}
while (n >= 10) {
result++;
n /= 10;
}
return result;
}
/*
* getaddrinfo().
*/
int
getaddrinfo(nodename, servname, hints, res)
const char *nodename;
const char *servname;
const struct addrinfo *hints;
struct addrinfo **res;
{
struct addrinfo *head_res = NULL;
struct addrinfo *tail_res = NULL;
struct addrinfo *new_res;
struct sockaddr_in *sa_in;
struct in_addr **addr_list;
struct in_addr *addr_list_buf[2];
struct in_addr addr_buf;
struct in_addr **ap;
struct servent *servent;
struct hostent *hostent;
const char *canonname = NULL;
in_port_t port;
int saved_h_errno;
int result = 0;
ObtainSemaphore(&GetaddrinfoSemaphore);
saved_h_errno = h_errno;
if (nodename == NULL && servname == NULL) {
result = EAI_NONAME;
goto end;
}
if (hints != NULL) {
if (hints->ai_family != PF_INET && hints->ai_family != PF_UNSPEC) {
result = EAI_FAMILY;
goto end;
}
if (hints->ai_socktype != SOCK_DGRAM
&& hints->ai_socktype != SOCK_STREAM
&& hints->ai_socktype != 0) {
result = EAI_SOCKTYPE;
goto end;
}
} else {
hints = &default_hints;
}
if (servname != NULL) {
if (is_integer(servname))
port = htons(atoi(servname));
else {
if (hints->ai_flags & AI_NUMERICSERV) {
result = EAI_NONAME;
goto end;
}
if (hints->ai_socktype == SOCK_DGRAM)
servent = getservbyname((char*)servname, (char*)"udp");
else if (hints->ai_socktype == SOCK_STREAM)
servent = getservbyname((char*)servname, (char*)"tcp");
else if (hints->ai_socktype == 0)
servent = getservbyname((char*)servname, (char*)"tcp");
else {
result = EAI_SOCKTYPE;
goto end;
}
if (servent == NULL) {
result = EAI_SERVICE;
goto end;
}
port = servent->s_port;
}
} else {
port = htons(0);
}
if (nodename != NULL) {
if (is_address(nodename)) {
addr_buf.s_addr = inet_addr(nodename);
addr_list_buf[0] = &addr_buf;
addr_list_buf[1] = NULL;
addr_list = addr_list_buf;
if (hints->ai_flags & AI_CANONNAME
&& !(hints->ai_flags & AI_NUMERICHOST)) {
hostent = gethostbyaddr((char *)&addr_buf,
sizeof(struct in_addr), AF_INET);
if (hostent != NULL)
canonname = hostent->h_name;
else
canonname = nodename;
}
} else {
if (hints->ai_flags & AI_NUMERICHOST) {
result = EAI_NONAME;
goto end;
}
hostent = gethostbyname(nodename);
if (hostent == NULL) {
switch (h_errno) {
case HOST_NOT_FOUND:
case NO_DATA:
result = EAI_NONAME;
goto end;
case TRY_AGAIN:
result = EAI_AGAIN;
goto end;
default:
result = EAI_FAIL;
goto end;
}
}
addr_list = (struct in_addr **)hostent->h_addr_list;
if (hints->ai_flags & AI_CANONNAME)
canonname = hostent->h_name;
}
} else {
if (hints->ai_flags & AI_PASSIVE)
addr_buf.s_addr = htonl(INADDR_ANY);
else
addr_buf.s_addr = htonl(0x7F000001);
addr_list_buf[0] = &addr_buf;
addr_list_buf[1] = NULL;
addr_list = addr_list_buf;
}
for (ap = addr_list; *ap != NULL; ap++) {
new_res = (struct addrinfo *)malloc(sizeof(struct addrinfo));
if (new_res == NULL) {
if (head_res != NULL)
freeaddrinfo(head_res);
result = EAI_MEMORY;
goto end;
}
new_res->ai_family = PF_INET;
new_res->ai_socktype = hints->ai_socktype;
new_res->ai_protocol = hints->ai_protocol;
new_res->ai_addr = NULL;
new_res->ai_addrlen = sizeof(struct sockaddr_in);
new_res->ai_canonname = NULL;
new_res->ai_next = NULL;
new_res->ai_addr = (struct sockaddr *)
malloc(sizeof(struct sockaddr_in));
if (new_res->ai_addr == NULL) {
free(new_res);
if (head_res != NULL)
freeaddrinfo(head_res);
result = EAI_MEMORY;
goto end;
}
sa_in = (struct sockaddr_in *)new_res->ai_addr;
memset(sa_in, 0, sizeof(struct sockaddr_in));
sa_in->sin_family = PF_INET;
sa_in->sin_port = port;
memcpy(&sa_in->sin_addr, *ap, sizeof(struct in_addr));
if (head_res == NULL)
head_res = new_res;
else
tail_res->ai_next = new_res;
tail_res = new_res;
}
if (canonname != NULL && head_res != NULL) {
head_res->ai_canonname = (char *)malloc(strlen(canonname) + 1);
if (head_res->ai_canonname != NULL)
strcpy(head_res->ai_canonname, canonname);
}
*res = head_res;
end:
h_errno = saved_h_errno;
ReleaseSemaphore(&GetaddrinfoSemaphore);
return result;
}
int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *node, socklen_t nodelen, char *serv, socklen_t servlen, int flags) {
const struct sockaddr_in *sa_in = (const struct sockaddr_in *)sa;
struct hostent *hostent;
struct servent *servent;
char *ntoa_address;
int saved_h_errno;
int result = 0;
ObtainSemaphore(&GetaddrinfoSemaphore);
saved_h_errno = h_errno;
if (sa_in->sin_family != PF_INET) {
result = EAI_FAMILY;
goto end;
} else if (node == NULL && serv == NULL) {
result = EAI_NONAME;
goto end;
}
if (serv != NULL && servlen > 0) {
if (flags & NI_NUMERICSERV)
servent = NULL;
else if (flags & NI_DGRAM)
servent = getservbyport(sa_in->sin_port, "udp");
else
servent = getservbyport(sa_in->sin_port, "tcp");
if (servent != NULL) {
if (servlen <= strlen(servent->s_name)) {
result = EAI_OVERFLOW;
goto end;
}
strcpy(serv, servent->s_name);
} else {
if (servlen <= itoa_length(ntohs(sa_in->sin_port))) {
result = EAI_OVERFLOW;
goto end;
}
sprintf(serv, "%d", ntohs(sa_in->sin_port));
}
}
if (node != NULL && nodelen > 0) {
if (flags & NI_NUMERICHOST)
hostent = NULL;
else {
hostent = gethostbyaddr((char *)&sa_in->sin_addr,
sizeof(struct in_addr), AF_INET);
}
if (hostent != NULL) {
if (nodelen <= strlen(hostent->h_name)) {
result = EAI_OVERFLOW;
goto end;
}
strcpy(node, hostent->h_name);
} else {
if (flags & NI_NAMEREQD) {
result = EAI_NONAME;
goto end;
}
ntoa_address = inet_ntoa(sa_in->sin_addr);
if (nodelen <= strlen(ntoa_address)) {
result = EAI_OVERFLOW;
goto end;
}
strcpy(node, ntoa_address);
}
}
end:
h_errno = saved_h_errno;
ReleaseSemaphore(&GetaddrinfoSemaphore);
return result;
}

223
inet_getaddrinfo.h Normal file
View File

@ -0,0 +1,223 @@
/*
* Copyright (c) 2015 Carsten Larsen
* Copyright (c) 2001, 02 Motoyuki Kasahara
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name of the project 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 PROJECT 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 PROJECT 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.
*/
#ifndef INET_GETADDRINFO_H
#define INET_GETADDRINFO_H
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
/********************************************************************/
/*
* Undefine all the macros.
* <netdb.h> might defines some of them.
*/
#ifdef EAI_ADDRFAMILY
#undef EAI_ADDRFAMILY
#endif
#ifdef EAI_AGAIN
#undef EAI_AGAIN
#endif
#ifdef EAI_BADFLAGS
#undef EAI_BADFLAGS
#endif
#ifdef EAI_FAIL
#undef EAI_FAIL
#endif
#ifdef EAI_FAMILY
#undef EAI_FAMILY
#endif
#ifdef EAI_MEMORY
#undef EAI_MEMORY
#endif
#ifdef EAI_NONAME
#undef EAI_NONAME
#endif
#ifdef EAI_OVERFLOW
#undef EAI_OVERFLOW
#endif
#ifdef EAI_SERVICE
#undef EAI_SERVICE
#endif
#ifdef EAI_SOCKTYPE
#undef EAI_SOCKTYPE
#endif
#ifdef EAI_SYSTEM
#undef EAI_SYSTEM
#endif
#ifdef AI_PASSIVE
#undef AI_PASSIVE
#endif
#ifdef AI_CANONNAME
#undef AI_CANONNAME
#endif
#ifdef AI_NUMERICHOST
#undef AI_NUMERICHOST
#endif
#ifdef AI_NUMERICSERV
#undef AI_NUMERICSERV
#endif
#ifdef AI_V4MAPPED
#undef AI_V4MAPPED
#endif
#ifdef AI_ALL
#undef AI_ALL
#endif
#ifdef AI_ADDRCONFIG
#undef AI_ADDRCONFIG
#endif
#ifdef AI_DEFAULT
#undef AI_DEFAULT
#endif
#ifdef NI_NOFQDN
#undef NI_NOFQDN
#endif
#ifdef NI_NUMERICHOST
#undef NI_NUMERICHOST
#endif
#ifdef NI_NAMEREQD
#undef NI_NAMEREQD
#endif
#ifdef NI_NUMERICSERV
#undef NI_NUMERICSERV
#endif
#ifdef NI_NUMERICSCOPE
#undef NI_NUMERICSCOPE
#endif
#ifdef NI_DGRAM
#undef NI_DGRAM
#endif
#ifdef NI_MAXHOST
#undef NI_MAXHOST
#endif
#ifdef NI_MAXSERV
#undef NI_MAXSERV
#endif
/*
* Fake struct and function names.
* <netdb.h> might declares all or some of them.
*/
/*
#if defined(HAVE_GETADDRINFO) || defined(HAVE_GETNAMEINFO)
#define addrinfo my_addrinfo
#define gai_strerror my_gai_strerror
#define freeaddrinfo my_freeaddrinfo
#define getaddrinfo my_getaddrinfo
#define getnameinfo my_getnameinfo
#endif
*/
/********************************************************************/
/*
* Error codes.
*/
#define EAI_ADDRFAMILY 1
#define EAI_AGAIN 2
#define EAI_BADFLAGS 3
#define EAI_FAIL 4
#define EAI_FAMILY 5
#define EAI_MEMORY 6
#define EAI_NONAME 7
#define EAI_OVERFLOW 8
#define EAI_SERVICE 9
#define EAI_SOCKTYPE 10
#define EAI_SYSTEM 11
/*
* Flags for getaddrinfo().
*/
#define AI_ADDRCONFIG 0x0001
#define AI_ALL 0x0002
#define AI_CANONNAME 0x0004
#define AI_NUMERICHOST 0x0008
#define AI_NUMERICSERV 0x0010
#define AI_PASSIVE 0x0020
#define AI_V4MAPPED 0x0040
#define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG)
/*
* Flags for getnameinfo().
*/
#define NI_DGRAM 0x0001
#define NI_NAMEREQD 0x0002
#define NI_NOFQDN 0x0004
#define NI_NUMERICHOST 0x0008
#define NI_NUMERICSCOPE 0x0010
#define NI_NUMERICSERV 0x0020
/*
* Maximum length of FQDN and servie name for getnameinfo().
*/
#define NI_MAXHOST 1025
#define NI_MAXSERV 32
/*
* Address families and Protocol families.
*/
#ifndef AF_UNSPEC
#define AF_UNSPEC AF_INET
#endif
#ifndef PF_UNSPEC
#define PF_UNSPEC PF_INET
#endif
typedef unsigned int socklen_t;
typedef u_int16_t in_port_t;
typedef unsigned int sa_family_t;
#ifdef AOS3
/*
* struct addrinfo.
*/
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
socklen_t ai_addrlen;
char *ai_canonname;
struct sockaddr *ai_addr;
struct addrinfo *ai_next;
};
#endif
#include <exec/types.h>
extern struct SignalSemaphore GetaddrinfoSemaphore;
const char* gai_strerror(int);
void freeaddrinfo(struct addrinfo *);
int getaddrinfo(const char *, const char *, const struct addrinfo *, struct addrinfo **);
int getnameinfo(const struct sockaddr *, socklen_t, char *, socklen_t, char *, socklen_t, int);
#endif

37
workman Executable file
View File

@ -0,0 +1,37 @@
#! /bin/sh
# This file is in the public domain, so clarified as of
# 2009-05-17 by Arthur David Olson.
# Tell groff not to emit SGR escape sequences (ANSI color escapes).
GROFF_NO_SGR=1
export GROFF_NO_SGR
# Tell groff to emit SGR escape sequences (ANSI color escapes).
#GROFF_SGR=1
#export GROFF_SGR
echo ".am TH
.hy 0
.na
..
.rm }H
.rm }F" | nroff -man - ${1+"$@"} | perl -ne '
binmode STDIN, '\'':encoding(utf8)'\'';
binmode STDOUT, '\'':encoding(utf8)'\'';
chomp;
s/.\010//g;
s/\s*$//;
if (/^$/) {
$sawblank = 1;
next;
} else {
if ($sawblank && $didprint) {
print "\n";
$sawblank = 0;
}
print "$_\n";
$didprint = 1;
}
'