get internet v6 address from interface name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Good morning, can anyone give me a hint for this problem?

I have written a kernel module.

I would need to know how to retrieve the ipv6 address structure
knowing the network interface name.

For ipv4, i do as follows:

int get_ifaddr_by_name(const char *ifname, __u32 * addr)
{
       struct net_device *pnet_device;
       struct in_device *pin_device;
       struct in_ifaddr* inet_ifaddr;

       read_lock_bh(&dev_base_lock);

       pnet_device = first_net_device();
       while (pnet_device != NULL)
       {
               if ((netif_running(pnet_device))
                               && (pnet_device->ip_ptr != NULL)
                               && (strcmp(pnet_device->name, ifname) == 0))
               {
                       pin_device =
                               (struct in_device *) pnet_device->ip_ptr;
                       inet_ifaddr = pin_device->ifa_list;
                       if(inet_ifaddr == NULL)
                       {
                               printk("ifa_list is null!\n");
                               break;
                       }
                       /* ifa_local: ifa_address is the remote point in ppp */
                       *addr = (inet_ifaddr->ifa_local);
                       read_unlock_bh(&dev_base_lock);
                       return 1;
               }
               pnet_device = next_net_device(pnet_device);
       }

       read_unlock_bh(&dev_base_lock);
       return -1;              /* address not found! */
}

thanks for any suggestion/hint/example

giacomo.

-- 
Giacomo S.
http://www.giacomos.it

- - - - - - - - - - - - - - - - - - - - - -

IPFIREwall (http://www.giacomos.it/ipfire) viene presentato
all'Universita` degli Studi di Udine, il 28 ottobre, in occasione del
Linux Day 2006:
http://iglu.cc.uniud.it/linuxday

- - - - - - - - - - - - - - - - - - - - - -

 . ''  `.
:   :'    :
 `.  ` '
    `- Debian GNU/Linux -- The power of freedom
        http://www.debian.org
-
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux