Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to UDP Broadcast with C in Linux?

Tags:

linux

udp

How to UDP Broadcast with C in Linux?

like image 616
Daniel Silveira Avatar asked Dec 03 '08 15:12

Daniel Silveira


1 Answers

In many IP stack, such as Linux, this code does not work. Your socket must have broadcast permissions. Try this:

bcast_sock = socket(AF_INET, SOCK_DGRAM, 0); int broadcastEnable=1; int ret=setsockopt(bcast_sock, SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable));  /* Add other code, sockaddr, sendto() etc. */ 
like image 117
skoylu Avatar answered Oct 02 '22 02:10

skoylu