*BSD News Article 87308


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!lucy.swin.edu.au!news.rmit.EDU.AU!news.unimelb.EDU.AU!munnari.OZ.AU!news.mel.connect.com.au!news.mel.aone.net.au!grumpy.fl.net.au!news.webspan.net!newsfeeds.sol.net!newspump.sol.net!howland.erols.net!news.mathworks.com!fu-berlin.de!irz401!orion.sax.de!uriah.heep!news
From: j@uriah.heep.sax.de (J Wunsch)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: socket client pgm read() fail!
Date: 21 Jan 1997 23:31:22 GMT
Organization: Private BSD site, Dresden
Lines: 27
Message-ID: <5c3jka$mtn@uriah.heep.sax.de>
References: <5c238o$4hb@ustsu10.ust.hk>
Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch)
NNTP-Posting-Host: localhost.heep.sax.de
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Newsreader: knews 0.9.6
X-Phone: +49-351-2012 669
X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F  93 21 E0 7D F9 12 D6 4E
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:34409

eekhpang@uxmail.ust.hk (Pang Kin Hung) wrote:

>         if ((n=recv(s, buf, n,0))<0){
>                 printf("read failed\n");        <--------- always fails
>                 printf("n=%d\n",n);
>                 exit(1);
>         }

You should have used -Wall. :-)

``n'' has been used uninitialized.  Replace it by `sizeof buf', and
you're going.

Btw, bzero and bcopy should not be used in favor of memset and memcpy
which are ANSI/ISO C.  Also, your test program is missing some header
files (like unistd.h).

Final hint: in such an error message, at least print the value of the
global variable errno (#include <errno.h>).  This might help you
tracking down the problem.

-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)