Browse Source

core: use advertise port only when set for via header

(cherry picked from commit abaf42a735b00af8cbfec90888d2ef3397e5040d)
Daniel-Constantin Mierla 1 năm trước cách đây
mục cha
commit
24651787d5
1 tập tin đã thay đổi với 12 bổ sung8 xóa
  1. 12 8
      src/core/msg_translator.c

+ 12 - 8
src/core/msg_translator.c

@@ -2922,12 +2922,17 @@ char *via_builder(unsigned int *len, sip_msg_t *msg,
 		}
 	}
 	if(port_str == NULL) {
-		if(hp && hp->port->len)
+		if(hp && hp->port->len) {
 			port_str = hp->port;
-		else if(send_sock->useinfo.port_no > 0)
-			port_str = &(send_sock->useinfo.port_no_str);
-		else
-			port_str = &(send_sock->port_no_str);
+		} else if(send_sock->useinfo.name.len > 0) {
+			if(send_sock->useinfo.port_no > 0) {
+				port_str = &(send_sock->useinfo.port_no_str);
+			}
+		} else {
+			if(send_sock->port_no != SIP_PORT) {
+				port_str = &(send_sock->port_no_str);
+			}
+		}
 	}
 	proto = PROTO_NONE;
 	if(msg && (msg->msg_flags & FL_USE_XAVP_VIA_FIELDS)
@@ -2971,7 +2976,7 @@ char *via_builder(unsigned int *len, sip_msg_t *msg,
 	via_prefix_len = MY_VIA_LEN + (proto == PROTO_SCTP);
 	max_len = via_prefix_len + address_str->len /* space in MY_VIA */
 			  + 2 /* just in case it is a v6 address ... [ ] */
-			  + 1 /*':'*/ + port_str->len
+			  + 1 /*':'*/ + (port_str ? port_str->len : 0)
 			  + (branch ? (MY_BRANCH_LEN + branch->len) : 0)
 			  + (extra_params ? extra_params->len : 0) + comp_len
 			  + comp_name_len + CRLF_LEN + 1;
@@ -3056,8 +3061,7 @@ char *via_builder(unsigned int *len, sip_msg_t *msg,
 	}
 	memcpy(line_buf + via_prefix_len + extra_len, address_str->s,
 			address_str->len);
-	if((send_sock->port_no != SIP_PORT)
-			|| (port_str != &send_sock->port_no_str)) {
+	if(port_str != NULL && port_str->len > 0) {
 		line_buf[via_len] = ':';
 		via_len++;
 		memcpy(line_buf + via_len, port_str->s, port_str->len);