[Freeciv-Dev] Re: [PATCH] Hostname lookups, third take.
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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;
> }
|
|