hi again, Thanks. Atlast got to the kernel.I defined the new NEWSOCKETIOCTL in sockios.h. I wrote a dummy function in af_inet.c and it works when the socket ioctl call is made. After passing the argument in ioctl(socketfd,NEWSOCKIOCTL,NULL) now the next thing I want to do is to pass an argument to the ioctl call.I passed a NULL in the first dummy example. Now if I need to send reference to my own structure,how do i access this user space argument inside af_inet.c? Or do I need to write a translating function which converts the user data from user to kernel space? I want the socket ioctl call to be application independent. And I am currently planning to try the new IOCTL for TCP/IP only. Thanx again. Anil --- Gigi Sullivan <sullivan@sikurezza.org> wrote: > Aiee :) > > Hello! > > On Mon, Sep 17, 2001 at 10:40:42AM -0700, Anil Kumar > wrote: > > hi all, > > I wanted to know how I can write my own socket > > ioctl call. I have to add a new one for the > socket > > option in the kernel. > > Which socket family? (I suppose AF_INET about > what follows) > > [snip] > > But from the user program which ioctl function > > shall I use? Can I use sock_ioctl()? Or will > ioctl() > > You can't use sock_ioctl() from userland since > it's a kernel > function; you have to use the usual ioctl(2) > call. > > Moroever sock_ioctl() is just a simple wrapper > for the real > socket dependant ioctl call (through function > pointers - as > usual within the kernel code). > > > The command should also be implemented somewhere. > > I think af_inet.c for TCP/IP. But I want it to be > > protocol independent so that I can write different > > handlers for different protocols. So where do I > define > > the new ioctl ?? > > Look at net/ipv4/af_inet.c, inet_ioctl() funtion > [1] > That gets called for SOCK_DGRAM, SOCK_STREAM and > SOCK_RAW > socket type, family AF_INET. > > inet_ioctl() gets mapped upon socket creation > (using the > right proto_ops{} variable - this rapresent a > `layer' > between the `userspace view' of a socket and the > first > in kernel `struct socket'. > > If you think your custom ioctl call has to be > protocol dependant, > you should go deeply, adding your code to the > right .c file (i.e. > udp.c, raw.c, tcp_ipv4.c and so on). > > Look at net/ipv4/af_inet.c to see how the struct > proto gets filled > by this `protocol dependant' functions. > > This rapresent the second layer between the > kernel `struct socket' > and the `struct sock' datatypes. > > Well, what I said is, as always, IMHO :) > > Obviously feel free to correct this post if I > said something of wrong, > not so accurate and so on, thanks! > > > Thanx in advance. > > Anil > > > > > > __________________________________________________ > > Terrorist Attacks on U.S. - How can you help? > > Donate cash, emergency relief information > > > http://dailynews.yahoo.com/fc/US/Emergency_Information/ > > - > > Kernelnewbies: Help each other learn about the > Linux kernel. > > Archive: > http://mail.nl.linux.org/kernelnewbies/ > > IRC Channel: irc.openprojects.net / > #kernelnewbies > > Web Page: http://www.kernelnewbies.org/ > > bye bye > > -- gg sullivan > > [1]: What I said are just sorta of hints. > It's not so hard to track down something in the > kernel, well, better, > it's not so hard to track down syscall flows in the > kernel; grep will > really be your friend :) > > -- > Lorenzo Cavallaro `Gigi Sullivan' > <sullivan@sikurezza.org> > > Until I loved, life had no beauty; > I did not know I lived until I had loved. (Theodor > Korner) > __________________________________________________ Terrorist Attacks on U.S. - How can you help? Donate cash, emergency relief information http://dailynews.yahoo.com/fc/US/Emergency_Information/ - Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ IRC Channel: irc.openprojects.net / #kernelnewbies Web Page: http://www.kernelnewbies.org/