summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-01-28 20:00:47 +0100
committerTom Gundersen <teg@jklm.no>2014-01-30 14:30:39 +0100
commit801bd9e859d7f3f127617172910786929776472b (patch)
tree5c0d67fdf25bb222bcbdc977db96a7fc1e1e21d9 /src/shared
parenteb27aeca247a4cf8816fffc4c0dbcab55ead3864 (diff)
net-util: verify the address family
Error out if the address family is already set to something incompatible with the address being parsed.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/net-util.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/shared/net-util.c b/src/shared/net-util.c
index 8f8cfc9fdb..887dae5125 100644
--- a/src/shared/net-util.c
+++ b/src/shared/net-util.c
@@ -192,16 +192,24 @@ int net_parse_inaddr(const char *address, unsigned char *family, void *dst) {
/* IPv4 */
r = inet_pton(AF_INET, address, dst);
- if (r > 0)
- *family = AF_INET; /* successfully parsed IPv4 address */
- else if (r < 0)
+ if (r > 0) {
+ /* succsefully parsed IPv4 address */
+ if (*family == AF_UNSPEC)
+ *family = AF_INET;
+ else if (*family != AF_INET)
+ return -EINVAL;
+ } else if (r < 0)
return -errno;
else {
/* not an IPv4 address, so let's try IPv6 */
r = inet_pton(AF_INET6, address, dst);
- if (r > 0)
- *family = AF_INET6; /* successfully parsed IPv6 address */
- else if (r < 0)
+ if (r > 0) {
+ /* successfully parsed IPv6 address */
+ if (*family == AF_UNSPEC)
+ *family = AF_INET6;
+ else if (*family != AF_INET6)
+ return -EINVAL;
+ } else if (r < 0)
return -errno;
else
return -EINVAL;