chiark / gitweb /
core: introduce parse_ip_port (#4825)
authorSusant Sahani <ssahani@users.noreply.github.com>
Tue, 6 Dec 2016 11:21:45 +0000 (16:51 +0530)
committerSven Eden <yamakuzure@gmx.net>
Mon, 17 Jul 2017 15:58:35 +0000 (17:58 +0200)
1. Listed in TODO.
2. Tree wide replace safe_atou16 with parse_ip_port incase
   it's used for ports.

src/basic/parse-util.c
src/basic/parse-util.h

index b1cad55e7c1915090ff5f980f3d2ebe8677bdee6..2daa797a5025dc888f8f764d589944e905498f12 100644 (file)
@@ -582,3 +582,19 @@ int parse_nice(const char *p, int *ret) {
         return 0;
 }
 #endif // 0
         return 0;
 }
 #endif // 0
+
+int parse_ip_port(const char *s, uint16_t *ret) {
+        uint16_t l;
+        int r;
+
+        r = safe_atou16(s, &l);
+        if (r < 0)
+                return r;
+
+        if (l == 0)
+                return -EINVAL;
+
+        *ret = (uint16_t) l;
+
+        return 0;
+}
index 23b1937430a60d91293550a51ffeac1d2e127e6f..2f6cfdbc5f9aba222cb643df42747366da234284 100644 (file)
@@ -114,3 +114,5 @@ int parse_percent(const char *p);
 #if 0 /// UNNEEDED by elogind
 int parse_nice(const char *p, int *ret);
 #endif // 0
 #if 0 /// UNNEEDED by elogind
 int parse_nice(const char *p, int *ret);
 #endif // 0
+
+int parse_ip_port(const char *s, uint16_t *ret);