Module: kamailio Branch: master Commit: abaf42a735b00af8cbfec90888d2ef3397e5040d URL: https://github.com/kamailio/kamailio/commit/abaf42a735b00af8cbfec90888d2ef33...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2024-09-18T09:52:32+02:00
core: use advertise port only when set for via header
---
Modified: src/core/msg_translator.c
---
Diff: https://github.com/kamailio/kamailio/commit/abaf42a735b00af8cbfec90888d2ef33... Patch: https://github.com/kamailio/kamailio/commit/abaf42a735b00af8cbfec90888d2ef33...
---
diff --git a/src/core/msg_translator.c b/src/core/msg_translator.c index 4f88150e11b..f74e4ce3258 100644 --- a/src/core/msg_translator.c +++ b/src/core/msg_translator.c @@ -2940,12 +2940,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) @@ -2989,7 +2994,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; @@ -3074,8 +3079,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);