Hey, C! What's my IP?

Doran L. Barton fozz at iodynamics.com
Tue Jan 16 22:56:02 MST 2007


Topher Fischer wrote:
> Is there a "standard" (de facto or otherwise) way of finding a local
> machine's IP address in C?  I've googled about, but I still haven't
> found what I'm looking for.  The only thing I've come up with so far is
> calling gethostbyname on my machine's hostname, but that obviously won't
> work when I leave my home network.
> 
> Any ideas?

Warning: This is completely tongue in cheek. :)

How about this?

fh = popen("/sbin/ifconfig eth0", "r");
/* Then just fread/fgets from fh to find the IP */
pclose(fh);

Lotta overhead to find the IP, I know. ;-)

-- 
fozz at iodynamics.com is Doran L. Barton, president/CTO, Iodynamics LLC
Iodynamics: IT and Web services by Linux/Open Source specialists
 "The Civil War began in 1830. Many soldiers repeatedly gave their lives
  for their country. "
    -- Seen in a school report
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fozz.vcf
Type: text/x-vcard
Size: 264 bytes
Desc: not available
Url : http://plug.org/pipermail/plug/attachments/20070116/e5dc2fee/attachment.vcf 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 251 bytes
Desc: OpenPGP digital signature
Url : http://plug.org/pipermail/plug/attachments/20070116/e5dc2fee/attachment.bin 


More information about the PLUG mailing list