Commit 959fb010 authored by Mark Andrews's avatar Mark Andrews

1846. [contrib] query-loc-0.3.0 from Stephane Bortzmeyer

                        <bortzmeyer@nic.fr>.
parent 46cb442c
1846. [contrib] query-loc-0.3.0 from Stephane Bortzmeyer
<bortzmeyer@nic.fr>.
1845. [placeholder] rt13745
1844. [bug] inet_pton() accepted more that 4 hexadecimal digits
......
The following machines, at least today seem to have LOC
records:
*.cpod.fr (for instance www.cpod.fr)
130.104.3.*
195.202.193.*
Melanie.Tolna.Net
204.92.254.*
mail.vitts.com
alink.net
caida.org
ckdhr.com
distributed.net (rc5stats.distributed.net)
nikhef.nl
yahoo.com
nic.af
$Id: ADDRESSES,v 1.1 2005/04/01 05:34:59 marka Exp $
Just for info, can be out of date.
RFC 1876, 5.2, specially 5.2.3
Important points:
- LOC RRs are always attached to a *name*.
- we can have two (or more) RRs for one address, one more specific than the other
main
if (host is a name)
getLOCbyname
else # host is an IP address
gethostbyaddr
if (name)
getLOCbyname
# If there is none, do not search. We assume the above was sufficient # (But check 5.2.2)
else
getLOCbyaddress
getLOCbyname (host)
get LOC for host
if (it exists)
OK
else
get all A records of the name
foreach A record
getLOCbyaddress
OK at the first one found
# we assume they are consistent
END
getLOCbyaddress (address)
# May receive a mask. Otherwise, deduce it from the class
makeNetAddress
getLOCbynetwork
getLOCbynetwork
get PTR and A for it
if (exist)
getLOCbyname
******* DIFFICULT : we have to manage a stack. See the code
makeNetAddress (level--)
getLOCbynetwork
else
END
Type './configure', then 'make' and (as root if necessary) 'make
install'.
It requires a recent libresolv, with loc_ntoa, but use an alternative
which I provide, if not found.
Tested on Linux (i386 and Alpha), Solaris (Sparc) and Digital Unix (Alpha).
$Id: INSTALL,v 1.1 2005/04/01 05:34:59 marka Exp $
# $Id: Makefile.in,v 1.1 2005/04/01 05:34:59 marka Exp $
CC=@CC@
CFLAGS=@CFLAGS@
LIBS=@LIBS@
DESTDIR=@prefix@
BINDIR=@prefix@/bin
MANDIR=@prefix@/share/man/man1
DISTRIB= README INSTALL ALGO USAGE ADDRESSES Makefile.in configure configure.in config.h.in install-sh loc.h loc.c query-loc.c loc_ntoa.c query-loc.1
OBJS=query-loc.o loc.o @LOC_NTOA@
VERSION=`grep VERSION loc.h | cut -d ' ' -f 3 | sed s/\"//g`
all: query-loc
query-loc: $(OBJS)
$(CC) -o $@ $(OBJS) $(LIBS)
%.o: %.c loc.h
$(CC) $(CFLAGS) -c $<
clean:
rm -f *.o query-loc *~
distclean: clean
rm -f config.h config.cache config.log config.status Makefile
distrib: clean
./reconf
@(echo Query-Loc is version ${VERSION}; \
mkdir query-loc-${VERSION}; \
cp $(DISTRIB) query-loc-${VERSION};\
tar cvf query-loc-${VERSION}.tar query-loc-${VERSION}; \
rm -rf query-loc-${VERSION}; \
gzip -v -9 -f query-loc-${VERSION}.tar);
install:
@INSTALL@ -m 0755 query-loc $(BINDIR)
if [ ! -d $(MANDIR) ]; then \
mkdir $(MANDIR); \
fi
@INSTALL@ -m 0644 query-loc.1 $(MANDIR)
query-loc: a program to retrieve and display the location
information in the DNS.
It uses the algorithms described in
RFC 1876 (and RFC 1101 to get the network names).
You can find examples of networks wchich implement this scheme
in the ADDRESSES file.
It is under the General Public Licence (GPL, which
you can fetch from <http://www.gnu.org/copyleft/gpl.html>.
Copyright Stéphane Bortzmeyer <bortzmeyer@debian.org>, 1998.
Thanks to Paul Vixie for the RFC and its encouragements. Thanks
to Björn Augustsson for the xtraceroute program
<http://www.dtek.chalmers.se/~d3august/xt/>.
$Id: README,v 1.1 2005/04/01 05:34:59 marka Exp $
query-loc [-v] [-d nnn] host-name-or-address
Examples of hosts with LOCation info (quite uncommon, if you know more,
please tell me):
- Everything in the 193.105.79.0 network, such as www.humanite.presse.fr
- Everything in the 192.88.144 network, such as www.kei.com
/* config.h.in. Generated from configure.in by autoheader. */
/* $Id: config.h.in,v 1.1 2005/04/01 05:35:00 marka Exp $ */
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `resolv' library (-lresolv). */
#undef HAVE_LIBRESOLV
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* The size of a `char', as computed by sizeof. */
#undef SIZEOF_CHAR
/* The size of a `int', as computed by sizeof. */
#undef SIZEOF_INT
/* The size of a `long', as computed by sizeof. */
#undef SIZEOF_LONG
/* The size of a `short', as computed by sizeof. */
#undef SIZEOF_SHORT
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* Is there a loc_ntoa on this system? */
#undef HAVE_LOC_NTOA
This diff is collapsed.
dnl Process this file with autoconf to produce a configure script.
AC_RELEASE("$Id: configure.in,v 1.1 2005/04/01 05:35:00 marka Exp $")
AC_INIT(query-loc.c)
dnl Checks for programs.
AC_PROG_CC
if test "$GCC" = "yes"; then
CFLAGS="${CFLAGS} -Wall"
fi
AC_PROG_INSTALL
dnl Checks for libraries.
AC_CHECK_LIB(resolv, res_query)
dnl Checks for header files.
AC_HEADER_STDC
AC_CONFIG_HEADER(config.h)
AC_CHECK_HEADER(resolv.h, , AC_MSG_ERROR("No headers for name service applications"))
AC_CHECK_HEADER(arpa/nameser.h, , AC_MSG_ERROR("No headers for name service applications"))
AC_CHECK_HEADER(sys/time.h, , AC_MSG_ERROR("Mandatory header missing on your system"))
AC_CHECK_HEADER(unistd.h, , AC_MSG_ERROR("Mandatory header missing on your system"))
dnl This one is only useful for Solaris?
AC_MSG_CHECKING(if libnsl is mandatory)
AC_TRY_LINK([#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
union
{
HEADER hdr;
u_char buf[4096]; /* With RFC 2671, otherwise 512 is enough */
}
response;
char *domain;
int requested_type; ],
[res_query(domain,
C_IN,
requested_type,
(u_char *) & response,
sizeof (response)) ], dnl
[AC_MSG_RESULT(no)], dnl
[AC_MSG_RESULT(yes); LIBS="${LIBS} -lnsl"])
dnl Check for the loc_ntoa macro/function
AC_MSG_CHECKING(loc_ntoa)
AC_TRY_LINK([#include <resolv.h>], dnl
[u_char *cp; char *result; loc_ntoa(cp, result)], dnl
[AC_MSG_RESULT(yes); AC_DEFINE(HAVE_LOC_NTOA)], dnl
[AC_MSG_RESULT([no, using the alternative]); LOC_NTOA=loc_ntoa.o])
AC_SUBST(LOC_NTOA)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(char)
dnl Misc.
AC_OUTPUT(Makefile)
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, 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.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
chmodcmd=""
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0
#include "loc.h"
/* $Id: loc.c,v 1.1 2005/04/01 05:35:00 marka Exp $ */
/* Global variables */
short rr_errno;
/*
Prints the actual usage
*/
void
usage ()
{
(void) fprintf (stderr,
"Usage: %s: [-v] [-d nnn] hostname\n", progname);
exit (2);
}
/*
Panics
*/
void
panic (message)
char *message;
{
(void) fprintf (stderr,
"%s: %s\n", progname, message);
exit (2);
}
/*
** IN_ADDR_ARPA -- Convert dotted quad string to reverse in-addr.arpa
** ------------------------------------------------------------------
**
** Returns:
** Pointer to appropriate reverse in-addr.arpa name
** with trailing dot to force absolute domain name.
** NULL in case of invalid dotted quad input string.
*/
#ifndef ARPA_ROOT
#define ARPA_ROOT "in-addr.arpa"
#endif
char *
in_addr_arpa (dottedquad)
char *dottedquad; /* input string with dotted quad */
{
static char addrbuf[4 * 4 + sizeof (ARPA_ROOT) + 2];
unsigned int a[4];
register int n;
n = sscanf (dottedquad, "%u.%u.%u.%u", &a[0], &a[1], &a[2], &a[3]);
switch (n)
{
case 4:
(void) sprintf (addrbuf, "%u.%u.%u.%u.%s.",
a[3] & 0xff, a[2] & 0xff, a[1] & 0xff, a[0] & 0xff, ARPA_ROOT);
break;
case 3:
(void) sprintf (addrbuf, "%u.%u.%u.%s.",
a[2] & 0xff, a[1] & 0xff, a[0] & 0xff, ARPA_ROOT);
break;
case 2:
(void) sprintf (addrbuf, "%u.%u.%s.",
a[1] & 0xff, a[0] & 0xff, ARPA_ROOT);
break;
case 1:
(void) sprintf (addrbuf, "%u.%s.",
a[0] & 0xff, ARPA_ROOT);
break;
default:
return (NULL);
}
while (--n >= 0)
if (a[n] > 255)
return (NULL);
return (addrbuf);
}
/*
Returns a human-readable version of the LOC information or
NULL if it failed. Argument is a name (of a network or a machine)
and a boolean telling is it is a network name or a machine name.
*/
char *
getlocbyname (name, is_network)
const char *name;
short is_network;
{
char *result;
struct list_in_addr *list, *p;
result = findRR (name, T_LOC);
if (result != NULL)
{
if (debug >= 2)
printf ("LOC record found for the name %s\n", name);
return result;
}
else
{