Hi , I have been trying to store an array of pointers to sockets in a global structure, to retrieve it at a later point in time. But I'm unable to do so and the pointer points to some invalid address and the kernel crashes Could someone please help me? This program is written in the kernel for Ubuntu 8.10
The following is the Code:
struct my_sock { struct socket *cli_sock; }Sock; Sock *s[10];
struct socket * server_skt; int sock_init() { // Server binds and listens on a particular socket
while(1) { for(i=0;i<3;i++) { s[i]=(Sock *)kmalloc(sizeof(Sock),GFP_KERNEL); iError=sock_create(PF_INET,SOCK_STREAM,IP_PROTO_TCP,&(s[i]->cli_sock)); iError=server_skt->ops->accept(server_skt,s[i]->cli_sock,"connect");
} kthread_run(kconnect,(void *)&data,0);
} } int kconnect(void *data) { for(i=0;i<3;i++) { ilen=sizeof(struct sockaddr); ierror=s[i]->cli_sock->ops->getname(s[i]->cli_sock,struct sockaddr *)&cli_addr,&ilen,1); // Here i get the value of iError as -107 defined as ENOCONN when i tried printing s[i]->cli_sock address it showed a different value in the main fuction and in the thread. Am I losing the pointers here? } }
can anyone please tell me where im goin wrong with the pointers?
Thanks