Jeff Abrahamson on 22 Feb 2004 17:28: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 11:33:25AM -0500, Jeff Abrahamson wrote:
>   [31 lines, 153 words, 1040 characters]  Top characters: etranodi
> 
> Here's a code snippet.  It should receive a UDP packet and then send
> it back to the guy it got it from.  For brevity in this email, I've
> stripped error checking.
> 
> What actually happens is that it receives the UDP packet's contents
> just fine, but faddr is not filled in, remaining all zeroes.  So the
> sendto fails with a bad parameter error.
> 
> I've been googling, gdb'ing, and reading man pages for too long.  Any
> suggestions on what I mean to do here?
> 
> Thanks.
> 
> 
>     struct sockaddr_in faddr; /* address of remote peer */
>     int num_read;
> 
>     memset(&faddr, 0, sizeof(faddr));
>     num_read = recvfrom(sock, &buf, MAX_MSG_SIZE, 0,
>                         (struct sockaddr *)&faddr, &fromlen);
>     printf("Server received message: '%s'\n", buf);
> 
>     /* Now just send it back to client to show that we can. */
>     ret = sendto(sock, &buf, num_read, 0,
>                  (struct sockaddr *)&faddr, sizeof(faddr));

I stopped using threads and the code worked.  That is, I removed this
from the compile line:

    `pkg-config --cflags --libs gthread-2.0`

I'm glad it works, but I don't understand why it should have
mattered.  Any clues?

-- 
 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