This post is in continuation of our previous post “ Understanding ARP (Address Resolution Protocol) basics “ To visualise what ARP reply we are getting from arping command, we need to write an ARP reply receiver code as below, $ vim receive_arp_reply.c /* Copyright (C) 2011-2015 P.D. Buchan (pdbuchan@yahoo.com) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Command line execution

Terminalbash
gcc -o receive_arp_reply receive_arp_reply.c  $ sudo ./receive_arp_reply Ethernet frame header: Destination MAC (this node): ff:ff:ff:ff:ff:ff Source MAC: 0d:61:77:62:cf:50 Ethernet type code (2054 = ARP): 2054 Ethernet data (ARP header): Hardware type (1 = ethernet (10 Mb)): 1 Protocol type (2048 for IPv4 addresses): 2048 Hardware (MAC) address length (bytes): 6 Protocol (IPv4) address length (bytes): 4 Opcode (2 = ARP reply): 2 Sender hardware (MAC) address: 0d:61:77:62:cf:50 Sender protocol (IPv4) address: 192.168.0.106 Target (this node) hardware (MAC) ad

Risk level: destructive. Review the command before running it.

Implementation details

See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ // Receive an ARP reply and extract the MAC address // of the sender of the ARP reply, as well as any other // information stored in the ethernet frame. #include <stdio.h> #include <stdlib.h> #include <unistd.h> // close() #include <string.h> // strcpy, memset() #include <netinet/ip.h> // IP_MAXPACKET (65535) #include <sys/types.h> // needed for socket(), uint8_t, uint16_t #include <sys/socket.h> // needed for socket() #include <linux/if_ether.h> // ETH_P_ARP = 0x0806, ETH_P_ALL = 0x0003 #include <net/ethernet.h> #include <errno.h> // errno, perror() // Define an struct for ARP header typedef struct _arp_hdr arp_hdr; struct _arp_hdr { uint16_t htype; uint16_t ptype; uint8_t hlen; uint8_t plen; uint16_t opcode; uint8_t sender_mac[6]; uint8_t sender_ip[4]; uint8_t target_mac[6]; uint8_t target_ip[4]; }; // Define some constants.

Gotchas and common issues

  • Permission checks - verify user access rights and sudo privileges before executing system-level operations.

  • Environment configuration - double-check path variables and dependency versions to prevent runtime failures.

  • Backup safeguards - maintain configuration backups before applying system or database modifications.

Following these steps ensures clean configuration and reliable execution for sending arp request and receiving arp reply using c code.