From db5b3d9f9c5f77c873b86855ec3794b8f26964f4 Mon Sep 17 00:00:00 2001 From: Stefan Mititelu Date: Wed, 16 Mar 2022 16:48:11 +0200 Subject: [PATCH] Add dontreuseaddr parameter --- include/sipp.hpp | 1 + src/sipp.cpp | 1 + src/socket.cpp | 8 +++++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/sipp.hpp b/include/sipp.hpp index 9a533cb6..aa739a71 100644 --- a/include/sipp.hpp +++ b/include/sipp.hpp @@ -424,6 +424,7 @@ MAYBE_EXTERN int reset_number DEFVAL(0); MAYBE_EXTERN bool reset_close DEFVAL(true); MAYBE_EXTERN int reset_sleep DEFVAL(1000); MAYBE_EXTERN bool sendbuffer_warn DEFVAL(false); +MAYBE_EXTERN bool dontreuseaddr DEFVAL(false); /* A list of sockets pending reset. */ MAYBE_EXTERN set sockets_pending_reset; diff --git a/src/sipp.cpp b/src/sipp.cpp index 0f865026..4b50e42c 100644 --- a/src/sipp.cpp +++ b/src/sipp.cpp @@ -164,6 +164,7 @@ struct sipp_option options_table[] = { "- cn: un + compression (only if compression plugin loaded). This plugin is not provided with SIPp.\n" , SIPP_OPTION_TRANSPORT, NULL, 1 }, + {"dontreuseaddr", "Do not reuse TCP ports. Might be important in multi-socket mode (see -t parameter) in order to allow higher amount of calls.", SIPP_OPTION_SETFLAG, &dontreuseaddr, 1}, {"i", "Set the local IP address for 'Contact:','Via:', and 'From:' headers. Default is primary host IP address.\n", SIPP_OPTION_IP, local_ip, 1}, {"p", "Set the local port number. Default is a random free port chosen by the system.", SIPP_OPTION_INT, &user_port, 1}, {"bind_local", "Bind socket to local IP address, i.e. the local IP address is used as the source IP address. If SIPp runs in server mode it will only listen on the local IP address instead of all IP addresses.", SIPP_OPTION_SETFLAG, &bind_local, 1}, diff --git a/src/socket.cpp b/src/socket.cpp index b8f655eb..85aa192b 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -1733,9 +1733,11 @@ void sipp_customize_socket(SIPpSocket *socket) socket->ss_transport == T_SCTP) { int sock_opt = 1; - if (setsockopt(socket->ss_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&sock_opt, - sizeof (sock_opt)) == -1) { - ERROR_NO("setsockopt(SO_REUSEADDR) failed"); + if (dontreuseaddr == false) { + if (setsockopt(socket->ss_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&sock_opt, + sizeof (sock_opt)) == -1) { + ERROR_NO("setsockopt(SO_REUSEADDR) failed"); + } } #ifdef USE_SCTP