From 9e1c90adb9821e97757fbb8206456fbae7374985 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 19 Dec 2011 14:06:45 +0000 Subject: [PATCH] inet_pton is anal, so gotta work around that --- daemon/aux.h | 13 ++++++++++--- daemon/main.c | 9 +++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/daemon/aux.h b/daemon/aux.h index 9be4445d2..8ea0d14ee 100644 --- a/daemon/aux.h +++ b/daemon/aux.h @@ -113,10 +113,17 @@ static inline void smart_ntop(char *o, struct in6_addr *a, size_t len) { inet_ntop(AF_INET6, a, o, len); } -static inline int smart_pton(int af, const char *src, void *dst) { +static inline int smart_pton(int af, char *src, void *dst) { + char *p; + int ret; + if (af == AF_INET6) { - if (src[0] == '[') - return inet_pton(af, src+1, dst); + if (src[0] == '[' && (p = strchr(src, ']'))) { + *p = '\0'; + ret = inet_pton(af, src+1, dst); + *p = ']'; + return ret; + } } return inet_pton(af, src, dst); } diff --git a/daemon/main.c b/daemon/main.c index fa5e5fade..51070ce1e 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -121,16 +121,21 @@ static int parse_ip6_port(struct in6_addr *ip6, u_int16_t *port, char *s) { } if (*s != '[') return -1; - if (inet_pton(AF_INET6, s+1, ip6) != 1) - return -1; p = strstr(s, "]:"); if (!p) return -1; + *p = '\0'; + if (inet_pton(AF_INET6, s+1, ip6) != 1) + goto fail; *port = atoi(p+2); if (!*port) return -1; return 0; + +fail: + *p = ']'; + return -1; }