### Description
Please check attached pcap. [siptrace.pcap.gz](https://github.com/kamailio/kamailio/files/3688791/siptrace.pcap.gz)
Kamailio send INVITE (packet 1) from port `TCP/42394`. SIP trace encapsulate INVITE (packet 2) and encodes Kamailio source port `TCP/5060`
#### Debugging Data HEP header parsed by lua [disector](https://github.com/sipcapture/hep-wireshark) ``` HEP3 Protocol HEP ID: HEP3 Length (Bytes): 1574 Protocol family: IPv4 Protocol ID: TCP Source IPv4 address: 172.21.0.131 Destination IPv4 address: 192.168.57.11 Source port: 5060 Destination port: 5060 Timestamp: 1570150645 Timestamp us: 740165 Protocol Type: SIP Capture ID: 1 Payload [truncated]: INVITE sip:911@192.168.57.11;transport=tcp SIP/2.0\r\nRecord-Route: sip:172.21.0.131;transport=tcp;lr=on;ftag=KvNj7jXrmK89p\r\nVia: SIP/2.0/TCP 172.21.0.131;branch=z9hG4bK7c2d.2d8104273b7063309f5694ac963c9ad8.0;i=21 ``` [HEP format description located here](https://github.com/sipcapture/HEP/blob/master/docs/HEP3_Network_Protocol_Spe...).
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
``` / # kamailio -v version: kamailio 5.1.6 (x86_64/linux) flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144 MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB poll method support: poll, epoll_lt, epoll_et, sigio_rt, select. id: unknown compiled on 11:01:40 Oct 4 2018 with gcc 6.4.0 ```
* **Operating System**: Docker container Userland ``` / # cat /etc/os-release NAME="Alpine Linux" ID=alpine VERSION_ID=3.8.1 PRETTY_NAME="Alpine Linux v3.8" HOME_URL="http://alpinelinux.org" BUG_REPORT_URL="http://bugs.alpinelinux.org" ``` Kernel Amazon Linux 2 ``` / # uname -a Linux proxy-dc0-0 4.14.128-112.105.amzn2.x86_64 #1 SMP Wed Jun 19 16:53:40 UTC 2019 x86_64 Linux ```
The address is the socket kamailio is listening on, which is typically ip:5060.
With tcp the source port of connect() cannot be easily ensured (only with latest kernels when re-using the port option is enabled).
So this is by design, otherwise there will be different ports for each connection.
If you want to change, that's fine, you can make pull request so other can review, however add a modparam to control this behaviour, with the default option to be like it is now.
Closed #2092.
Thank you Daniel Could you give me reference to code where outbound TCP socket created/bound. I will try debug.
So this is by design, otherwise there will be different ports for each connection.
I do not mind that different ports are used. I am for sending the correct information about the source port
Here is relevant page how to get source port for outbound connection. https://stackoverflow.com/questions/47095534/how-to-get-local-source-port-fr...
How to bind selected port for outbound connection. https://github.com/openssh/openssh-portable/pull/130
Daniel @miconda could you look this links. Think first allow resolve issue. Second link will allow send TCP outbound messages from kamailio `socket` port instead of random port.
Hello Bastian @btriller Could you looks this issue also.
Example how get outbound socket port ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h>
#define SERVER_ADDR "172.217.160.99" #define SERVER_PORT 80
int main() { char myIP[16]; unsigned int myPort; struct sockaddr_in server_addr, my_addr; int sockfd;
// Connect to server if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("Can't open stream socket."); exit(-1); }
// Set server_addr bzero(&server_addr, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = inet_addr(SERVER_ADDR); server_addr.sin_port = htons(SERVER_PORT);
// Connect to server if (connect(sockfd, (struct sockaddr *) &server_addr, sizeof(server_addr)) < 0) { perror("Connect server error"); close(sockfd); exit(-1); }
// Get my ip address and port bzero(&my_addr, sizeof(my_addr)); socklen_t len = sizeof(my_addr); getsockname(sockfd, (struct sockaddr *) &my_addr, &len); inet_ntop(AF_INET, &my_addr.sin_addr, myIP, sizeof(myIP)); myPort = ntohs(my_addr.sin_port);
printf("Local ip address: %s\n", myIP); printf("Local port : %u\n", myPort);
return 0; } ```
Found at https://gist.github.com/listnukira/4045436