you need to use UDP to send a broadcast message over the network. when creating a socket using the socket() function, specify AF_INET for the family parameter and SOCK_DGRAM for the type parameter. on some systems, you need to enable broadcast packet sending by setting the SO_BROADCAST socket option to 1 using setsockopt() .
then use the sendto() function call to send the datagram and use 255.255.255.255 as the destination address. (for datagram sockets, you do not need to call connect() , since there is no βconnectionβ).
in standard implementations, this address is transmitted to the entire computer on the local network, which means that the packet will not cross the gateway and will not be accepted by computers using a network mask that is different from the network mask of the sending computer.
source share