Skip to content

Instantly share code, notes, and snippets.

@keeler
Last active September 27, 2022 01:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keeler/8345633 to your computer and use it in GitHub Desktop.
Save keeler/8345633 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
const int size = 256;
char ip_address[size];
int hw_type;
int flags;
char mac_address[size];
char mask[size];
char device[size];
FILE* fp = fopen("/proc/net/arp", "r");
if(fp == NULL)
{
perror("Error opening /proc/net/arp");
}
char line[size];
fgets(line, size, fp); // Skip the first line, which consists of column headers.
while(fgets(line, size, fp))
{
sscanf(line, "%s 0x%x 0x%x %s %s %s\n",
ip_address,
&hw_type,
&flags,
mac_address,
mask,
device);
printf("IP = %s, MAC = %s", ip_address, mac_address);
}
fclose(fp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment