Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi All,
Is it possible to use create a raw socket in kernel space ? If possible is there any snippet/code which I can use to enhance my application ?
Any help is highly appreciated.
-Thanks in advance
Thanks Irmin,
Does this mean I need to call setsockopt to inform the kernal not to add the headers and create my own ip pkt ? Or there is any equivalant system call for it ?
-Thanks
If you do not want the IPv4 layer to create an IP header, you have to set the option IP_HDRINCL. (see man 7 raw)
Use kernel_setsockopt for this. Basically the kernel socket interface is the same as the system calls.
See <kernel-source>/include/linux/net.h for details.
But I wonder, if this really what you want to do, since sending and receiving raw ip packets can also be done using socket/setsockopt/sendmsg/recvmsg system calls.
Thanks Irmin,
This was helpful. I really appreciate it.
BTW what kind of header files I need ? I tried these hdr files but its not compiling and giving me error of files not found. I tried to compile this on Linux machine as well as Vmware.
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <linux/net/net.h>
#include <linux/fs.h>
#include <asm/segment.h>
#include <asm/uaccess.h>
#include <linux/buffer_head.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
Hi,
I have created the foo.c file for socket. I am calling the sock_sendmsg and etc as kernal system calls directly. I have included the files which are needed for this calls.
My question is should I build this foo.c using "gcc foo.c" or I have to build this file in kernal mode and than load the kernal using insmode ?
Any help is good.
-Thanks
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.