diff options
author | Susant Sahani <ssahani@users.noreply.github.com> | 2016-12-06 16:51:45 +0530 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-12-06 12:21:45 +0100 |
commit | 10452f7c93c3a492c1f8fdc4a49b65ddc40b27a2 (patch) | |
tree | 4f9bff7fdf68acc0a0c7cc9c9b884f433cc945e2 /src/basic | |
parent | 5efdbf11d1ef7da72d3de58abecd84edefbaf98a (diff) | |
download | systemd-10452f7c93c3a492c1f8fdc4a49b65ddc40b27a2.tar.gz systemd-10452f7c93c3a492c1f8fdc4a49b65ddc40b27a2.tar.bz2 systemd-10452f7c93c3a492c1f8fdc4a49b65ddc40b27a2.zip |
core: introduce parse_ip_port (#4825)
1. Listed in TODO.
2. Tree wide replace safe_atou16 with parse_ip_port incase
it's used for ports.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/parse-util.c | 16 | ||||
-rw-r--r-- | src/basic/parse-util.h | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index c98815b9bc..6e58ced6f5 100644 --- a/src/basic/parse-util.c +++ b/src/basic/parse-util.c @@ -574,3 +574,19 @@ int parse_nice(const char *p, int *ret) { *ret = n; return 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; +} diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h index 461e1cd4d8..4d132f0de5 100644 --- a/src/basic/parse-util.h +++ b/src/basic/parse-util.h @@ -110,3 +110,5 @@ int parse_percent_unbounded(const char *p); int parse_percent(const char *p); int parse_nice(const char *p, int *ret); + +int parse_ip_port(const char *s, uint16_t *ret); |