From owner-freebsd-questions Fri Sep 20 4:10:16 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E5A8937B401 for ; Fri, 20 Sep 2002 04:10:14 -0700 (PDT) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by mx1.FreeBSD.org (Postfix) with SMTP id 8C67E43E4A for ; Fri, 20 Sep 2002 04:10:13 -0700 (PDT) (envelope-from fh31415@gmx.net) Received: (qmail 14826 invoked by uid 0); 20 Sep 2002 11:10:11 -0000 Received: from b115106.adsl.hansenet.de (HELO host1.myhost.mydomain) (62.109.115.106) by mail.gmx.net (mp007-rz3) with SMTP; 20 Sep 2002 11:10:11 -0000 Received: from host1.myhost.mydomain (localhost [127.0.0.1]) by host1.myhost.mydomain (8.12.3/8.12.3) with ESMTP id g8KBBKPN000666 for ; Fri, 20 Sep 2002 13:11:20 +0200 (CEST) (envelope-from azure@host1.myhost.mydomain) Received: (from azure@localhost) by host1.myhost.mydomain (8.12.3/8.12.3/Submit) id g8KBBKIJ000665 for freebsd-questions@freebsd.org; Fri, 20 Sep 2002 13:11:20 +0200 (CEST) Date: Fri, 20 Sep 2002 13:11:20 +0200 From: Frank Heitmann To: freebsd-questions@freebsd.org Subject: Re: gethostbyname Message-ID: <20020920131120.A167@host1.myhost.mydomain> Mail-Followup-To: freebsd-questions@freebsd.org References: <200209200618.XAA05767@idk.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <200209200618.XAA05767@idk.com>; from tony@idk.com on Thu, Sep 19, 2002 at 11:18:56PM -0700 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > 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