recvfrom returns with an error code of 14, EFAULT "Bad Address"
From: Chris Ritchey (rethnor_at_yahoo.com)
Date: 07/03/03
- Next message: Fletcher Glenn: "Re: handle file > 2GB"
- Previous message: Alex: "gprof with C and C++ not working"
- Next in thread: Barry Margolin: "Re: recvfrom returns with an error code of 14, EFAULT "Bad Address""
- Reply: Barry Margolin: "Re: recvfrom returns with an error code of 14, EFAULT "Bad Address""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 3 Jul 2003 09:20:03 -0700
I'll post the code at the bottom of the post. Whenever I try to
retreive a udp packet sent via broadcast I get the errorcode
EFAULT(bad address). The same program sends out the packets without
any complaints but it fails when retreiving, I'm lost as to why it
would report this error. It returns the number of bytes correctly but
returns the char* buffer as NULL. Any help would be appriciated and I
wouldn't be supprised if I was just missing something simple with
broacasting as I am still learning some aspects of socket
programiing.Thanks in advance to all whom reply and here is the code:
int Communications::GetBroadcastSocket()
{
int toReturn;
int on = 1; // flag to turn on socket options
memset(&broadcast, 0, sizeof(broadcast));
broadcast.sin_family = AF_INET;
broadcast.sin_port = PORTNUM + 1;
broadcast.sin_addr.s_addr = inet_addr(BCAST_ADDR);
if((toReturn = socket(AF_INET, SOCK_DGRAM, 0)) == -1) return -1;
if( SetNonBlocking(toReturn) < 0 ||
setsockopt(toReturn, SOL_SOCKET, SO_REUSEADDR, &on,
sizeof(on)) < 0 ||
setsockopt(toReturn, SOL_SOCKET, SO_BROADCAST, &on,
sizeof(on)) < 0 ||
bind(toReturn, (sockaddr *) &broadcast, sizeof(broadcast)) <
0)
{
close(toReturn);
return -1;
}
return toReturn;
}
- Next message: Fletcher Glenn: "Re: handle file > 2GB"
- Previous message: Alex: "gprof with C and C++ not working"
- Next in thread: Barry Margolin: "Re: recvfrom returns with an error code of 14, EFAULT "Bad Address""
- Reply: Barry Margolin: "Re: recvfrom returns with an error code of 14, EFAULT "Bad Address""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|