Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: Brian Haley <Brian.Haley@nospam_hp.com>
Subject: Re: gethostbyname returns only single IP address
Date: Mon, 26 Apr 2004 22:51:12 GMT	[thread overview]
Message-ID: <408D8D8C.3030801@nospam_hp.com> (raw)
In-Reply-To: <5d1678ff.0404261254.5405fb4e@posting.google.com>



Calista wrote:

> Yes Brian, I have tried the program on Linux, and there it prints both
> of the IP addresses. It doesn't print both on Tru64 though. I suspect
> the problem is with how the system is configured, but I have no idea
> where\what to look for.

You still haven't given enough configuration information - do the two IP 
addresses have different hostnames associated with them?  I would not 
expect that to return more than one address unless there is some special 
DNS configuration.

Just so we're on the same page, I've included an example gethostbyname() 
utility I use.

# ./gethostbyname `hostname`

Oh, and my Linux box behaves like Tru64 :)

-Brian


#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>

void printhostent();
void print_h_errno();

main ( argc, argv )
int argc;
char *argv[];
{
    struct hostent *hp;

    if ( argc != 2 )
        printf("Usage: gethostbyname host\n");
    else if ( hp = gethostbyname(argv[1]) ) {
        printf("hp = 0x%lx\n", hp);
        printhostent(hp);
    } else
        print_h_errno();

}


void
printhostent ( hp )
struct hostent *hp;
{
    char **cpp;
    struct in_addr addr;

    printf("struct hostent:\n");
    printf("\t h_name        %s\n",hp->h_name);
    cpp = hp->h_aliases;
    if ( !*cpp )
       printf("\t h_aliases\n");
    else {
       printf("\t h_aliases     %s\n",*cpp);
       while ( *++cpp )
          printf("\t               %s\n",*cpp);
    }
    printf("\t h_addrtype    %d\n",hp->h_addrtype); /*** CONVERT TO 
MNEMONIC ***/
    printf("\t h_length      %d\n",hp->h_length);
    cpp = hp->h_addr_list;
    if ( !*cpp )
       printf("\t h_addr_list\n");
    else {
       addr.s_addr = **(u_int **)cpp;
       printf("\t h_addr_list   %s\n",inet_ntoa(addr));
       while ( *++cpp ) {
          addr.s_addr = **(u_int **)cpp;
          printf("\t               %s\n",inet_ntoa(addr));
       }
    }
}


void
print_h_errno()
{
    char *msg;

    switch(h_errno) {
       case HOST_NOT_FOUND:
          msg = "HOST_NOT_FOUND";
          break;
       case TRY_AGAIN:
          msg = "TRY_AGAIN";
          break;
       case NO_RECOVERY:
          msg = "NO_RECOVERY";
          break;
       case NO_ADDRESS:
          msg = "NO_ADDRESS";
          break;
       default:
          msg = "unknown error code";
    }
    printf("h_errno: %s\n",msg);
}



  reply	other threads:[~2004-04-26 22:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-22 15:43 gethostbyname returns only single IP address Calista
2004-04-23  1:42 ` Stuart Fuller
2004-04-23 13:04   ` Calista
2004-04-24  1:32     ` Peter da Silva
2004-04-26 14:05     ` Brian Haley
2004-04-26 20:54       ` Calista
2004-04-26 22:51         ` Brian Haley [this message]
2004-04-27 16:54           ` Calista
2004-04-27 20:36             ` Brian Haley
2004-05-03  3:15             ` Peter da Silva
2004-04-23 13:15   ` Calista
2004-04-23 20:43 ` Rick Jones
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox