Files
claude-os/apps/dhcp/dhcp.c
AI d7ce0d5856 Implement DHCP client subsystem and dhcp app (AI)
- Created src/dhcp.h: DHCP packet struct, lease info struct, message types,
  options codes, client states, discover/receive/get_lease API
- Created src/dhcp.c: DHCP client with DISCOVER/OFFER/REQUEST/ACK flow,
  manual IP+UDP header construction for broadcast, option parsing for
  subnet mask/router/DNS/lease time/server ID, lease table, auto-applies
  configuration to ethernet interface on ACK, sysfs /sys/dhcp/status
- Created apps/dhcp/dhcp.c: reads /sys/dhcp/status to display DHCP info
- Kernel calls dhcp_init() at boot
- Tested: clean boot, DHCP initialized, dhcp app in CPIO
2026-02-24 07:35:20 +00:00

29 lines
543 B
C

/**
* @file dhcp.c
* @brief Display DHCP status information.
*
* Reads DHCP lease information from /sys/dhcp/status and displays it.
*
* Usage:
* dhcp - Show current DHCP status
*/
#include "syscalls.h"
int main(void) {
int32_t fd = open("/sys/dhcp/status", 0);
if (fd < 0) {
puts("dhcp: failed to open /sys/dhcp/status\n");
return 1;
}
char buf[512];
int32_t n;
while ((n = read(fd, buf, sizeof(buf))) > 0) {
write(1, buf, (uint32_t)n);
}
close(fd);
return 0;
}