From: Ben Greear <greearb@candelatech.com>
To: netdev@oss.sgi.com
Subject: Re: Function to determine if IP exists on a net-device?
Date: Thu, 20 Nov 2003 00:30:28 -0800 [thread overview]
Message-ID: <3FBC7BA4.9070501@candelatech.com> (raw)
In-Reply-To: <20031119181529.4c2b861a.davem@redhat.com>
David S. Miller wrote:
> On Wed, 19 Nov 2003 18:05:15 -0800
> Ben Greear <greearb@candelatech.com> wrote:
>
>
>>Is there not a more direct access if I already have the netdevice in question?
>>ie, can I get at the list by looking at dev->ip_ptr struct?
>
>
> Yes, using dev->ip_ptr as a "struct in_device *in_dev"
> do something like this:
>
> struct in_ifaddr *ifa;
>
> read_lock(&in_dev->lock);
> for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
> if (inet_ifa_match(my_addr, ifa)) {
> /* match */
> }
> }
> read_unlock(&in_dev->lock);
>
> should work...
>
The inet_ifa_match thing uses a mask, and was matching everything on the subnet,
or something...
This seems to work though:
static int is_ip_on_dev(struct net_device* dev, __u32 ip) {
int rv = 0;
struct in_device* in_dev = in_dev_get(dev);
if (in_dev) {
struct in_ifaddr *ifa;
read_lock(&in_dev->lock);
for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_address == ip) {
/* match */
rv = 1;
break;
}
}
read_unlock(&in_dev->lock);
in_dev_put(in_dev);
}
return rv;
}
--
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc http://www.candelatech.com
prev parent reply other threads:[~2003-11-20 8:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-19 9:25 Function to determine if IP exists on a net-device? Ben Greear
[not found] ` <20031119173103.1938bc51.davem@redhat.com>
2003-11-20 2:05 ` Ben Greear
[not found] ` <20031119181529.4c2b861a.davem@redhat.com>
2003-11-20 8:30 ` Ben Greear [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3FBC7BA4.9070501@candelatech.com \
--to=greearb@candelatech.com \
--cc=netdev@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).