The problem should be pretty obvious if you turned on more warnings:
if(sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP)) < 0)
The above assigns the result of the comparison to sock
, and of course it's not the valid socket.
Instead you need to use parentheses to avoid the operator precedence problem:
if((sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP))) < 0)