Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2000:
[Freeciv-Dev] Re: Hostname lookups again.
Home

[Freeciv-Dev] Re: Hostname lookups again.

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Vasco Alexandre Da Silva Costa <vasc@xxxxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Hostname lookups again.
From: Gaute B Strokkenes <gs234@xxxxxxxxx>
Date: 20 Sep 2000 02:30:12 +0200

Vasco Alexandre Da Silva Costa <vasc@xxxxxxxxxxxxxx> writes:

> On 19 Sep 2000, Gaute B Strokkenes wrote:
> 
> > Vasco Alexandre Da Silva Costa <vasc@xxxxxxxxxxxxxx> writes:
> > 
> > > On 18 Sep 2000, Gaute B Strokkenes wrote:
> > > 
> > > > I have attached a (slighly) updated version.  It's a very
> > > > straightforward fix.  It would be great if someone gave me some
> > > > feedback, or just applied the damn thing...
> > > 
> > > Well, i really don't see why you're making all those checks to see if a
> > > name is of the AF_INET family in look up using gethostbyname().  It's not
> > > like DNS is used for non IP stuff...  as far as i know...
> > 
> > AF_INET6.  There are various other, though less common, possibilities
> > as well.
> 
> Such as?  gethostbyname() calls the resolver which calls DNS.  If DNS is
> used over anything else than IP let me know.

Not quite.  gethostbyname() and friends were intended from the
beginning as an extensible system, and unless you're prepared to
guarantee that no one has every used it for anything other than IPv4
and that no one ever will (and unless you have a functional crystal
ball, you can't) checking for AF_INET is the smart thing to do.  It's
not like it's either difficult or costly.

> As for AF_INET6... well check this
> (from http://community.roxen.com/developers/idocs/rfc/rfc2553.html):
[snip]
> We note that the two existing functions, gethostbyname() and
> gethostbyaddr(), are left as-is. New functions are defined to handle
> both IPv4 and IPv6 addresses.

Interesting.  An excerpt from the gethostbyname() man page on my system
says:

       The gethostbyname() function returns a structure  of  type
       hostent  for  the  given host name.  Here name is either a
       host name, or an IPv4 address in standard dot notation, or
       an IPv6 address in colon (and possibly dot) notation. (See
       RFC 1884 for the description of IPv6 addresses.)  If  name
       is  an  IPv4  or  IPv6 address, no lookup is performed and
       gethostbyname() simply copies name into the  h_name  field
       and  its struct in_addr equivalent into the h_addr_list[0]
       field of the returned hostent structure.

The libc info pages say similar things.

So the experts are not agreed, or there are conflicting standards
and/or implementations out there.  And you can bet that whatever
reference is correct, if there is misleading documentation out there,
there will be similarly demented implementations.  Accept, check, and
deflect.  Simple.

> > My problem with that code was that it would use the size field in
> > the result of the look-up to determine how much to copy.  I didn't
> > investigate the affected data structures too much, but sooner or
> > later you'll end up being sorry for copying a 128-bit inetv6
> > address instead of a 32-bit inetv4 address.  If you prefer
> > memcpy() over struct assignments, please feel free to change it
> > back.  But do it properly... >8-)

> What's wrong about the memcpy()?  The only problem which you mention
> is is gethostbyname() returns some address which is not of the
> AF_INET type i know of no such case.  The RFC claims it only returns
> IPv4 addresses.

And there are no (possibly broken) systems where it doesn't?  And
you're 100% confident that there never will be?  And, for that matter,
if you're that sure that it's AF_INET anyway, why reference the length
field, when you know it's sizeof (struct in_addr) anyway?

> But if you want that check, fine by me...  But give me *one* real
> case where it isn't true before adding superfluous checks.

Superfluous checks are good.  That's why assert() exists, and why
people use it.  The only time that you don't want superfluous checks
is when there is some sort of excessive penalty involved.  That's not
the case here.

> > Actually checking the length field of the look-up (when we've already
> > ascertained that it's AF_INET) might be a bit anal, but why not.

> > Or just forget about them altogether (as my patch does,) since
> > gethostbyname() is supposed to do the right thing when presented with
> > a dotted quad.  I suppose there might be brain-damaged systems out
> > there that don't do this.  If anyone knows of one, they might wish to
> > chime in.

> Actually no.  I did this once in the past, and in Linux when libc
> couldn't connect to DNS it failed to lookup the numbers and dots
> addresses (of course noone uses Linux...).

<bastard-mode>I thought you just said that we shouldn't support broken
systems?</bastard-mode>But then again, if someone can't connect to a
DNS server they're probably either not connected or too busy fixing
their broken setup to play Freeciv.

But the point is taken.  On reflection, I think that this stuff should
go in a function somewhere anyway, after all it's really just the same
code repeated three times.

> You see, the lookup code not so long ago.  So it's not like that bit of
> the code has been ignored.  Your point about the isdigit() is valid, but
> everything else isn't.

Oh, I've hurt your pride, haven't I?  Take a deep breath and relax.
No one is trying to get you.

-- 
Big Gaute (not to be confused with LG)
Yow!!  It's LIBERACE and TUESDAY WELD!!  High on a HILL... driving a
 LITTLE CAR...  I wanna be in that LITTLE CAR, too!!  I wanna drive off
 with LIBBY and TUESDAY!



[Prev in Thread] Current Thread [Next in Thread]