Module: kamailio
Branch: master
Commit: 9fb15e2ef93a0d606fa4c6d695a2f13a4b0a8031
URL:
https://github.com/kamailio/kamailio/commit/9fb15e2ef93a0d606fa4c6d695a2f13…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2024-10-09T19:51:27+02:00
siptrace: use advertise address if set for trace mode 1 callbacks
---
Modified: src/modules/siptrace/siptrace.c
---
Diff:
https://github.com/kamailio/kamailio/commit/9fb15e2ef93a0d606fa4c6d695a2f13…
Patch:
https://github.com/kamailio/kamailio/commit/9fb15e2ef93a0d606fa4c6d695a2f13…
---
diff --git a/src/modules/siptrace/siptrace.c b/src/modules/siptrace/siptrace.c
index 208718adf0d..31609821682 100644
--- a/src/modules/siptrace/siptrace.c
+++ b/src/modules/siptrace/siptrace.c
@@ -2308,15 +2308,26 @@ int siptrace_net_data_recv(sr_event_param_t *evp)
sto.fromip.s = sto.fromip_buff;
}
- sto.toip.len = snprintf(sto.toip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d",
- siptrace_proto_name(nd->rcv->proto), ip_addr2strz(&nd->rcv->dst_ip),
- (int)nd->rcv->dst_port);
- if(sto.toip.len < 0 || sto.toip.len >= SIPTRACE_ADDR_MAX) {
- LM_ERR("failed to format toip buffer (%d)\n", sto.toip.len);
- sto.toip.s = SIPTRACE_ANYADDR;
- sto.toip.len = SIPTRACE_ANYADDR_LEN;
- } else {
+ if(nd->rcv->bind_address != NULL
+ && nd->rcv->bind_address->useinfo.sock_str.len > 0
+ && (nd->rcv->bind_address->useinfo.sock_str.len
+ < SIPTRACE_ADDR_MAX - 1)) {
+ sto.toip.len = nd->rcv->bind_address->useinfo.sock_str.len;
+ memcpy(sto.toip_buff, nd->rcv->bind_address->useinfo.sock_str.s,
+ sto.toip.len);
+ sto.toip_buff[sto.toip.len] = '\0';
sto.toip.s = sto.toip_buff;
+ } else {
+ sto.toip.len = snprintf(sto.toip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d",
+ siptrace_proto_name(nd->rcv->proto),
+ ip_addr2strz(&nd->rcv->dst_ip), (int)nd->rcv->dst_port);
+ if(sto.toip.len < 0 || sto.toip.len >= SIPTRACE_ADDR_MAX) {
+ LM_ERR("failed to format toip buffer (%d)\n", sto.toip.len);
+ sto.toip.s = SIPTRACE_ANYADDR;
+ sto.toip.len = SIPTRACE_ANYADDR_LEN;
+ } else {
+ sto.toip.s = sto.toip_buff;
+ }
}
sto.dir = "in";
@@ -2408,6 +2419,7 @@ int siptrace_net_data_sent(sr_event_param_t *evp)
int proto;
int evcb_ret;
int ret = 0;
+ str vsock;
if(evp->data == 0)
return -1;
@@ -2437,14 +2449,18 @@ int siptrace_net_data_sent(sr_event_param_t *evp)
sto.fromip.len = SIPTRACE_ANYADDR_LEN;
proto = PROTO_UDP;
} else {
- if(new_dst.send_sock->sock_str.len >= SIPTRACE_ADDR_MAX - 1) {
- LM_ERR("socket string is too large: %d\n",
- new_dst.send_sock->sock_str.len);
+ if(new_dst.send_sock->useinfo.sock_str.len > 0) {
+ vsock = new_dst.send_sock->useinfo.sock_str;
+ } else {
+ vsock = new_dst.send_sock->sock_str;
+ }
+ if(vsock.len >= SIPTRACE_ADDR_MAX - 1) {
+ LM_ERR("socket string is too large: %d\n", vsock.len);
return -1;
}
- strncpy(sto.fromip_buff, new_dst.send_sock->sock_str.s,
- new_dst.send_sock->sock_str.len);
- sto.fromip.len = new_dst.send_sock->sock_str.len;
+ memcpy(sto.fromip_buff, vsock.s, vsock.len);
+ sto.fromip.len = vsock.len;
+ sto.fromip_buff[sto.fromip.len] = '\0';
proto = new_dst.send_sock->proto;
}
sto.fromip.s = sto.fromip_buff;