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
This commit is contained in:
28
apps/dhcp/dhcp.c
Normal file
28
apps/dhcp/dhcp.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
Reference in New Issue
Block a user