This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: gethostname
- From: Andrew Lunn <andrew dot lunn at ascom dot ch>
- To: Bob Koninckx <bob dot koninckx at mech dot kuleuven dot ac dot be>
- Cc: ecos-discuss at sources dot redhat dot com
- Date: Wed, 11 Dec 2002 09:36:34 +0100
- Subject: Re: [ECOS] gethostname
- References: <1039595264.19657.3.camel@pc086-2.mech.kuleuven.ac.be>
On Wed, Dec 11, 2002 at 09:27:45AM +0100, Bob Koninckx wrote:
> Hi,
>
> My system gets it IP through DHCP. Is there any way to get hold if its
> IP an hostname at the application level.
>
> I was thinking of doing gethostname followed by gethostbyname.
> Unfortunately, gethostname does not seem to be present. (or did I miss
> something ?)
That would not work....
NAME
gethostname, sethostname - get/set host name
SYNOPSIS
#include <unistd.h>
int gethostname(char *name, size_t len);
int sethostname(const char *name, size_t len);
DESCRIPTION
These functions are used to access or to change the host
name of the current processor.
You want the name of the interface, not the processor. You need to
make an IOCTL call on the interface to get the IP address. SIOCGIFADDR
is the one to do. Then call gethostbyaddr.
Andrew
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss