All of lore.kernel.org
 help / color / mirror / Atom feed
* Gettin own IP address thorugh ioctl in kernel space.
@ 2006-07-19  9:33 Chinmaya Mishra
  2006-07-19  9:52 ` Parag N(पराग़)
  2006-07-19 11:56 ` Erik Mouw
  0 siblings, 2 replies; 5+ messages in thread
From: Chinmaya Mishra @ 2006-07-19  9:33 UTC (permalink / raw)
  To: Linux Kernel

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Gettin own IP address thorugh ioctl in kernel space.
  2006-07-19  9:33 Gettin own IP address thorugh ioctl in kernel space Chinmaya Mishra
@ 2006-07-19  9:52 ` Parag N(पराग़)
  2006-07-19 11:56 ` Erik Mouw
  1 sibling, 0 replies; 5+ messages in thread
From: Parag N(पराग़) @ 2006-07-19  9:52 UTC (permalink / raw)
  To: chinmaya; +Cc: Linux Kernel

Hi,
On 7/19/06, Chinmaya Mishra <chinmaya4@gmail.com> wrote:
> 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.
 Check point 29 from http://kasperd.net/~kasperd/comp.os.linux.development.faq.
Modify that source code according to your needs.
Regards,
Parag.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Gettin own IP address thorugh ioctl in kernel space.
  2006-07-19  9:33 Gettin own IP address thorugh ioctl in kernel space Chinmaya Mishra
  2006-07-19  9:52 ` Parag N(पराग़)
@ 2006-07-19 11:56 ` Erik Mouw
  2006-07-19 15:07   ` Jan Engelhardt
  1 sibling, 1 reply; 5+ messages in thread
From: Erik Mouw @ 2006-07-19 11:56 UTC (permalink / raw)
  To: chinmaya; +Cc: Linux Kernel

On Wed, Jul 19, 2006 at 03:03:24PM +0530, Chinmaya Mishra wrote:
> 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.

> 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.

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


Erik

-- 
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Gettin own IP address thorugh ioctl in kernel space.
  2006-07-19 11:56 ` Erik Mouw
@ 2006-07-19 15:07   ` Jan Engelhardt
  2006-07-19 15:23     ` Valdis.Kletnieks
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Engelhardt @ 2006-07-19 15:07 UTC (permalink / raw)
  To: Erik Mouw; +Cc: chinmaya, Linux Kernel

>> 
>> 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
-- 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Gettin own IP address thorugh ioctl in kernel space.
  2006-07-19 15:07   ` Jan Engelhardt
@ 2006-07-19 15:23     ` Valdis.Kletnieks
  0 siblings, 0 replies; 5+ messages in thread
From: Valdis.Kletnieks @ 2006-07-19 15:23 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Erik Mouw, chinmaya, Linux Kernel

[-- Attachment #1: Type: text/plain, Size: 400 bytes --]

On Wed, 19 Jul 2006 17:07:47 +0200, Jan Engelhardt said:
> >> 
> >> 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....

[-- Attachment #2: Type: application/pgp-signature, Size: 226 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-07-19 15:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-19  9:33 Gettin own IP address thorugh ioctl in kernel space Chinmaya Mishra
2006-07-19  9:52 ` Parag N(पराग़)
2006-07-19 11:56 ` Erik Mouw
2006-07-19 15:07   ` Jan Engelhardt
2006-07-19 15:23     ` Valdis.Kletnieks

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.