From owner-freebsd-hackers@FreeBSD.ORG Tue May 31 11:20:06 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4C16216A41C for ; Tue, 31 May 2005 11:20:06 +0000 (GMT) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [204.156.12.53]) by mx1.FreeBSD.org (Postfix) with ESMTP id F0B0443D54 for ; Tue, 31 May 2005 11:20:05 +0000 (GMT) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by cyrus.watson.org (Postfix) with ESMTP id 366D546B10; Tue, 31 May 2005 07:20:05 -0400 (EDT) Date: Tue, 31 May 2005 12:20:40 +0100 (BST) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: shiner chen In-Reply-To: <20050531075739.38574.qmail@web15501.mail.cnb.yahoo.com> Message-ID: <20050531121853.Q85876@fledge.watson.org> References: <20050531075739.38574.qmail@web15501.mail.cnb.yahoo.com> MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="0-1032786843-1117538440=:85876" Cc: freebsd-hackers@freebsd.org Subject: Re: the error connection of socket in kernel(new) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2005 11:20:06 -0000 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--