I am trying to broadcast an arp response packet using packet-sockets on
linux. I created an arp response packet and then used sendto to dispatch it
from a socket created using socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ARP))
and bound as follows:
struct sockaddr_ll sa;
memset((char *)&sa, 0, sizeof(sa));
sa.sll_family = AF_PACKET;
sa.sll_protocol = htons(ETH_P_ARP);
sa.sll_ifindex = 2;
sa.sll_hatype = htons(ARPHRD_ETHER);
sa.sll_pkttype = htons(PACKET_BROADCAST);
sa.sll_halen = htons(ETHER_ADDR_LEN);
memcpy(sa.sll_addr, mac, ETHER_ADDR_LEN);
[where mac is my mac address as an array of chars.]
bind(sock, (struct sockaddr *)&sa, sizeof(sa));
However, when I use tcpdump to print the sent packet it prints as follows:
17:25:50.268936 eth0 > arp-#0 for proto #0 (0) hardware #0 (0)
17:25:50.269001 eth0 > arp-#0 for proto #0 (0) hardware #0 (0)
17:25:50.269062 eth0 > arp-#0 for proto #0 (0) hardware #0 (0)
17:25:50.269124 eth0 > arp-#0 for proto #0 (0) hardware #0 (0)
Does anyone know what am I doing wrong? Can anyone point me to a working
example for sending broadcast arp responses.
Any help is deeply appreciated.