Date: Wed, 14 Jul 2004 06:31:22 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Miguel Cardenas <mfcardenas@prodigy.net.mx> Cc: freebsd-questions@freebsd.org Subject: Re: getenv() fails II Message-ID: <20040714033122.GC3825@gothmog.gr> In-Reply-To: <200407132225.21260.mfcardenas@prodigy.net.mx> References: <200407130133.41534.mfcardenas@prodigy.net.mx> <20040713064604.GB39956@orion.daedalusnetworks.priv> <200407132225.21260.mfcardenas@prodigy.net.mx>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2004-07-13 22:25, Miguel Cardenas <mfcardenas@prodigy.net.mx> 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 <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040714033122.GC3825>
