From owner-freebsd-questions@FreeBSD.ORG Wed Jul 14 03:31:28 2004 Return-Path: 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 B452B16A4CE for ; Wed, 14 Jul 2004 03:31:28 +0000 (GMT) Received: from brain.otenet.gr (brain.otenet.gr [195.170.0.25]) by mx1.FreeBSD.org (Postfix) with ESMTP id E49FB43D41 for ; Wed, 14 Jul 2004 03:31:27 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from gothmog.gr (patr530-a161.otenet.gr [212.205.215.161]) i6E3VOhh028201; Wed, 14 Jul 2004 06:31:24 +0300 Received: from gothmog.gr (gothmog [127.0.0.1]) by gothmog.gr (8.12.11/8.12.11) with ESMTP id i6E3VMAt004178; Wed, 14 Jul 2004 06:31:22 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from giorgos@localhost) by gothmog.gr (8.12.11/8.12.11/Submit) id i6E3VMP7004177; Wed, 14 Jul 2004 06:31:22 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Wed, 14 Jul 2004 06:31:22 +0300 From: Giorgos Keramidas To: Miguel Cardenas Message-ID: <20040714033122.GC3825@gothmog.gr> References: <200407130133.41534.mfcardenas@prodigy.net.mx> <20040713064604.GB39956@orion.daedalusnetworks.priv> <200407132225.21260.mfcardenas@prodigy.net.mx> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200407132225.21260.mfcardenas@prodigy.net.mx> cc: freebsd-questions@freebsd.org Subject: Re: getenv() fails II X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Jul 2004 03:31:28 -0000 On 2004-07-13 22:25, Miguel Cardenas wrote: > Efectively was that way... in Linux it used to work fine... then my > next question should be... is there any other way to retrieve the > hostname? and... as a normal user? Yep. See the manpage of gethostname(). This should work fine: 1 #include 2 #include 3 #include 4 5 #define HOST_NAME_MAX 255 6 static char buf[HOST_NAME_MAX + 1]; 7 8 int 9 main(void) 10 { 11 12 if (gethostname(buf, HOST_NAME_MAX) == -1) { 13 fprintf(stderr, 14 "error: my hostname is not defined\n"); 15 exit(EXIT_FAILURE); 16 } 17 printf("%s\n", buf); 18 return EXIT_SUCCESS; 19 } Giorgos