[ale] Accessing /proc from C
cfowler
cfowler at outpostsentinel.com
Sun Dec 29 09:40:09 EST 2002
On Sat, 2002-12-28 at 23:37, Benjamin Dixon wrote:
>
> This is nice. I looked around, and seeing how the proc system is accessed,
> as you indicate, its only really useful if you feel like messing with
> ASCII. I was just looking for data from the arp cache and ended up just
> doing some socket manipulation and ioctl to get the info I needed.
> Probably more portable anyway.
>
> Thanks,#define ARPFILE "/proc/net/arp"
int
arp(int argc, char *argv[])
{
FILE *fp;
char buffer[1024];
char ip[32], hw[32], mask[32], device[12];
unsigned long hwtype;
unsigned long flags;
if((fp = fopen(ARPFILE, "r")) == NULL)
err_quit("can not get stats");
printf("\nIP address HWtype Flags HW
address Mask Device\n");
fgets(buffer, sizeof(buffer), fp); // Trash
while(fgets(buffer, sizeof(buffer), fp) != NULL)
{
sscanf(buffer, "%s %X %X %s %s %s", &ip, &hwtype,
&flags,
&hw, &mask, &device);
printf("%-16s %-2X %-2X %-16s %-8s
%-12s\n", ip, hwtype, flags, hw, mask, device);
}
printf("\n");
return 0;
}
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list