cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-library Archives

Re: Using libcurl to get local Network IP for ETH0 and ETH1

From: Yves Arrouye <yarrouye_at_expedia.com>
Date: Fri, 21 Dec 2012 10:21:09 -0800

> I'd say ioctl() and SIOCGIFADDR seem like a much easier way to get that
information...

Or check out getifaddrs(3). Attached are a couple files I've used in a
home project that will get you in the right direction (look at
get_if_info, you can also call get_first_if_up_with_mac_addr() to get the
first interface that is up and has a physical (MAC) address, then call
get_if_info() on that).

Feel free to reuse, borrow etc. from that. No warranties :)

YA

On 12/21/12 4:54 AM, "Daniel Stenberg" <daniel_at_haxx.se> wrote:

>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.html

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html

Received on 2012-12-21

These mail archives are generated by hypermail.

donate! Page updated January 05, 2012.
web site info

File upload with ASP.NET