Re: Is socket communication socket possible between kernel modules and user space?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi
I have changed SOCK_DGRAM to SOCK_STREAM and the module loaded correctly.
The errno was 0 after listen.

Anurag

--- vaishali  paisal <vaishalipaisal@xxxxxxxxxxxxxx> wrote:
> 
> >See the article by Rubini.
> >
> >http://www.linux-mag.com/2000-12/gear_01.html.
> >
> 
> i tried to write a kernel module which creates a socket.Binds to a port and
> listens on that .But the code gives me the following error when i try  to
> insmod it.
> 
>  error :-95<3>
> socket.o: init_module: Operation not permitted
> Hint: insmod errors can be caused by incorrect module parameters, including
> invalid IO or IRQ parameters.
>       You may find more information in syslog or the output from dmesg
> 
> 
> following is the code
> 
> -----------------------------------------------------------
> #include<linux/module.h>
> #include<linux/byteorder/generic.h>
> #include<linux/kernel.h>
> #include<linux/init.h>
> #include<linux/sched.h>
> #include<linux/timer.h>
> #include<linux/slab.h>
> #include<linux/list.h>
> #include <linux/net.h>
> #include <linux/version.h>
> #include <linux/smp_lock.h>
> #include <net/sock.h>//contains sockaddr_in
> #include <linux/config.h>
> #define PORT 9090
> int time_init(void)
> {
>     int error;
>     struct socket*sock;
>     struct sockaddr_in sin;
>                                                                              
>   
>     error=sock_create(PF_INET,SOCK_DGRAM,0,&sock);
>    if(error<0)
>    {
>  printk("\n error while creating socket");
>     return -1;
>    }
>   sin.sin_family=AF_INET;
>    sin.sin_port=htonl((unsigned short)PORT);
>    sin.sin_addr.s_addr=INADDR_ANY;
>    error=sock->ops->bind(sock,(struct sockaddr*)&sin,sizeof(sin));
>   if(error<0)
>   {
>     printk(KERN_ERR"\nCan't bind to port 80");
>     return -1;
>   }
>   error=sock->ops->listen(sock,5);
>   printk("\n error :%d",error);
>   if(error<0)
>   {
>      printk(KERN_ERR"\n Can't listen ");
>      return -1;
>   }
>                                                                              
>   
>     return 0;
> }
> void time_cleanup(void)
> {
>    printk(KERN_INFO "\nsocket module unloaded\n");
> }
> module_init(time_init);
> module_exit(time_cleanup);
> MODULE_LICENSE("GPL");
> --------------------------------------------------------
> 
> Can anyone suggest what is happening.I think its unable ti listen on that
> port .But why????????
> 
> Regards
> vaishali
> 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux