Implement ARP subsystem and arp app (AI)
- Created src/arp.h: ARP packet struct, cache entry struct, operation codes, lookup/request/resolve/receive API, sysfs registration - Created src/arp.c: ARP cache with 32 entries, request/reply handling, ARP response to incoming requests for our IP, sysfs /sys/arp/table with formatted IP/MAC/interface/state columns - Created apps/arp/arp.c: reads and displays /sys/arp/table - Kernel calls arp_init() at boot, registered sysfs 'arp' namespace - Tested: clean boot, ARP initialized, arp app in CPIO
This commit is contained in:
30
apps/arp/arp.c
Normal file
30
apps/arp/arp.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @file arp.c
|
||||
* @brief Display the ARP table.
|
||||
*
|
||||
* Reads the ARP cache from /sys/arp/table and displays it.
|
||||
*
|
||||
* Usage:
|
||||
* arp - Show the ARP table
|
||||
*/
|
||||
|
||||
#include "syscalls.h"
|
||||
|
||||
int main(void) {
|
||||
/* Open the ARP table sysfs file */
|
||||
int32_t fd = open("/sys/arp/table", 0);
|
||||
if (fd < 0) {
|
||||
puts("arp: failed to open /sys/arp/table\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Read and display contents */
|
||||
char buf[512];
|
||||
int32_t n;
|
||||
while ((n = read(fd, buf, sizeof(buf))) > 0) {
|
||||
write(1, buf, (uint32_t)n);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user