curl-library
Re: Using libcurl to get local Network IP for ETH0 and ETH1
From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 21 Dec 2012 13:54:15 +0100 (CET)
Date: Fri, 21 Dec 2012 13:54:15 +0100 (CET)
On Thu, 20 Dec 2012, Bernard Evensrud wrote:
> Can libcurl from within a C application be used to get the network IP
> address for ETH0 and ETH1 on Linux, just like ifconfig eth0 | grep
> \"inet addr\" | awk -F: '{print $2}' | awk '{print$1}'?
You can tell libcurl to use that address as a source address when doing
network operations by setting CURLOPT_INTERFACE.
You can then extract that info with curl_easy_getinfo()'s CURLINFO_LOCAL_IP
> I do not need the localhost IP or external IP. Just the local network IP
> received from DHCP.
I'd say ioctl() and SIOCGIFADDR seem like a much easier way to get that
information...
-- / daniel.haxx.se ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.htmlReceived on 2012-12-21