From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 18-MAR-1993 20:09:52.65
To:	Info-VAX@KL.SRI.COM
CC:	
Subj:	Re: UCX gethostbyname() fails -- record not found


In article <1993Mar11.054358.16525@cs.umb.edu>, mzraly@ra.cs.umb.edu (Michael S. Zraly) writes:

>OK I've been trying to get some example internetworking code to work
>but I've been running into problems with gethostbyname().  Since UCX
>FTP and TELNET both work, I assume its more a programming problem than
>a network problem.
>
>Here is the relevant code:

Your code looks correct--I don't see a problem there, but you can
try the program at the bottom of this message to see if it works.
If it doesn't work then you need a patch for either UCX or the C
run time library or both.  This problem was fixed before I started
working with UCX so I'm kind of hazy on the details, but I think
that the C RTL patch is what you need.  If you are running UCX V2.0B
then you shouldn't need a UCX patch, if not then you should upgrade
UCX on general principle.

						B.J.

#include <stdio.h>
#include <in.h>
#include <netdb.h>

main()
{
    char host_name[256];
    struct hostent *hp;
    int i;

    while (1)
    {
	printf ("\nEnter host: ");
	gets (host_name);
	if (host_name[0] == '\0')
	    exit();

	hp = gethostbyname (host_name);

	if (hp == NULL)
	    printf ("NULL returned by gethostbyname.\n");
	else
	if ((int)hp == -1)
	    printf ("-1 returned by gethostbyname.\n");
	else
	{
	    printf("Name:       %s\n", hp->h_name);

	    if (hp->h_addr_list == NULL)
		printf("No address list returned.\n");
	    else
	    if (hp->h_addr_list[0] == NULL)
		printf("No addresses in the address list.\n");
	    else
	    {
		    printf("Addresses:  %s\n",
			inet_ntoa(*(struct in_addr *)hp->h_addr_list[0]));
		for (i = 1; hp->h_addr_list[i] != NULL; i++)
		    printf("            %s\n",
			inet_ntoa(*(struct in_addr *)hp->h_addr_list[i]));

		if (i != 1)
		    printf("                %d addresses.\n", i);
	    }

	    if (hp->h_aliases == NULL)
		printf("No alias list returned.\n");
	    else
	    if (hp->h_aliases[0] == NULL)
		printf("No aliases in the alias list.\n");
	    else
	    {
		printf("Aliases:    %s\n", hp->h_aliases[0]);
		for (i = 1; hp->h_aliases[i] != NULL; i++)
		    printf("            %s\n", hp->h_aliases[i]);

		if (i != 1)
		    printf("                %d aliases.\n", i);
	    }
	}
    }
}

