Determining one's own IP address.

Jonathan Knight jonathan at cs.keele.ac.uk
Wed Dec 13 22:03:39 AEST 1989


>From article <5215 at tekcrl.LABS.TEK.COM>, by terryl at tekcrl.LABS.TEK.COM:
> 
>      Well, as they say (whoever THEY are!! (-:), RTFM (at least for a BSD
> system):
> 
> 	sethostid(2), gethostid(2), hostid(1)

Ok, I did 'man hostid' and it says...

                      This numeric value is expected to be unique
     across all hosts and is normally set to the host's Internet
     address.

Note that it says 'normally' so you can't assume it will be.  This is
for an Ultrix 1.2 vax.  A sun of course is different, the hostid is
encoded in the ROM at the factory and can't be changed, so it's just
a "number that's unique accross all sun hosts." (sun manual)

The program 'ifconfig' will give you the IP address for your host.
The output formats vary a little, but it seems consistent for getting
the IP address out.  (e.g.  'ifconfig qe0' or 'ifconfig le0' or
'ifconfig ie0' depending on your interface name)

I have never tried to get the IP address for an interface from within
a C program however here are a few manual pages that should put you on
the right track.

On Sun.
	man 4n if
	man 4n routing

On Ultrix
	man 4n intro
-- 
  ______    JANET :jonathan at uk.ac.keele.cs     Jonathan Knight,
    /       BITNET:jonathan%cs.kl.ac.uk at ukacrl Department of Computer Science
   / _   __ other :jonathan at cs.keele.ac.uk     University of Keele, Keele,
(_/ (_) / / UUCP  :...!ukc!kl-cs!jonathan      Staffordshire.  ST5 5BG.  U.K.



More information about the Comp.unix.wizards mailing list