socketsnetwork-programmingbroadcastunicast

How to send an IP packet to directly connected Peer through broadcast?


let's two machines are directly connected on a Point-to-point link:

A -192.168.4.1/24---------------------------192.168.4.2/24--B

How A can send an IP packet to B through broadcast only ?

if A cooks up the packet with Dest mac = ff:ff:ff:ff:ff:ff and dest ip : 192.168.4.255, Would this make the packet destined to B ? If yes, Can somebody explains how this works ?


Solution

  • I figured out - we can send the packet with dest IP = 192.168.4.255. In addition, set the broadcast privileges on socket using

    int on=1;
    setsockopt(igmp_sockfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));
    

    It will work.