From 7f8e0b2cd5ad86e055434d0d7ab0f30550e1fc12 Mon Sep 17 00:00:00 2001 From: Behrad Mahmoudi Date: Tue, 17 Feb 2026 20:25:51 +0100 Subject: [PATCH] Now, the listening telnet socket is only bound to the dedicated interface IPs in config file, both for V4 and V6 --- common/utils/telnetsrv/telnetsrv.c | 50 +++++++++++++++++++++--------- common/utils/telnetsrv/telnetsrv.h | 2 +- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/common/utils/telnetsrv/telnetsrv.c b/common/utils/telnetsrv/telnetsrv.c index 03b67506bc..407a6b73b9 100644 --- a/common/utils/telnetsrv/telnetsrv.c +++ b/common/utils/telnetsrv/telnetsrv.c @@ -57,6 +57,10 @@ #include "common/utils/threadPool/notified_fifo.h" #include #include "common/oai_version.h" +#include +#include +#include +#include #include "telnetsrv_phycmd.h" @@ -79,7 +83,7 @@ paramdef_t telnetoptions[] = { /* configuration parameters for telnet utility */ /* optname helpstr paramflags XXXptr defXXXval type numelt */ /*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - {"listenaddr", "\n", 0, .uptr = &telnetparams.listenaddr, .defstrval = "0.0.0.0", TYPE_IPV4ADDR, 0}, + {"listenaddr", "\n", 0, .strptr = &telnetparams.listenaddr, .defstrval = "0.0.0.0", TYPE_STRING, 0}, {"listenport", "\n", 0, .uptr = &telnetparams.listenport, .defuintval = 9090, TYPE_UINT, 0}, {"listenstdin", "enable input from stdin\n", PARAMFLAG_BOOL, .uptr = &telnetparams.listenstdin, .defuintval = 0, TYPE_UINT, 0}, {"priority", " ai_next){ - if(bind(sock, (void *) &name, sizeof(name))) - fprintf(stderr,"[TELNETSRV] Error %s on bind call\n",strerror(errno)); + sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol); + if (sock < 0) continue; + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval); + if (bind(sock, p->ai_addr, p->ai_addrlen) == 0) + break; + close(sock); + sock = -1; + } + + freeaddrinfo(res); + + if (sock < 0) { + fprintf(stderr, "Failed to bind socket\n"); + exit(-1); + } if(listen(sock, 1) == -1) fprintf(stderr,"[TELNETSRV] Error %s on listen call\n",strerror(errno)); diff --git a/common/utils/telnetsrv/telnetsrv.h b/common/utils/telnetsrv/telnetsrv.h index ab866c88fb..b841905cae 100644 --- a/common/utils/telnetsrv/telnetsrv.h +++ b/common/utils/telnetsrv/telnetsrv.h @@ -162,7 +162,7 @@ typedef struct { cmdparser_t CmdParsers[TELNET_MAXCMD]; // array of registered modules. char msgbuff[TELNET_MAX_MSGLENGTH]; // internal buffer of the client_printf function which is used to print to the client terminal */ unsigned int listenport; // ip port the telnet server is listening on - unsigned int listenaddr; // ip address the telnet server is listening on + char *listenaddr; // ip address the telnet server is listening on unsigned int listenstdin; // enable command input from stdin unsigned int loopcount; // loop command param: number of loop iteration unsigned int loopdelay; // loop command param: delay in ms between 2 iterations