Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Sep 2002 13:11:20 +0200
From:      Frank Heitmann <fh31415@gmx.net>
To:        freebsd-questions@freebsd.org
Subject:   Re: gethostbyname
Message-ID:  <20020920131120.A167@host1.myhost.mydomain>
In-Reply-To: <200209200618.XAA05767@idk.com>; from tony@idk.com on Thu, Sep 19, 2002 at 11:18:56PM -0700
References:  <200209200618.XAA05767@idk.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> Anyone have a simple example of how to use this function..

This should work (and is really reduced to a minimum)

=====================================================

struct hostent *hostentry;

if ( (hostentry = gethostbyname("localhost")) == NULL) {
	// Error handling
}
printf("Name: %s; Alias: %s\n",
       hostentry->h_name, hostentry->h_aliases[0]);

=====================================================

At my system the output is just:
"Name: localhost; Alias: (null)"

Note that gethostbyname tries to get information from the nameserver
or /etc/hosts. (I don't know if the order in which these are accessed
depends on /etc/host.conf and I also do not know if the lookup in
/etc/hosts only occurs if the local name server is not running - it
seems so to me, according to gethostbyname(3))

Cheers,
Frank

--
Be aware that this message has been written by a FreeBSD newbie!
Using FreeBSD for approximately 6 weeks and 3 days now :)

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020920131120.A167>