Skip to content

Commit

Permalink
allow setting the port to listen on via cmdline argument
Browse files Browse the repository at this point in the history
  • Loading branch information
glimberg committed May 9, 2024
1 parent aed3afd commit 219133a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tcp-proxy/tcp-proxy.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 219133a

Please sign in to comment.