recvfrom returns with an error code of 14, EFAULT "Bad Address"

From: Chris Ritchey (rethnor_at_yahoo.com)
Date: 07/03/03


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



Relevant Pages

  • Re: Norton Internet Security professional
    ... I also see that it is a UDP packet and bootpc and bootps ... During the DHCP discovery process, a DHCP client will send a UDP packet with ... yet) to the broadcast address as DA. ...
    (comp.security.firewalls)
  • Broadcasting from an NDIS Intermediate network driver
    ... In this routine I do the following: ... I've been looking at send.c in the ndisprot example DDK code but it's just ... All I want to do at the moment is have my timer routine broadcast a small ... UDP packet when it is triggered. ...
    (microsoft.public.development.device.drivers)
  • Re: Detecting server on lan
    ... My idea was to have them send out a UDP packet to the broadcast address ... Get the InterfaceAddress for the NetworkInterface connected to the LAN ... ss at comp dot lancs dot ac dot uk ...
    (comp.lang.java.programmer)
  • Re: UDP Broadcast on machine with multiple NIC cards
    ... > multiple NIC cards. ... > When I send a UDP packet to INADDR_BROADCAST which is defined as ... > My question is - how do I restrict the broadcast to a specific Interface, ...
    (microsoft.public.win32.programmer.networks)