the error connection of socket in kernel(new)

2005-05-31 Thread shiner chen
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 ___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]

Re: the error connection of socket in kernel(new)

2005-05-31 Thread Robert Watson


On Tue, 31 May 2005, shiner chen wrote:

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


How do you initialize the value of control_fd?  You need to load it out 
of td-td_reval[0].


What thread is this running in?


/* 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){


Shouldn't you check for nError != 0 here?  If this is the real code, 
it's probably the case that you're getting EBADF back because you didn't 
set control_fd to the real file descriptor number.


Robert N M Watson


   printf(connect failed!);
   goto main_shutdown;
  } ;
 printf(connect is secusess!);





-
DO YOU YAHOO!?
 ÑÅ»¢Ãâ·ÑGÓÊÏ䣭ÖйúµÚÒ»¾øÎÞÀ¬»øÓʼþɧÈų¬´óÓÊÏä
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]

Re: the error connection of socket in kernel(new)

2005-05-31 Thread Neo-Vortex


On Tue, 31 May 2005, shiner chen wrote:

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

Can't help much with your question, but that last line quoted could be
made much simpler (and less prone to errors) by using the inet_addr()
function... half asleep at the moment... will re-look over your actual
question later :)

~Neo-Vortex
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]