diff options
author | dzwdz | 2022-08-22 18:14:31 +0200 |
---|---|---|
committer | dzwdz | 2022-08-22 18:14:31 +0200 |
commit | fcdadf5df39e1d72f9ac79fa384fc6b98be0b1aa (patch) | |
tree | 988b1c47a3f4e0689df4644bd7b16095d01877a5 /src/user/app/netstack/fs.c | |
parent | 55900142023f7a27d467c7ce6a61d2e5ecead4e3 (diff) |
user/netstack: ip_parse
Diffstat (limited to 'src/user/app/netstack/fs.c')
-rw-r--r-- | src/user/app/netstack/fs.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/user/app/netstack/fs.c b/src/user/app/netstack/fs.c index 4d1e38c..19e5bfd 100644 --- a/src/user/app/netstack/fs.c +++ b/src/user/app/netstack/fs.c @@ -96,15 +96,21 @@ static void fs_open(handle_t reqh, char *path) { } char *save; - const char *srcip_s, *dstip_s, *verb, *proto, *port_s; + const char *verb, *proto, *port_s; - srcip_s = strtok_r(path, "/", &save); - if (strcmp(srcip_s, "0.0.0.0") != 0) + uint32_t srcip, dstip; + if (ip_parse(strtok_r(path, "/", &save), &srcip) < 0) respond(NULL, -1); + if (srcip != 0) { + eprintf("unimplemented"); + respond(NULL, -1); + } verb = strtok_r(NULL, "/", &save); + if (!verb) respond(NULL, -1); if (strcmp(verb, "listen") == 0) { proto = strtok_r(NULL, "/", &save); + if (!proto) respond(NULL, -1); if (strcmp(proto, "udp") == 0) { port_s = strtok_r(NULL, "/", &save); if (port_s) { @@ -119,11 +125,10 @@ static void fs_open(handle_t reqh, char *path) { } } } else if (strcmp(verb, "connect") == 0) { - dstip_s = strtok_r(NULL, "/", &save); - // TODO proper ip parsing - // 0xc0a80001 == 192.168.0.1 - uint32_t dstip = strtol(dstip_s, NULL, 0); + if (ip_parse(strtok_r(NULL, "/", &save), &dstip) < 0) + respond(NULL, -1); proto = strtok_r(NULL, "/", &save); + if (!proto) respond(NULL, -1); if (strcmp(proto, "udp") == 0) { port_s = strtok_r(NULL, "/", &save); if (port_s) { |