This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: gethostname question
- From: "Gary D. Thomas" <gary dot thomas at mind dot be>
- To: Jonathan Larmour <jifl at eCosCentric dot com>
- Cc: Brent Eagles <brent dot eagles at iona dot com>,eCos Discussion <ecos-discuss at sources dot redhat dot com>
- Date: 27 Mar 2003 17:05:54 -0700
- Subject: Re: [ECOS] gethostname question
- References: <20030327150126.A10046@mail.ooc.nf.ca> <3E83732C.8060403@eCosCentric.com>
On Thu, 2003-03-27 at 14:54, Jonathan Larmour wrote:
> Brent Eagles wrote:
> > Hi,
> >
> > I know this has *got* to be a stupid question, but whats the story with
> > gethostname()? Is it supported? If not, what's the preferred way to
> > acquire the hostname?
>
> const char my_hostname[] = "foo.bar.com";
> #define gethostname() my_hostname
>
> :-)
>
> We should have it for the purposes of porting existing Unix code, but it's
> not generally very appropriate for embedded systems which is why no-one's
> ever considered it important enough to do.
>
Here's what I did for a program that wanted to know it's host name,
Normally, the hostname is only used for connectivity, etc, so just
using the IP address works well enough.
static char _hostname[64];
char *
gethostname(char *buf, int len)
{
strcpy(buf, _hostname);
return buf;
}
main()
{
...
#ifdef CYGHWR_NET_DRIVER_ETH0
if (eth0_up) {
inet_ntop(AF_INET, (void *)ð0_bootp_data.bp_yiaddr,
_hostname, sizeof(_hostname));
printf("Setting hostname to: %s\n", _hostname);
}
#endif
...
}
--
.--------------------------------------------------------.
| Mind: Embedded Linux and eCos Development |
|--------------------------------------------------------|
| Gary Thomas email: gary dot thomas at mind dot be |
| Mind ( http://mind.be ) tel: +1 (970) 229-1963 |
| gpg: http://www.chez-thomas.org/gary/gpg_key.asc |
'--------------------------------------------------------'
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss