the error connection of socket in kernel(new)

shiner chen shiner_chen at yahoo.com.cn
Tue May 31 00:57:42 PDT 2005


In order to test the process of connection of socket in kernel ,I wrote a kld . When i load the kld ,the code try to connect the server of ftp,but i foud the code does not work right . the function , connect ,which return is right ,but ,when i see the status of  connection by "netstat -a" , i found the connection didn't establish!  the detailed code is attached
the following code have mistake!!   The platform is freebsd 5.3
 
  /* create socket */
 td=curthread;
 
 sock.domain = AF_INET;
 sock.type = SOCK_STREAM;
 sock.protocol = 0;
 st = socket(td, &sock);
 /* does create ok? */
 if( st != 0 )
 { /* create error */
  log(LOG_DEBUG,"create socket error!\n");
  goto main_shutdown;
 }
  printf("the fd of socket is%d\n",control_fd);
 /* has create one ok socket */
 printf("the socket is created!");
/////////////////////////////////////////////////////////////////
there are some mistake here!!!!
 /*connect*/ 
 bzero(&sa_in, sizeof sa_in);
 sa_in.sin_family = AF_INET;
 /*this is port of ftp*/
       sa_in.sin_port = htons(21);
       /*this is my computer ip:172.19.11.8*/
       sa_in.sin_addr.s_addr = htonl((((((172 << 8) | 19) << 8) | 11) << 8) | 48);
       
       conn.s=control_fd ;
       conn.name=(char*) &sa_in;
       conn.namelen=sizeof(sa_in);
        /*why do not i connect the server of ftp*/
       nError=connect(td,&conn);
       
       if (!nError){
        printf("connect failed!");
        goto main_shutdown;
       } ;
      printf("connect is secusess!"); 




		
---------------------------------
DO YOU YAHOO!?
  ÑÅ»¢Ãâ·ÑGÓÊÏ䣭ÖйúµÚÒ»¾øÎÞÀ¬»øÓʼþɧÈų¬´óÓÊÏä 


More information about the freebsd-hackers mailing list