diff --git a/daemon/aux.h b/daemon/aux.h index 8ea0d14..0c5b67e 100644 --- a/daemon/aux.h +++ b/daemon/aux.h @@ -31,7 +31,7 @@ ntohs(((u_int16_t *) (x))[5]), \ ntohs(((u_int16_t *) (x))[6]), \ ntohs(((u_int16_t *) (x))[7]) -#define D6F IP6F ":%u" +#define D6F "["IP6F"]:%u" #define D6P(x) IP6P((x).sin6_addr.s6_addr), ntohs((x).sin6_port) #define DF IPF ":%u" #define DP(x) IPP((x).sin_addr.s_addr), ntohs((x).sin_port) @@ -107,10 +107,34 @@ static inline void in4_to_6(struct in6_addr *o, u_int32_t ip) { } static inline void smart_ntop(char *o, struct in6_addr *a, size_t len) { + const char *r; + if (IN6_IS_ADDR_V4MAPPED(a)) - inet_ntop(AF_INET, &(a->s6_addr32[3]), o, len); + r = inet_ntop(AF_INET, &(a->s6_addr32[3]), o, len); else - inet_ntop(AF_INET6, a, o, len); + r = inet_ntop(AF_INET6, a, o, len); + + if (!r) + *o = '\0'; +} + +static inline void smart_ntop_p(char *o, struct in6_addr *a, size_t len) { + int l; + + if (IN6_IS_ADDR_V4MAPPED(a)) { + if (!inet_ntop(AF_INET, &(a->s6_addr32[3]), o, len)) + *o = '\0'; + } + else { + *o = '['; + if (!inet_ntop(AF_INET6, a, o+1, len-2)) { + *o = '\0'; + return; + } + l = strlen(o); + o[l] = ']'; + o[l+1] = '\0'; + } } static inline int smart_pton(int af, char *src, void *dst) { diff --git a/daemon/call.c b/daemon/call.c index 0b5bf2b..bc70c63 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -176,7 +176,7 @@ static int stream_packet(struct streamrelay *r, char *b, int l, struct sockaddr_ p = &pe2->rtps[r->idx]; c = cs->call; m = c->callmaster; - smart_ntop(addr, &fsin->sin6_addr, sizeof(addr)); + smart_ntop_p(addr, &fsin->sin6_addr, sizeof(addr)); if (p->fd == -1) { mylog(LOG_WARNING, "[%s] RTP packet to port %u discarded from %s:%u", c->callid, r->localport, addr, ntohs(fsin->sin6_port)); @@ -898,7 +898,7 @@ static int call_streams(struct call *c, GQueue *s, const char *tag, int opmode) cs_o = l->data; for (x = 0; x < 2; x++) { r = &cs_o->peers[x].rtps[0]; - DBG("comparing new "IP6F":%u/%s to old "IP6F":%u/%s", + DBG("comparing new ["IP6F"]:%u/%s to old ["IP6F"]:%u/%s", IP6P(&t->ip46), t->port, tag, IP6P(&r->peer_advertised.ip46), r->peer_advertised.port, cs_o->peers[x].tag); @@ -1419,12 +1419,12 @@ static void call_status_iterator(void *key, void *val, void *ptr) { if (r1->fd == -1 || r2->fd == -1) continue; - smart_ntop(addr1, &r1->peer.ip46, sizeof(addr1)); - smart_ntop(addr2, &r2->peer.ip46, sizeof(addr2)); + smart_ntop_p(addr1, &r1->peer.ip46, sizeof(addr1)); + smart_ntop_p(addr2, &r2->peer.ip46, sizeof(addr2)); if (IN6_IS_ADDR_V4MAPPED(&r1->peer.ip46)) inet_ntop(AF_INET, &m->ipv4, addr3, sizeof(addr3)); else - inet_ntop(AF_INET6, &m->ipv6, addr3, sizeof(addr3)); + smart_ntop_p(addr3, &m->ipv6, sizeof(addr3)); streambuf_printf(s->outbuf, "stream %s:%u %s:%u %s:%u %llu/%llu/%llu %s %s %s %i\n", addr1, r1->peer.port, diff --git a/daemon/control_udp.c b/daemon/control_udp.c index fc040cb..93e4bbd 100644 --- a/daemon/control_udp.c +++ b/daemon/control_udp.c @@ -47,7 +47,7 @@ static void control_udp_incoming(int fd, void *p) { } buf[len] = '\0'; - smart_ntop(addr, &sin.sin6_addr, sizeof(addr)); + smart_ntop_p(addr, &sin.sin6_addr, sizeof(addr)); ret = pcre_exec(u->parse_re, u->parse_ree, buf, len, 0, 0, ovec, G_N_ELEMENTS(ovec)); if (ret <= 0) {