Jeff Abrahamson on 22 Feb 2004 17:51:02 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] UDP programming question


On Sun, Feb 22, 2004 at 12:31:01PM -0500, gabriel rosenkoetter wrote:
>   [24 lines, 127 words, 778 characters]  Top characters: etionrad
> 
> On Sun, Feb 22, 2004 at 11:33:25AM -0500, Jeff Abrahamson wrote:
> > I've been googling, gdb'ing, and reading man pages for too long.  Any
> > suggestions on what I mean to do here?
> 
> Did you read this bit:
> 
>      If from is non-nil, and the socket is not connection-oriented, the source
>      address of the message is filled in.  fromlen is a value-result parame-
>      ter, initialized to the size of the buffer associated with from, and mod-
>      ified on return to indicate the actual size of the address stored there.

Yup, I read that.  That's why I think my code should work. ;-)

Maybe I'm confused.


> >     struct sockaddr_in faddr; /* address of remote peer */
> >     int num_read;
> > 
> >     memset(&faddr, 0, sizeof(faddr));
> 
> You're explicitly setting faddr to be exactly what will never get
> filled in. That is, nil.

I don't think so.  I'm setting from to point to a structure whose
contents are all zeroes, but fromlen I am passing as sizeof(from):

    memset(&faddr, 0, sizeof(faddr));
    num_read = recvfrom(sock, &buf, MAX_MSG_SIZE, 0,
			(struct sockaddr *)&faddr, &fromlen);
    ret = sendto(sock, &buf, num_read, 0,
		 (struct sockaddr *)&faddr, sizeof(faddr));


In a follow-on mail, I noted that not compiling with threads solved
the problem.  I don't understand at all why that should matter: I
wasn't using threads, just planning to later.

-- 
 Jeff

 Jeff Abrahamson  <http://www.purple.com/jeff/>
 GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B

Attachment: signature.asc
Description: Digital signature