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:
AI
2026-02-24 07:31:45 +00:00
parent 1825448528
commit d7d7e8e58e
7 changed files with 571 additions and 7 deletions

30
apps/arp/arp.c Normal file
View 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;
}