Date: Mon, 26 Nov 2001 17:06:41 -0500 From: The Anarcat <anarcat@anarcat.dyndns.org> To: cjclark@alum.mit.edu Cc: Simon Dick <simond@irrelevant.org>, Jim Conner <jconner@enterit.com>, FreeBSD Questions <freebsd-questions@FreeBSD.ORG> Subject: Re: can't do reverse dns with /etc/hosts Message-ID: <20011126220641.GA1160@shall.anarcat.dyndns.org> In-Reply-To: <20011126010753.E222@gohan.cjclark.org> References: <5.1.0.14.0.20011123164749.0245ec60@mail.enterit.com> <20011114173647.D66694@blossom.cjclark.org> <20011115012039.GA61093@shall.anarcat.dyndns.org> <20011114173647.D66694@blossom.cjclark.org> <5.1.0.14.0.20011123164749.0245ec60@mail.enterit.com> <5.1.0.14.0.20011123172728.02c61518@mail.enterit.com> <20011124103734.GB386@irrelevant.org> <3BFFF17E.D2E2F7C1@anarcat.dyndns.org> <20011126010753.E222@gohan.cjclark.org>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
On Lun nov 26, 2001 at 01:07:53 -0800, Crist J. Clark wrote:
> On Sat, Nov 24, 2001 at 02:14:06PM -0500, John Smith wrote:
> >
> >
> > Simon Dick wrote:
> > >
> > > I guess my method of just using ping <hostname> and seeing what IP it tries
> > > to ping won't be suitable for this? :)
> >
> > no because I want to test reverse DNS.
>
> That does not make any sense. You want to test reverse-DNS without
> using DNS?
yes. Well, actually, I want to test the resolver's reverse functionality
without *forcing* use of DNS.
> ITYM, "I want to test address-to-hostname translation using
> /etc/hosts."
No. "I want to test address-to-hostname translation using the resolver,
whatever *it's* using (DNS/hosts/YP)."
> I couldn't sleep so I wrote a quick program.
Exactly what I was looking for. I enhanced it to provide both addr and
name lookups.
I think this is a useful tool that could be included in the base system,
even if so trivial. It can be very useful to test an installation or
configuration of the resolver.
Index: iplookup.c
===================================================================
RCS file: /u/anarcat/ncvs/iplookup.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- iplookup.c 26 Nov 2001 20:28:40 -0000 1.1
+++ iplookup.c 26 Nov 2001 22:01:40 -0000 1.2
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2001 Crist J. Clark
- * $Id: iplookup.c,v 1.1 2001/11/26 20:28:40 anarcat Exp $
+ * $Id: iplookup.c,v 1.2 2001/11/26 22:01:40 anarcat Exp $
*/
#include <sys/types.h>
@@ -17,21 +17,38 @@
{
struct hostent *h;
struct in_addr a;
- int i, j;
+ int i, name_l;
+ char addr[24];
+ char **p;
for (i = 1; i < argc; i++) {
- if (inet_aton(argv[i], &a) == 0)
- errx(EX_USAGE, "could not parse IP address: %s",
- argv[i]);
-
- if ((h = gethostbyaddr((char *)&a, sizeof a, AF_INET)) == NULL)
+ if (name_l = (inet_aton(argv[i], &a) == 0)) {
+ h = gethostbyname(argv[i]);
+ } else {
+ h = gethostbyaddr((char *)&a, sizeof a, AF_INET);
+ }
+ if (h == NULL)
errx(EX_OSERR, "address, %s, failed: %s",
argv[i], hstrerror(h_errno));
- printf("%s\n", h->h_name);
+ if (name_l) {
+ printf("%s: ", h->h_name);
+ a.s_addr = inet_addr(h->h_addr);
+ for (p = h->h_addr_list ; p != NULL && *p ;) {
+ addr[0] = '\0';
+ inet_ntop(h->h_addrtype, *p, addr, sizeof addr);
+ printf("%s",addr);
+ if (++p != NULL && *p) {
+ printf(", ");
+ }
+ }
+ printf("\n");
+ } else {
+ printf("%s: %s\n", argv[i], h->h_name);
+ }
- for (j = 0; h->h_aliases[j] != NULL; j++)
- printf("\t%s\n", h->h_aliases[j]);
+ for (p = h->h_aliases; p != NULL && *p; p++)
+ printf("\t%s\n", *p);
}
return 0;
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (FreeBSD)
Comment: Pour information voir http://www.gnupg.org
iEYEARECAAYFAjwCvPAACgkQttcWHAnWiGf+JwCcC0jbJdxdaP79ak1MrXTEN6zE
dYYAoJthVVn3Lr3jnqD1zisP1ue1XNb5
=RGZ/
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011126220641.GA1160>
