Skip to contentSkip to conversation

Gettin own IP address thorugh ioctl in kernel space.

DISCUSSION Chinmaya Mishra 5 participants 5 messages Jul 19, 2006

lore
Share & tools
lore
#0 lore raw

Hi,

Can you provide an example how to invoke ioctl on
device in kernel module.

For example. I want to find out the IP address of
my eth0 and I want to make SIOCSIFADDR on it from kernel module.

At user space i am doing it like this.....

unsigned long *ip;
char *iface;
int sockfd;
struct ifreq ifr;
strcpy(ifr.ifr_name, iface); // interface name 'eth0'
sockfd = socket(AF_INET,SOCK_DGRAM,0); ioctl(sockfd, SIOCGIFADDR, (char*)&ifr); memcpy(ip, &(ifr.ifr_addr.sa_data[2]),4); //Copy the ip addr close(sockfd);

How to port this in keernel space.

Thank you.
Chinmaya

#1 lore raw

Hi,

Quoted 22 lines · Chinmaya Mishra

Hi,

Can you provide an example how to invoke ioctl on
device in kernel module.

For example. I want to find out the IP address of
my eth0 and I want to make SIOCSIFADDR on it from
kernel module.

At user space i am doing it like this.....

unsigned long *ip;
char *iface;
int sockfd;
struct ifreq ifr;
strcpy(ifr.ifr_name, iface); // interface name 'eth0'
sockfd = socket(AF_INET,SOCK_DGRAM,0); ioctl(sockfd, SIOCGIFADDR, (char*)&ifr); memcpy(ip, &(ifr.ifr_addr.sa_data[2]),4); //Copy the ip addr close(sockfd);

Quoted 1 line

How to port this in keernel space.

Check point 29 from http://kasperd.net/~kasperd/comp.os.linux.development.faq.
Modify that source code according to your needs.
Regards,
Parag.

#2 lore raw
In reply to Chinmaya Mishra
Quoted 6 lines · Chinmaya Mishra

Can you provide an example how to invoke ioctl on
device in kernel module.

For example. I want to find out the IP address of
my eth0 and I want to make SIOCSIFADDR on it from
kernel module.

Sounds like a badly designed module. Do it from userspace.

Quoted 12 lines

At user space i am doing it like this.....

unsigned long *ip;
char *iface;
int sockfd;
struct ifreq ifr;
strcpy(ifr.ifr_name, iface); // interface name 'eth0'
sockfd = socket(AF_INET,SOCK_DGRAM,0); ioctl(sockfd, SIOCGIFADDR, (char*)&ifr); memcpy(ip, &(ifr.ifr_addr.sa_data[2]),4); //Copy the ip addr close(sockfd);

Quoted 1 line

How to port this in keernel space.

Not. For the same reasons why you shouldn't read files from kernel space.

Erik

Signature · 2 lines
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands
#3 lore raw
Quoted 6 lines
Quoted 2 lines

How to port this in keernel space.

Not. For the same reasons why you shouldn't read files from kernel space.

About reading files, tell that
- ndiswrapper
- ralink drivers from RaLinkTech and Serialmonkey
:-)

Jan Engelhardt

#4 lore raw
Quoted 9 lines · Jan Engelhardt
Quoted 6 lines
Quoted 2 lines

How to port this in keernel space.

Not. For the same reasons why you shouldn't read files from kernel space.

About reading files, tell that
- ndiswrapper
- ralink drivers from RaLinkTech and Serialmonkey

Out-of-tree code involving binary blobs shouldn't be held up as examples of how we do things in-tree....