Skip to content

Commit

Permalink
nathelper: enclode IPv6 in square branckets for fix_nated_contact()
Browse files Browse the repository at this point in the history
- even there is no nat in ipv6
  • Loading branch information
miconda committed Jan 22, 2015
1 parent a0fee0d commit 814c08f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions modules/nathelper/nathelper.c
Expand Up @@ -803,6 +803,8 @@ fix_nated_contact_f(struct sip_msg* msg, char* str1, char* str2)

cp = ip_addr2a(&msg->rcv.src_ip);
len = c->uri.len + strlen(cp) + 6 /* :port */ - hostport.len + 1;
if(msg->rcv.src_ip.af==AF_INET6)
len += 2;
buf = pkg_malloc(len);
if (buf == NULL) {
LM_ERR("out of pkg memory\n");
Expand All @@ -812,8 +814,13 @@ fix_nated_contact_f(struct sip_msg* msg, char* str1, char* str2)
temp[1] = c->uri.s[c->uri.len];
c->uri.s[c->uri.len] = hostport.s[0] = '\0';
if(uri.maddr.len<=0) {
len1 = snprintf(buf, len, "%s%s:%d%s", c->uri.s, cp, msg->rcv.src_port,
hostport.s + hostport.len);
if(msg->rcv.src_ip.af==AF_INET6) {
len1 = snprintf(buf, len, "%s[%s]:%d%s", c->uri.s, cp,
msg->rcv.src_port, hostport.s + hostport.len);
} else {
len1 = snprintf(buf, len, "%s%s:%d%s", c->uri.s, cp,
msg->rcv.src_port, hostport.s + hostport.len);
}
} else {
/* skip maddr parameter - makes no sense anymore */
LM_DBG("removing maddr parameter from contact uri: [%.*s]\n",
Expand All @@ -827,8 +834,15 @@ fix_nated_contact_f(struct sip_msg* msg, char* str1, char* str2)
params1.len--;
params2.s = uri.maddr.s + uri.maddr.len;
params2.len = c->uri.s + c->uri.len - params2.s;
len1 = snprintf(buf, len, "%s%s:%d%.*s%.*s", c->uri.s, cp, msg->rcv.src_port,
params1.len, params1.s, params2.len, params2.s);
if(msg->rcv.src_ip.af==AF_INET6) {
len1 = snprintf(buf, len, "%s[%s]:%d%.*s%.*s", c->uri.s, cp,
msg->rcv.src_port, params1.len, params1.s,
params2.len, params2.s);
} else {
len1 = snprintf(buf, len, "%s%s:%d%.*s%.*s", c->uri.s, cp,
msg->rcv.src_port, params1.len, params1.s,
params2.len, params2.s);
}
}
if (len1 < len)
len = len1;
Expand Down

0 comments on commit 814c08f

Please sign in to comment.