Re: creating process from kernel

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

 



Hi ,
You can do that rather there is tutorial on how to do
socket programming from kernel space by Allesandro
rubini.
Somthing like this.
        int error;
        static int sockfd;
        static struct completion startup =   
        COMPLETION_INITIALIZER(startup);
        error=sock_create(PF_INET,SOCK_DGRAM,
IPPROTO_UDP, &sock);
                                                      
                                                      
               
                if(error < 0){
                printk("MY thread can't create
socket:errno=%d\n", error);
                }
                                                      
                                                      
               
        memset(&source,0,sizeof(source));
        source.sin_family       =PF_INET;
        source.sin_addr.s_addr   
                          =htonl(inet_addr(CLIENTIP));
        source.sin_port         =htons(CLIENT_PORT);
                                                      
                                                      
               
                                                      
                                                      
               
        memset(&target,0,sizeof(target));
        target.sin_family       =PF_INET;
        target.sin_addr.s_addr 
=htonl(inet_addr(SERVERIP));
        target.sin_port         =htons(SERVER_PORT);
        error = sock->ops->bind(sock,(struct sockaddr
*)&source,sizeof(source));
                if (error<0) {
                printk("sockd: can't bind UDP port
%d\n",SERVER_PORT);
                }
               
pid=kernel_thread(sock_thread,&startup,0);
although  abovs code snippet is for simple UDP data
transfer.
I dont think much difference for 
tcp data transfer as well.
--- jhoney jhoney <jhoney_joney@xxxxxxxxxxxxxx> wrote:
> Hello All,
> 
> I am calling socket function (sock_*) from the
> kernel. In my work no application is being run,
> everything should be done from the kernel only. The
> actual application runs on other boad and
> communicates with the pci add-on card which runs
> linux and I have to make use of the TCP/IP stack.To
> test this I have written one server programe which
> is running from the kernel.
> 
> I faced the following problem. when I connected more
> than two clients from other machine to the server
> progarm, it is getting hanged, I guess it is due to
> the accept() function.
> 
> But in actual application program, the process is
> going to block until the accept returns. Since I do
> not have any application, how to simulate this. 
> 
> I had one plan of using kernel threads for accept.
> will it be appropriate?
> 
> Can I create process from the kernel so that for
> each connection , process is going to block when
> accept is called .
> 
> Thanks in advance.
> 
> Regards
> Jhoney


	
		
__________________________________ 
Celebrate Yahoo!'s 10th Birthday! 
Yahoo! Netrospective: 100 Moments of the Web 
http://birthday.yahoo.com/netrospective/

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