Browse code

path: received parameter enclosed in square brackets if ipv6

- received should be useless for ipv4, but still can be enforced from
config, so has to be well formatted because it is followed by a port
- reported by Sebastian Damm

Daniel-Constantin Mierla authored on 23/01/2015 11:50:49
Showing 1 changed files
... ...
@@ -67,7 +67,7 @@ static int prepend_path(struct sip_msg* _m, str *user, path_param_t param, str *
67 67
 
68 68
 	/* maximum possible length of suffix */
69 69
 	suffix_len = strlen(";lr;received=sip::12345%3Btransport%3Dsctp;ob;>\r\n")
70
-			+ IP_ADDR_MAX_STR_SIZE + (add_params ? add_params->len : 0) + 1;
70
+			+ IP_ADDR_MAX_STR_SIZE + 2 + (add_params ? add_params->len : 0) + 1;
71 71
 
72 72
 	cp = suffix = pkg_malloc(suffix_len);
73 73
 	if (!suffix) {
... ...
@@ -86,8 +86,13 @@ static int prepend_path(struct sip_msg* _m, str *user, path_param_t param, str *
86 86
 		else
87 87
 			proto_str = NULL;
88 88
 
89
-		cp += sprintf(cp, ";received=sip:%s:%hu%s", ip_addr2a(&_m->rcv.src_ip),
90
-				_m->rcv.src_port, proto_str ? : "");
89
+		if(_m->rcv.src_ip.af==AF_INET6) {
90
+			cp += sprintf(cp, ";received=sip:[%s]:%hu%s", ip_addr2a(&_m->rcv.src_ip),
91
+					_m->rcv.src_port, proto_str ? : "");
92
+		} else {
93
+			cp += sprintf(cp, ";received=sip:%s:%hu%s", ip_addr2a(&_m->rcv.src_ip),
94
+					_m->rcv.src_port, proto_str ? : "");
95
+		}
91 96
 		break;
92 97
 	case PATH_PARAM_OB:
93 98
 		cp += sprintf(cp, ";ob");