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

[Freeciv-Dev] Re: [PATCH] Hostname lookups, third take.

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Gaute B Strokkenes <gs234@xxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [PATCH] Hostname lookups, third take.
From: Vasco Alexandre Da Silva Costa <vasc@xxxxxxxxxxxxxx>
Date: Fri, 22 Sep 2000 22:13:02 +0100 (WET DST)

On 22 Sep 2000, Gaute B Strokkenes wrote:

> 
> As promised, here is the (hopefully final) version of my hostname
> lookup patch.  It does the following:
> 
> * Consolidate all the code that looks up hostnames in one function,
>   look_up_host().

I modified your function slighly and cleaned up the comments... here it
is:

/***************************************************************
Use hostname string to find TCP/IP address
***************************************************************/
int lookup_host(const char *hostname, struct sockaddr_in *sock)
{
  struct hostent *hp;

  sock->sin_family=AF_INET;

#ifdef HAVE_INET_ATON
  if (inet_aton(hostname, &sock->sin_addr)) {
    return 1;
  }
#else
#  ifndef INADDR_NONE
#    define INADDR_NONE 0xffffffff
#  endif

  if ((sock->sin_addr.s_addr=inet_addr(hostname)) != INADDR_NONE) {
    return 1;
  }
#endif
  if ((hp=gethostbyname(hostname)) == NULL) {
    return 0;
  }

  if (hp->h_addrtype != AF_INET) {
    return 0;
  }

  memcpy(&sock.sin_addr, hp->h_addr, hp->h_length);
  return 1;
}

> * Eliminate the isdigit(hostname[0]) bug.
> 
> * Include config.h in all .c files, since no one screamed when I
>   suggested this.

I dunno if there's a problem.  Jeff, David?

> * Attempts to deal correctly with all combinations of RFCs 2133, 2553,
>   IPv4 and IPv6.  Rationales for doing things the way that they have
>   been done are in the source.

I removed those.  Sorry, but this way it's half the size :-)  I'm a firm
believer in only using coments when necessary.  Simple code with
loads of coments == one huge mess, IMHO.

> After applying this patch you should:
> 
> * Add a configure test for inet_aton().  (I tested it by defining
>   HAVE_INET_ATON directly.)

AC_CHECK_FUNC(inet_aton)

Should do the trick.

> * Modify common/create_lsend.pl to include config.h .  (I didn't do
>   this since I don't do perl.)

== Well David was the author of that...  I've never programmed in perl but:

print OUT_C "\#ifdef HAVE_CONFIG_H\n\#include\"config.h\"\n\#endif\n\n";

== Should work i guess.

== inserted before:

# packets.h should include packet_l.h

== like this:

print OUT_C "\#ifdef HAVE_CONFIG_H\n\#include \"config.h\"\n\#endif\n\n";

# packets.h should include packet_l.h
print OUT_C "\#include \"packets.h\"\n\n";






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