gethostbyname()

Russ Nelson nelson at sun.soe.clarkson.edu
Thu Mar 31 01:13:08 AEST 1988


I have a problem with the following program.  It works when compiled
by itself, but when I include it in the phone source (by Jonathan Broome,
gotten from Simtel20), it fails.  There don't seem to be any stupid
#defines in the phone source.  I'm running it on a Sun 3 under SunOS 3.4.

Or, in lieu of solving THIS problem, does anyone have a multiple user talk
program similar to pwrite or phone that operates over tcp/ip?


#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

main()
{
	struct	hostent	*hp, *gethostbyname();
  	char host[32];
	struct	sockaddr_in	locaddr;	/* our own host address */

	gethostname (host, 32);
	hp = gethostbyname ("localhost");
	printf("\r\nnames: hp->hn: %s hp->h_addr: %s(%d.%d.%d.%d)\r\n", hp->h_name, inet_ntoa(hp->h_addr), hp->h_addr[0], hp->h_addr[1], hp->h_addr[2], hp->h_addr[3]);
	bcopy ((char *)hp->h_addr, (char *)&locaddr.sin_addr, hp->h_length);
	printf("\r\nnames: locaddr: %s\r\n", inet_ntoa(locaddr.sin_addr));
	}



More information about the Comp.unix.questions mailing list