Umm... As far as I could see there's not easy way of doing it.
Here's a small sample application I wrote... hopefully it'll help you.
get_ip,c: Get the first IP assigned to an Ethernet device.
=============================================================
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/inetdevice.h>
#include <linux/netdevice.h>
MODULE_DESCRIPTION("Test Module");
MODULE_AUTHOR("Gilboa Davara");
MODULE_LICENSE("GPL");
static int ethernet_id = 0;
module_param(ethernet_id,int,0400);
MODULE_PARM_DESC(ethernet_id,"Ethernet device to display");
static int __init test_startup(void)
{
struct net_device *device;
struct in_device *in_dev;
struct in_ifaddr *if_info;
char dev_name[20];
__u8 *addr;
sprintf(dev_name,"eth%d",ethernet_id);
device = dev_get_by_name(dev_name);
in_dev = (struct in_device *)device->ip_ptr;
if_info = in_dev->ifa_list;
addr = (char *)&if_info->ifa_local;
printk(KERN_WARNING "Device %s IP: %u.%u.%u.%u\n",
dev_name,
(__u32)addr[0],
(__u32)addr[1],
(__u32)addr[2],
(__u32)addr[3]);
return 0;
}
static void __exit test_exit(void)
{
}
module_init(test_startup);
module_exit(test_exit);
=============================================================
On Thu, 2005-06-30 at 13:45 +0300, Amir Binyamini wrote:
> Hello,
> Is there a way to get in a kernel module the ip address which is
> assigned
> to eth0 ?
>
> (for the simplicity let's assume that there is only eth0 and no
> eth0:1 and so on ; and that there is another ethN (where N>1).
>
> I of course know about the ifconfig of net-tools, but this
> is a user space app which opens a socket; I want to get the IP address
> of eth0 in a module in kernel space
>
> I assume that there is an IOCTL call which does this but googling
> did not gave much success.
>
> Regards,
>
> Amir
>
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today it's FREE!
> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
>
> =================================================================
> To unsubscribe, send mail to [EMAIL PROTECTED] with
> the word "unsubscribe" in the message body, e.g., run the command
> echo unsubscribe | mail [EMAIL PROTECTED]
--
Gilboa Davara <[EMAIL PROTECTED]>
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]