aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2019-04-08 12:14:50 +0200
committerLinus Nordberg <linus@nordberg.se>2019-04-08 12:14:50 +0200
commit1b76dc7b38624136838580ea5853189c43b4236d (patch)
treecbc00d2632aaaf983c584ead87fe58beb6cc182b
parentCorrect logic in log_warn, log_info (diff)
downloadwg-dynamic-1b76dc7b38624136838580ea5853189c43b4236d.tar.xz
wg-dynamic-1b76dc7b38624136838580ea5853189c43b4236d.zip
Use a fixed low TCP port
970 is the ASCII sum of the string "wireguard" and is also not registered by by IANA.
-rw-r--r--common.h2
-rw-r--r--wg-dynamic-client.c13
2 files changed, 4 insertions, 11 deletions
diff --git a/common.h b/common.h
index 8d33d25..1cb7f7f 100644
--- a/common.h
+++ b/common.h
@@ -22,7 +22,7 @@
#define MAX_RESPONSE_SIZE 8192
static const char WG_DYNAMIC_ADDR[] = "fe80::";
-static const uint16_t WG_DYNAMIC_PORT = 1337;
+static const uint16_t WG_DYNAMIC_PORT = 970;
#define WG_DYNAMIC_LEASETIME 10 /* NOTE: 10s is good for testing purposes */
diff --git a/wg-dynamic-client.c b/wg-dynamic-client.c
index 2838eaf..cf9d941 100644
--- a/wg-dynamic-client.c
+++ b/wg-dynamic-client.c
@@ -20,7 +20,6 @@
#include "netlink.h"
#define LEASE_CHECK_INTERVAL 1000 /* 1s is convenient for testing */
-#define LOW_PORT_START 214
int DBG_LVL = 3;
@@ -200,6 +199,7 @@ static int do_connect(int *fd)
struct sockaddr_in6 our_addr = {
.sin6_family = AF_INET6,
.sin6_addr = our_lladdr,
+ .sin6_port = htons(WG_DYNAMIC_PORT),
.sin6_scope_id = device->ifindex,
};
struct sockaddr_in6 their_addr = {
@@ -212,15 +212,8 @@ static int do_connect(int *fd)
if (*fd < 0)
fatal("Creating a socket failed");
- for (int port = LOW_PORT_START;; port++) {
- our_addr.sin6_port = htons(port);
- if (!bind(*fd, (struct sockaddr *)&our_addr, sizeof(our_addr)))
- break;
- if (errno != EADDRINUSE)
- fatal("Binding socket failed");
- if (port >= 1024)
- die("No low ports available");
- }
+ if (bind(*fd, (struct sockaddr *)&our_addr, sizeof(our_addr)))
+ fatal("Binding socket failed");
if (!inet_pton(AF_INET6, WG_DYNAMIC_ADDR, &their_addr.sin6_addr))
fatal("inet_pton()");