From owner-freebsd-hackers@FreeBSD.ORG Mon Dec 20 17:26:06 2004 Return-Path: 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 A610416A4CE for ; Mon, 20 Dec 2004 17:26:06 +0000 (GMT) Received: from hotmail.com (bay20-f5.bay20.hotmail.com [64.4.54.94]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7EE2543D1F for ; Mon, 20 Dec 2004 17:26:06 +0000 (GMT) (envelope-from adityaeipl@hotmail.com) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Mon, 20 Dec 2004 09:26:06 -0800 Message-ID: Received: from 203.124.158.219 by by20fd.bay20.hotmail.msn.com with HTTP; Mon, 20 Dec 2004 17:25:08 GMT X-Originating-IP: [203.124.158.219] X-Originating-Email: [adityaeipl@hotmail.com] X-Sender: adityaeipl@hotmail.com From: "aditya eipl" To: freebsd-hackers@freebsd.org Date: Mon, 20 Dec 2004 22:55:08 +0530 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 20 Dec 2004 17:26:06.0141 (UTC) FILETIME=[FCB68ED0:01C4E6B8] Subject: roblem related to sockets in FreeBSD Kernel X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Dec 2004 17:26:06 -0000 Hi, I am writing a socket server in the kernel mode in FreeBSD 4.6.2. This program accepts connection and receives data on the socket. But we are not getting the data.In the code: We come to know that the we are connected we also get the notification for receipt of data but are unable to fetch the data. Can anybody please let me know what is wrong in my code? Here are the code snippets: After calling soaccept() I have: so->so_upcallarg = (caddr_t)upcallargs; so->so_upcall = socket_incoming; so->so_rcv.sb_flags |= SB_UPCALL; so->so_snd.sb_flags |= SB_UPCALL; I dont know whether this is required. But as I saw this in the FreeBSD source I put it. I have written socket_incoming as follows: void socket_incoming(struct socket *so, void *arg, int waitflag) { log(LOG_ALERT, "hello: socket_incoming%x \n",so->so_state); if(so->so_state & SS_ISCONNECTED) server_receive(so); return; } I have written server receiveas follows: int server_receive(struct socket *so) { struct uio uio; struct iovec uiovec[2]; struct mbuf *mp; int err,i; int flags, s; struct socket *head = so; struct sockaddr *sa = NULL; char buff[MAX_BYTES_TO_PROCESS]; log(LOG_ALERT, "hello: connected now try to read data (%x %x) \n", so, socket_server); flags = MSG_DONTWAIT ; uiovec[0].iov_base = buff; uiovec[0].iov_len = MAX_BYTES_TO_PROCESS; uiovec[1].iov_base = NULL; uiovec[1].iov_len = 0; uio.uio_iov = &uiovec[0]; uio.uio_iovcnt = 1; uio.uio_offset = -1; uio.uio_resid = MAX_BYTES_TO_PROCESS; uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_READ; uio.uio_procp = p; err = -1; { log(LOG_ALERT, "hello: Calling soreceive\n"); err = soreceive(so, (so->so_state & SS_ISCONNECTED) ? NULL : &sa, &uio, &mp, NULL, &flags); /* err = so->so_proto->pr_usrreqs->pru_soreceive(so, (so->so_state & SS_ISCONNECTED) ? NULL : &sa, &uio, NULL, 0, &flags); */ /* one of the above should work but both of them do not work :( */ if (err < 0) { log(LOG_ALERT, "hello: socket receive err \n"); goto sock_server_exit; } log(LOG_ALERT, "hello: socket receive err = %d \n", err); } log(LOG_ALERT, "hello: iolen = %d \n data : ",uio.uio_iov[0].iov_len); for(i=0;i< uio.uio_resid;i++) { log(LOG_ALERT, "%c ",uio.uio_iov[0].iov_base[MAX_BYTES_TO_PROCESS - i]); } /* we see garbage here :( */ log(LOG_ALERT, "hello: data = %c \n",uio.uio_iov[0].iov_base[uio.uio_resid-3]); log(LOG_ALERT, "hello: iovcnt = %d \n",uio.uio_iovcnt); log(LOG_ALERT, "hello: offset = %d \n",uio.uio_offset); log(LOG_ALERT, "hello: resid = %d \n",uio.uio_resid); log(LOG_ALERT, "hello: rw = %d \n",uio.uio_rw); log(LOG_ALERT, "hello: msg header iovcnt = %s \n",(char *)mp->m_dat); sock_server_exit: return 0; } Any help will be much appreciated. _________________________________________________________________ Searching for your soulmate? Zero in on the perfect choice. http://www.astroyogi.com/newmsn/astrodate/ Try MSN Astrodate now!