]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
get IPvX family when creating each clock record.
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 31 Oct 2021 09:58:17 +0000 (09:58 +0000)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 31 Oct 2021 09:58:17 +0000 (09:58 +0000)
nqptp-clock-sources.c

index 4354c15dd80172cd553893a97c6787dd53b02ad1..9128c67ca7f9fd35a03e355cd7e7811cc1579b0f 100644 (file)
 #include <ifaddrs.h>
 #include <string.h>
 #include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
 
 #ifdef CONFIG_FOR_FREEBSD
 #include <netinet/in.h>
-#include <sys/socket.h>
 #endif
 
 #ifndef FIELD_SIZEOF
@@ -72,14 +73,12 @@ int create_clock_source_record(char *sender_string,
 
   if (found == 1) {
     int family = 0;
-    int ret;
-  // check its ipv4/6 family
+
+  // check its ipv4/6 family -- derived froom https://stackoverflow.com/a/3736377, with thanks.
     struct addrinfo hint, *res = NULL;
     memset(&hint, '\0', sizeof hint);
     hint.ai_family = PF_UNSPEC;
     hint.ai_flags = AI_NUMERICHOST;
-
-    ret = getaddrinfo(sender_string, NULL, &hint, &res);
     if (getaddrinfo(sender_string, NULL, &hint, &res) == 0) {
       family = res->ai_family;
       freeaddrinfo(res);
@@ -90,7 +89,7 @@ int create_clock_source_record(char *sender_string,
       clocks_private_info[i].family = family;
       clocks_private_info[i].vacant_samples = MAX_TIMING_SAMPLES;
       clocks_private_info[i].in_use = 1;
-      debug(1, "create record for ip: %s, family: %d.", &clocks_private_info[i].ip, clocks_private_info[i].family);
+      debug(1, "create record for ip: %s, family: %s.", &clocks_private_info[i].ip, clocks_private_info[i].family == AF_INET6 ? "IPv6" : "IPv4");
     } else {
       die("cannot getaddrinfo for ip: %s.", &clocks_private_info[i].ip);
     }