Article View: comp.os.linux.networking
Article #814Re: socket programming problem
From: Jeffery A. Collins
Date: Wed, 21 Dec 1994 15:38
Date: Wed, 21 Dec 1994 15:38
30 lines
2101 bytes
2101 bytes
There is a small bug in your recv program. In your recvfrom() call the
last argument (&len in your example) is both an input and an output. It needs
to be initialized to the size of the sin2 argument. The following change
makes your program work:
*** recv.c Wed Dec 21 10:31:42 1994
--- recv.c.new Wed Dec 21 10:30:50 1994
***************
*** 43,48 ****
--- 43,49 ----
while (1)
{
+ len = sizeof(struct sockaddr);
n = recvfrom(s, msg, 1300, 0, (struct sockaddr *)&sin2, &len);
if (n < 0)
fprintf(stderr, "recvfrom error: %d\n", errno);
The reason that you got different results compiling it with debug and
without debug is that len was initialized (or actually not initialized) to
different values. With debug, it must have had a value greater than the size
of a struct sockaddr.
Jeff
--
==============================================================================
Jeff Collins Email: collins@paros.com
President Phone: (404) 874-5122
Paros Software, Inc FAX: (404) 874-8171
Technical Details
Message-ID:
<COLLINS.94Dec21103838@zeke.paros.com>Path:
arc1-ca.pugleaf.net!nntp.gmd.de!Germany.EU.net!howland.reston.ans.net!swrinde!emory!metro.atlanta.com!hood.paros.com!hood.paros.com!collinsReferences:
<3d7dvb$lcl@lennon.cc.gatech.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,e67558230f76e1ad X-Google-Attributes: gid11318c,public X-Google-Thread: 10c696,e67558230f76e1ad X-Google-Attributes: gid10c696,public X-Google-Thread: 100b1f,e67558230f76e1ad X-Google-Attributes: gid100b1f,public X-Google-Thread: 10669a,e67558230f76e1ad X-Google-Attributes: gid10669a,public X-Google-ArrivalTime: 1994-12-21 07:38:38 PST Path: arc1-ca.pugleaf.net!nntp.gmd.de!Germany.EU.net!howland.reston.ans.net!swrinde!emory!metro.atlanta.com!hood.paros.com!hood.paros.com!collins From: collins@zeke.paros.com (Jeffery A. Collins) Newsgroups: comp.os.linux.networking,comp.os.linux.help,comp.os.linux.development.apps,gnu.gcc.help Subject: Re: socket programming problem Date: 21 Dec 1994 15:38:38 GMT Organization: Paros, Inc. Lines: 30 Message-ID: <COLLINS.94Dec21103838@zeke.paros.com> References: <3d7dvb$lcl@lennon.cc.gatech.edu> NNTP-Posting-Host: zeke.paros.com In-reply-to: selbie@cc.gatech.edu's message of 20 Dec 1994 15:14:35 -0500