Date: Tue, 31 May 2005 12:20:40 +0100 (BST) From: Robert Watson <rwatson@FreeBSD.org> To: shiner chen <shiner_chen@yahoo.com.cn> Cc: freebsd-hackers@freebsd.org Subject: Re: the error connection of socket in kernel(new) Message-ID: <20050531121853.Q85876@fledge.watson.org> In-Reply-To: <20050531075739.38574.qmail@web15501.mail.cnb.yahoo.com> References: <20050531075739.38574.qmail@web15501.mail.cnb.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--0-1032786843-1117538440=:85876
Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE
On Tue, 31 May 2005, shiner chen wrote:
> In order to test the process of connection of socket in kernel ,I wrote=
=20
> a kld . When i load the kld ,the code try to connect the server of=20
> ftp,but i foud the code does not work right . the function , connect=20
> ,which return is right ,but ,when i see the status of connection by=20
> "netstat -a" , i found the connection didn't establish! the detailed=20
> code is attached the following code have mistake!! The platform is=20
> freebsd 5.3
>
> /* create socket */
> td=3Dcurthread;
>
> sock.domain =3D AF_INET;
> sock.type =3D SOCK_STREAM;
> sock.protocol =3D 0;
> st =3D socket(td, &sock);
> /* does create ok? */
> if( st !=3D 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=
=20
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 =3D AF_INET;
> /*this is port of ftp*/
> sa_in.sin_port =3D htons(21);
> /*this is my computer ip:172.19.11.8*/
> sa_in.sin_addr.s_addr =3D htonl((((((172 << 8) | 19) << 8) | 11) <<=
8) | 48);
>
> conn.s=3Dcontrol_fd ;
> conn.name=3D(char*) &sa_in;
> conn.namelen=3Dsizeof(sa_in);
> /*why do not i connect the server of ftp*/
> nError=3Dconnect(td,&conn);
>
> if (!nError){
Shouldn't you check for "nError !=3D 0" here? If this is the real code,=20
it's probably the case that you're getting EBADF back because you didn't=20
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!?
> =D1=C5=BB=A2=C3=E2=B7=D1G=D3=CA=CF=E4=A3=AD=D6=D0=B9=FA=B5=DA=D2=BB=BE=
=F8=CE=DE=C0=AC=BB=F8=D3=CA=BC=FE=C9=A7=C8=C5=B3=AC=B4=F3=D3=CA=CF=E4
--0-1032786843-1117538440=:85876--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050531121853.Q85876>
