UDP Broadcast

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UDP Broadcast

1,639 Views
iaccy
Contributor I

How does one set up a UDP socket to receive broadcast messages. I've managed to get multicast working but I need broadcast for NBNS.

 

Thanks

Labels (1)
Tags (1)
0 Kudos
Reply
1 Reply

673 Views
w2vy
Contributor V

iaccy wrote:

How does one set up a UDP socket to receive broadcast messages. I've managed to get multicast working but I need broadcast for NBNS.

 

Thanks


 

void ethernet_udp_init(void) {   struct sockaddr_in any;    udp_ethernet = socket(PF_INET, SOCK_DGRAM, 0); /* Bind the socket to the Browser port */ any.sin_family      = AF_INET; any.sin_port        = MY_PORT; any.sin_addr.s_addr = INADDR_ANY; bind(udp_ethernet, &any, sizeof(any));}

 Try this and then you can read from it like this:

 

 sock_list[0] = udp_ethernet;   sock = RTCS_selectset(sock_list, 1, -1); // Check for activity, do not block (-1)   if (sock == 0) return;   rlen = sizeof(raddr);   memset(&raddr, 0, rlen);   len = recvfrom(sock, data, DATA_LEN, 0, &raddr, &rlen);

 

 

good luck

 

tom