From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Fri, 27 Jan 2023 18:30:50 +0000 (+0000) Subject: Add modifications suggested by https://github.com/mikebrady/nqptp/issues/14 to restri... X-Git-Tag: 1.2~1^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=090ca128844b4ac1f4fa3cdf8ae4ca77d4d0b8d8;p=thirdparty%2Fnqptp.git Add modifications suggested by https://github.com/mikebrady/nqptp/issues/14 to restrict UDP write access to 9000 to the localhost. --- diff --git a/nqptp-utilities.c b/nqptp-utilities.c index a28c9ce..8940868 100644 --- a/nqptp-utilities.c +++ b/nqptp-utilities.c @@ -43,7 +43,7 @@ #include "debug.h" -void open_sockets_at_port(uint16_t port, sockets_open_bundle *sockets_open_stuff) { +void open_sockets_at_port(const char *node, uint16_t port, sockets_open_bundle *sockets_open_stuff) { // open up sockets for UDP ports 319 and 320 struct addrinfo hints, *info, *p; @@ -57,7 +57,7 @@ void open_sockets_at_port(uint16_t port, sockets_open_bundle *sockets_open_stuff char portstr[20]; snprintf(portstr, 20, "%d", port); - ret = getaddrinfo(NULL, portstr, &hints, &info); + ret = getaddrinfo(node, portstr, &hints, &info); if (ret) { die("getifaddrs: %s", gai_strerror(ret)); } diff --git a/nqptp-utilities.h b/nqptp-utilities.h index 82adad6..a0643a8 100644 --- a/nqptp-utilities.h +++ b/nqptp-utilities.h @@ -38,7 +38,7 @@ typedef struct { socket_info sockets[MAX_OPEN_SOCKETS]; } sockets_open_bundle; -void open_sockets_at_port(uint16_t port, sockets_open_bundle *sockets_open_stuff); +void open_sockets_at_port(const char *node, uint16_t port, sockets_open_bundle *sockets_open_stuff); void debug_print_buffer(int level, char *buf, size_t buf_len); uint64_t get_self_clock_id(); // a clock ID based on a MAC address #endif \ No newline at end of file diff --git a/nqptp.c b/nqptp.c index aab6203..2c2ba38 100644 --- a/nqptp.c +++ b/nqptp.c @@ -253,9 +253,9 @@ int main(int argc, char **argv) { // open sockets 319 and 320 - open_sockets_at_port(319, &sockets_open_stuff); - open_sockets_at_port(320, &sockets_open_stuff); - open_sockets_at_port(NQPTP_CONTROL_PORT, + open_sockets_at_port(NULL, 319, &sockets_open_stuff); + open_sockets_at_port(NULL, 320, &sockets_open_stuff); + open_sockets_at_port("localhost", NQPTP_CONTROL_PORT, &sockets_open_stuff); // this for messages from the client // start the timed tasks