From 219133a2c8a22422d294562d73495e5b0accebc5 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Thu, 9 May 2024 12:21:51 -0700 Subject: [PATCH] allow setting the port to listen on via cmdline argument --- tcp-proxy/tcp-proxy.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tcp-proxy/tcp-proxy.cpp b/tcp-proxy/tcp-proxy.cpp index f770a42fe..f8bc64640 100644 --- a/tcp-proxy/tcp-proxy.cpp +++ b/tcp-proxy/tcp-proxy.cpp @@ -321,11 +321,21 @@ int main(int argc,char **argv) svc.phy = &phy; svc.udpPortCounter = 1023; + uint16_t listenPort = ZT_TCP_PROXY_TCP_PORT; + if (argc > 1) { + listenPort = (uint16_t)atoi(argv[1]); + } + + if (listenPort == 0) { + fprintf(stderr,"%s: fatal error: invalid port number\n",argv[0]); + return 1; + } + { struct sockaddr_in laddr; memset(&laddr,0,sizeof(laddr)); laddr.sin_family = AF_INET; - laddr.sin_port = htons(ZT_TCP_PROXY_TCP_PORT); + laddr.sin_port = htons(listenPort); if (!phy.tcpListen((const struct sockaddr *)&laddr)) { fprintf(stderr,"%s: fatal error: unable to bind TCP port %d\n",argv[0],ZT_TCP_PROXY_TCP_PORT); return 1;