Skip to content

Commit

Permalink
Merge pull request SIPp#598 from smititelu/local_ip_hints
Browse files Browse the repository at this point in the history
Add define to use local ip hints
  • Loading branch information
lemenkov authored Jan 11, 2024
2 parents 8da405d + 866b095 commit c9f6f0f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ option(USE_SSL "Build with SIPS support" OFF)
option(USE_SCTP "Build with SCTP support" OFF)
option(USE_PCAP "Build with PCAP playback support" OFF)
option(USE_GSL "Build with improved statistical support" ON)
option(USE_LOCAL_IP_HINTS "Build with local ip hints priority" OFF)

file(GLOB all_SRCS
"${PROJECT_SOURCE_DIR}/src/*.cpp"
Expand Down Expand Up @@ -108,6 +109,10 @@ if(USE_PCAP)
add_definitions("-DPCAPPLAY")
endif(USE_PCAP)

if(USE_LOCAL_IP_HINTS)
add_definitions("-DUSE_LOCAL_IP_HINTS")
endif(USE_LOCAL_IP_HINTS)

if(USE_GSL)
find_library(GSL_LIBRARY gsl)
if(GSL_LIBRARY)
Expand Down
26 changes: 25 additions & 1 deletion src/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2335,10 +2335,34 @@ int open_connections()
/* Resolving the remote IP */
{
fprintf(stderr, "Resolving remote host '%s'... ", remote_host);
struct addrinfo hints;

memset((char*)&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_UNSPEC;

#ifdef USE_LOCAL_IP_HINTS
struct addrinfo * local_addr;
int ret;
if (strlen(local_ip)) {
if ((ret = getaddrinfo(local_ip, NULL, &hints, &local_addr)) != 0) {
ERROR("Can't get local IP address in getaddrinfo, "
"local_ip='%s', ret=%d", local_ip, ret);
}

/* Use local address hints when getting the remote */
if (local_addr->ai_addr->sa_family == AF_INET6) {
local_ip_is_ipv6 = true;
hints.ai_family = AF_INET6;
} else {
hints.ai_family = AF_INET;
}
}
#endif

/* FIXME: add DNS SRV support using liburli? */
if (gai_getsockaddr(&remote_sockaddr, remote_host, remote_port,
AI_PASSIVE, AF_UNSPEC) != 0) {
hints.ai_flags, hints.ai_family) != 0) {
ERROR("Unknown remote host '%s'.\n"
"Use 'sipp -h' for details", remote_host);
}
Expand Down

0 comments on commit c9f6f0f

Please sign in to comment.