diff options
author | dzwdz | 2024-05-05 15:20:33 +0200 |
---|---|---|
committer | dzwdz | 2024-05-05 15:20:33 +0200 |
commit | 1e9887d904280c43c5a92570a07627689c89b48f (patch) | |
tree | 92a93a7e4bfd9da3ff7e9b09f83579f360340ce9 /src/cmd/netstack | |
parent | d7e389ae21685dda6ef6619cbd3c64ad2db149b4 (diff) |
net: expose the rtl mac to userland, make the netstack use it
Diffstat (limited to 'src/cmd/netstack')
-rw-r--r-- | src/cmd/netstack/netstack.c | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/src/cmd/netstack/netstack.c b/src/cmd/netstack/netstack.c index a8e011e..3876df9 100644 --- a/src/cmd/netstack/netstack.c +++ b/src/cmd/netstack/netstack.c @@ -10,10 +10,7 @@ #include <string.h> #include <thread.h> -struct net_state state = { - // TODO dynamically get mac - .mac = {0x52, 0x54, 0x00, 0xCA, 0x77, 0x1A}, -}; +struct net_state state = {0}; void network_thread(void *arg) { (void)arg; const size_t buflen = 4096; @@ -29,24 +26,51 @@ void network_thread(void *arg) { (void)arg; void fs_thread(void *arg); int main(int argc, char **argv) { + char *path; if (argc < 4) { fprintf(stderr, "usage: netstack iface ip gateway\n"); return 1; } - state.raw_h = camellia_open(argv[1], OPEN_RW); + + if (asprintf(&path, "%s/net", argv[1]) < 0) { + errx(1, "asprintf failed for some reason"); + } + state.raw_h = camellia_open(path, OPEN_RW); if (state.raw_h < 0) { - err(1, "open %s", argv[1]); + err(1, "open %s", path); + return 1; + } + free(path); + + if (asprintf(&path, "%s/mac", argv[1]) < 0) { + errx(1, "asprintf failed for some reason"); + } + hid_t h = camellia_open(path, OPEN_READ); + if (h < 0) { + err(1, "open %s", path); return 1; } + if (_sys_read(h, state.mac, 6, 0) != 6) { + errx(1, "can't read mac", path); + return 1; + } + _sys_close(h); + free(path); + if (ip_parse(argv[2], &state.ip) < 0) { errx(1, "invalid ip: %s", argv[2]); - return -1; + return 1; } if (ip_parse(argv[3], &state.gateway) < 0) { - errx(1, "invalid gateway: %s", argv[2]); - return -1; + errx(1, "invalid gateway: %s", argv[3]); + return 1; } - setproctitle(argv[2]); + + setproctitle( + "ip=%s gw=%s mac=%02x:%02x:%02x:%02x:%02x:%02x", argv[2], argv[3], + state.mac[0], state.mac[1], state.mac[2], state.mac[3], state.mac[4], + state.mac[5] + ); arp_request(state.gateway); thread_create(0, network_thread, NULL); thread_create(0, fs_thread, NULL); |