AnsweredAssumed Answered

Socket broadcast

Question asked by Silvia Gonzalez on Nov 20, 2014
Latest reply on Dec 3, 2014 by Silvia Gonzalez

Hello

I have the next net.

net1.png

I execute the tcpdump -X -i br0, with th next result.

tcpdump.png

but, When I execute my program to receive the mesage, I don't receive any messsage. My program is the next.

int main(int argc, char *argv[]) {

struct sockaddr_in server;
uint16_t *buf2=malloc(1 * sizeof(uint16_t));
/* Create socket for sending/receiving datagrams */
  if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
  perror("socket() failed");

 

  /* allow broadcast messages for the socket */
   int true = 1;
   rc=setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &true, sizeof(true));

     /* Construct local address structure */
     memset(&broadcastAddr, 0, sizeof(broadcastAddr));   /* Zero out structure */
     broadcastAddr.sin_family = AF_INET; /* Internet address family */
     broadcastAddr.sin_addr.s_addr = htonl(INADDR_ANY);

    broadcastAddr.sin_port = htons(1000);      /* Broadcast port */


     localIPLen = sizeof(uint16_t);  /* Find length of localIP */

     mess=recvfrom(sock, buf2, localIPLen , 0, (struct sockaddr *) &broadcastAddr, sizeof(broadcastAddr)); 

  }

I can't find the error. Can anyone help me.

 

Thanks.

Outcomes