Skip site navigation (1)Skip section navigation (2)
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

--AhhlLboLdkugWU4S
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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:
> >=20
> >=20
> > Simon Dick wrote:
> > >=20
> > > I guess my method of just using ping <hostname> and seeing what IP it=
 tries
> > > to ping won't be suitable for this? :)
> >=20
> > no because I want to test reverse DNS.
>=20
> That does not make any sense. You want to test reverse-DNS without
> using DNS?=20

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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
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 $
  */
=20
 #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;
=20
 	for (i =3D 1; i < argc; i++) {
-		if (inet_aton(argv[i], &a) =3D=3D 0)
-			errx(EX_USAGE, "could not parse IP address: %s",
-			    argv[i]);
-
-		if ((h =3D gethostbyaddr((char *)&a, sizeof a, AF_INET)) =3D=3D NULL)
+		if (name_l =3D (inet_aton(argv[i], &a) =3D=3D 0)) {
+			h =3D gethostbyname(argv[i]);
+		} else {
+			h =3D gethostbyaddr((char *)&a, sizeof a, AF_INET);
+		}
+		if (h =3D=3D NULL)
 			errx(EX_OSERR, "address, %s, failed: %s",
 			    argv[i], hstrerror(h_errno));
=20
-		printf("%s\n", h->h_name);
+		if (name_l) {
+			printf("%s: ", h->h_name);
+			a.s_addr =3D inet_addr(h->h_addr);
+        		for (p =3D h->h_addr_list ; p !=3D NULL && *p ;) {
+                		addr[0] =3D '\0';
+                		inet_ntop(h->h_addrtype, *p, addr, sizeof addr);
+                		printf("%s",addr);
+				if (++p !=3D NULL && *p) {
+					printf(", ");
+				}
+        		}
+			printf("\n");
+		} else {
+			printf("%s: %s\n", argv[i], h->h_name);
+		}
=20
-		for (j =3D 0; h->h_aliases[j] !=3D NULL; j++)
-			printf("\t%s\n", h->h_aliases[j]);
+		for (p =3D h->h_aliases; p !=3D NULL && *p; p++)
+			printf("\t%s\n", *p);
 	}
=20
 	return 0;

--AhhlLboLdkugWU4S
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (FreeBSD)
Comment: Pour information voir http://www.gnupg.org

iEYEARECAAYFAjwCvPAACgkQttcWHAnWiGf+JwCcC0jbJdxdaP79ak1MrXTEN6zE
dYYAoJthVVn3Lr3jnqD1zisP1ue1XNb5
=RGZ/
-----END PGP SIGNATURE-----

--AhhlLboLdkugWU4S--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011126220641.GA1160>