[vox-tech] getting IP address in C

Rod Roark vox-tech@lists.lugod.org
Wed, 16 Apr 2003 04:54:43 -0700


On Wednesday 16 April 2003 02:41 am, Ryan wrote:
> Is there a quick and easy way in C to get the IP address of the current
> machine the program is running on?

Depends on what you want to do.  The problem with your
question is that a machine can have multiple IP addresses.

Using 127.0.0.1 will usually work if you want to open a
connection to something running on the local machine.

Otherwise you can try gethostname() and resolve it to an IP
with gethostbyname().

-- 
Rod Roark, Sunset Systems     http://www.sunsetsystems.com/
Offering preconfigured Linux computers, custom software and
remote system administration services.
Public Key: http://www.sunsetsystems.com/rodspublickey.asc