* API to find out wether a IP address is local?
@ 2011-06-14 7:31 Clemens Eisserer
2011-06-14 9:11 ` John Haxby
0 siblings, 1 reply; 3+ messages in thread
From: Clemens Eisserer @ 2011-06-14 7:31 UTC (permalink / raw)
To: netfilter
Hi,
I know this question is not really netfilter related, sorry. But I
didn't know where to ask it instead.
Does Linux have an API to find out wether an IP address is local?
Thanks, Clemens
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: API to find out wether a IP address is local?
2011-06-14 7:31 API to find out wether a IP address is local? Clemens Eisserer
@ 2011-06-14 9:11 ` John Haxby
2011-06-14 9:48 ` Jan Engelhardt
0 siblings, 1 reply; 3+ messages in thread
From: John Haxby @ 2011-06-14 9:11 UTC (permalink / raw)
To: Clemens Eisserer; +Cc: netfilter
On 14/06/11 08:31, Clemens Eisserer wrote:
> I know this question is not really netfilter related, sorry. But I
> didn't know where to ask it instead.
>
> Does Linux have an API to find out wether an IP address is local?
netdevice(7) tells you how to extract all the IPv4 addresses from the
network devices; /proc/net/if_inet6 lists all the local IPv6 addresses.
This is not necessarily useful though: redirection happens in all kinds
of ways and all kinds of places and while getpeeraddr(2) might tell you
that you're connected to one of google.com's addresses, that could be
far from the truth. (Of course, the inverse is true, just because you
thought you were connecting to a local address doesn't mean that some
wild and woolly iptables configuration didn't send your packets winging
half way around the globe.)
jch
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: API to find out wether a IP address is local?
2011-06-14 9:11 ` John Haxby
@ 2011-06-14 9:48 ` Jan Engelhardt
0 siblings, 0 replies; 3+ messages in thread
From: Jan Engelhardt @ 2011-06-14 9:48 UTC (permalink / raw)
To: John Haxby; +Cc: Clemens Eisserer, netfilter
On Tuesday 2011-06-14 11:11, John Haxby wrote:
>On 14/06/11 08:31, Clemens Eisserer wrote:
>> I know this question is not really netfilter related, sorry. But I
>> didn't know where to ask it instead.
>>
>> Does Linux have an API to find out wether an IP address is local?
>
>netdevice(7) tells you how to extract all the IPv4 addresses from the
>network devices; /proc/net/if_inet6 lists all the local IPv6 addresses.
The API is netlink:
ip route get 2001:db8::1
and test for whether the standalone keyword "local" is present. (Or
alternatively, do the interfacing with netlink yourself using something
like libmnl.)
Due to things like client-side transparent proxying using TPROXY, it is
possible that "local" is returned even though the address is not on
any interface - but depending on your definition of "local" that might
just be what is desired.
Oh and stop using procfs, it is way too inferior.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-06-14 9:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-14 7:31 API to find out wether a IP address is local? Clemens Eisserer
2011-06-14 9:11 ` John Haxby
2011-06-14 9:48 ` Jan Engelhardt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.