summaryrefslogtreecommitdiff
path: root/src/user/app/netstack/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/app/netstack/util.c')
-rw-r--r--src/user/app/netstack/util.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/user/app/netstack/util.c b/src/user/app/netstack/util.c
index 9981aa3..e9d3118 100644
--- a/src/user/app/netstack/util.c
+++ b/src/user/app/netstack/util.c
@@ -29,3 +29,20 @@ uint16_t ip_checksum(const uint8_t *buf, size_t len) {
c = (c & 0xFFFF) + (c >> 16);
return ~c;
}
+
+int ip_parse(const char *s, uint32_t *dest) {
+ if (!s) return -1;
+
+ uint32_t ip = strtol(s, (char**)&s, 0);
+ int parts = 1;
+ for (; parts < 4; parts++) {
+ if (!*s) break;
+ if (*s++ != '.') return -1;
+ ip <<= 8;
+ ip += strtol(s, (char**)&s, 0);
+ }
+ if (parts > 1)
+ ip = ((ip & 0xFFFFFF00) << 8 * (4 - parts)) | (ip & 0xFF);
+ *dest = ip;
+ return 0;
+}