Im trying to add some bindings to ARP table in Linux, in C. Im opening a file with “a” (append, right?) and then trying to write some addresses, but I always get segmentation fault. I believe there is something wrong with ARP_table[i].IPaddr, ARP_table[i].MACaddr, ARP_table[i].ARPstatus
struct ARP_entry
{
char IPaddr[16];
char MACaddr[18];
char ARPstatus;
int timec;
};
static struct ARP_entry ARP_table[ARP_table_vel];
void copyZIS()
{
int i=0;
const char filename[] = "/proc/net/arp";
FILE *file = fopen(filename, "a");
for (i; i< i+j; i++)
{
fprintf(file, "%c %c %c", ARP_table[i].IPaddr, ARP_table[i].MACaddr, ARP_table[i].ARPstatus);
}
}
You are not checking the return value of
fopen. I am pretty sure you are not allowed to write to that file.Here is
/proc/net/arpon my system