diff options
author | Marvin Borner | 2021-03-26 21:55:50 +0100 |
---|---|---|
committer | Marvin Borner | 2021-03-26 22:02:20 +0100 |
commit | 05498860e8f7b1e8bb27880bc7526de026694804 (patch) | |
tree | 3bddf16e9439a950a3810d45e42a5cefdbcb7663 /libnet/ip.c | |
parent | a96e9c4c858d47f61b89d879aa0ce6a02bdacb38 (diff) |
Renamed libs
Cleaner and more flexible.
Diffstat (limited to 'libnet/ip.c')
-rw-r--r-- | libnet/ip.c | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/libnet/ip.c b/libnet/ip.c deleted file mode 100644 index eb2e202..0000000 --- a/libnet/ip.c +++ /dev/null @@ -1,49 +0,0 @@ -// MIT License, Copyright (c) 2020 Marvin Borner -// Most net/ip handlers are in the kernel space -// This is a userspace wrapper for some things - -#include <def.h> -#include <mem.h> -#include <net.h> -#include <str.h> - -// Inspired by Paul Vixie, 1996 -int ip_pton(const char *src, u32 *dst) -{ - const char *end = src + strlen(src); - u8 tmp[4], *tp; - int ch = 0; - int saw_digit = 0; - int octets = 0; - *(tp = tmp) = 0; - - while (src < end) { - ch = *src++; - if (ch >= '0' && ch <= '9') { - u32 new = *tp * 10 + (ch - '0'); - - if ((saw_digit && *tp == 0) || new > 255) - return 0; - - *tp = new; - if (!saw_digit) { - if (++octets > 4) - return 0; - saw_digit = 1; - } - } else if (ch == '.' && saw_digit) { - if (octets == 4) - return 0; - *++tp = 0; - saw_digit = 0; - } else { - return 0; - } - } - - if (octets < 4) - return 0; - - *dst = htonl(*(u32 *)tmp); - return 1; -} |