[ECOS] gethostname

Andrew Lunn andrew.lunn@ascom.ch
Wed Dec 11 00:36:00 GMT 2002


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



More information about the Ecos-discuss mailing list