kernel module:->
Expand|Select|Wrap|Line Numbers
- #include <linux/skbuff.h>
- #include<linux/module.h>
- #include <linux/socket.h>
- #include <linux/config.h>
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/init.h>
- #include <linux/errno.h>
- #include <linux/string.h>
- #include <linux/stat.h>
- #include <linux/netdevice.h>
- #include <linux/netlink.h>
- #include <linux/types.h>
- #include <linux/capability.h>
- #define MAX_PAYLOAD 1024
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("Test");
- MODULE_DESCRIPTION("Testing Kernel/User socket");
- //static int debug=0;
- //module_param(debug,int ,0);
- MODULE_PARM_DESC(debug,"Debug Information(default 0)");
- static struct sock *nl_sk=NULL;
- static nl_data_ready(struct sock *sk,int len)
- {
- struct sk_buff *skb=NULL;
- struct nlmsghdr *nlh=NULL;
- int err;
- int pid;
- printk("Netlink Socket is Ready\n");
- printk("Received Data from User Space Application\n");
- printk("Waiting .....\n");
- skb = skb_recv_datagram(nl_sk,0,0,&err);
- if(skb == NULL)
- {
- printk("Not Received Any data\n");
- }
- else
- {
- nlh =(struct nlmsghdr *)(skb->data);
- printk("Kernel Received Message %s\n",NLMSG_DATA(nlh));
- strcpy(NLMSG_DATA(nlh),"Its Kernel");
- pid = nlh->nlmsg_pid;
- skb->cb;
- (*(struct netlink_skb_parm*)&((skb)->cb)).pid =0;
- NETLINK_CB(skb).dst_groups;
- NETLINK_CB(skb).groups = 0;
- NETLINK_CB(skb).pid = pid;
- //NETLINK_CB(skb).dst_groups = 0;
- netlink_unicast(nl_sk,skb,pid,MSG_DONTWAIT);
- }
- // sock_release(nl_sk->sk_socket);
- }
- static void netlink_test()
- {
- int err;
- int pid;
- nl_sk = netlink_kernel_create(18,nl_data_ready);
- if(nl_sk < 0)
- {
- printk("Socket Creation fails\n");
- }
- else
- printk("Netlink socket created\n");
- }
- static int netsocket_init(void)
- {
- printk("Intializing netlink socket\n");
- netlink_test();
- return 0;
- }
- void netsocket_exit(void)
- {
- printk("Good Bye\n");
- }
- module_init(netsocket_init);
- module_exit(netsocket_exit);
..request for member 'dst_groups' in something not a structure or union
..request for member 'groups' in something not a structure or union
..request for member 'pid' in something not a structure or union
..request for member 'dst_groups' in something not a structure or union