Browse Source

inet_pton is anal, so gotta work around that

git.mgm/mediaproxy-ng/2.0
Richard Fuchs 14 years ago
parent
commit
9e1c90adb9
2 changed files with 17 additions and 5 deletions
  1. +10
    -3
      daemon/aux.h
  2. +7
    -2
      daemon/main.c

+ 10
- 3
daemon/aux.h View File

@ -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);
}


+ 7
- 2
daemon/main.c View File

@ -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;
}


Loading…
Cancel
Save