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:20:16 +0100 (WET DST)

Silly me...

> 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);
                ^--- this is a pointer to a struct
>   return 1;
> }




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