Date: Tue, 31 May 2005 15:57:39 +0800 (CST) From: shiner chen <shiner_chen@yahoo.com.cn> To: freebsd-hackers@freebsd.org Subject: the error connection of socket in kernel(new) Message-ID: <20050531075739.38574.qmail@web15501.mail.cnb.yahoo.com>
index | next in thread | raw e-mail
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邮箱-中国第一绝无垃圾邮件骚扰超大邮箱
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050531075739.38574.qmail>
