]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
add ip family stuff to the clock records and the port sockets
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Sat, 30 Oct 2021 17:28:08 +0000 (18:28 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Sat, 30 Oct 2021 17:28:08 +0000 (18:28 +0100)
nqptp-clock-sources.c
nqptp-clock-sources.h
nqptp-utilities.c
nqptp-utilities.h

index c894300b43230e9505642d602bba08fc231a3491..4354c15dd80172cd553893a97c6787dd53b02ad1 100644 (file)
@@ -71,13 +71,29 @@ int create_clock_source_record(char *sender_string,
   }
 
   if (found == 1) {
-    response = i;
-    memset(&clocks_private_info[i], 0, sizeof(clock_source_private_data));
-    strncpy((char *)&clocks_private_info[i].ip, sender_string,
-            FIELD_SIZEOF(clock_source_private_data, ip) - 1);
-    clocks_private_info[i].vacant_samples = MAX_TIMING_SAMPLES;
-    clocks_private_info[i].in_use = 1;
-    debug(2, "create record for ip: %s.", &clocks_private_info[i].ip);
+    int family = 0;
+    int ret;
+  // check its ipv4/6 family
+    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);
+      response = i;
+      memset(&clocks_private_info[i], 0, sizeof(clock_source_private_data));
+      strncpy((char *)&clocks_private_info[i].ip, sender_string,
+              FIELD_SIZEOF(clock_source_private_data, ip) - 1);
+      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);
+    } else {
+      die("cannot getaddrinfo for ip: %s.", &clocks_private_info[i].ip);
+    }
   } else {
     die("Clock tables full!");
   }
index 28b5b0967cf655bd6343533f5f1cd65ec1c63bec..1a8cd66f02835858307ff86bf146847d0f301674 100644 (file)
@@ -42,6 +42,7 @@ typedef struct {
 // information about each clock source
 typedef struct {
   char ip[64]; // 64 is nicely aligned and bigger than INET6_ADDRSTRLEN (46)
+  int family; // AF_INET or AF_INET6
   uint64_t clock_id;
   uint64_t local_time; // the local time when the offset was calculated
   uint64_t source_time;
index aa3d2d3b2b80dc5656d2a69d5345ddd5de24de10..3663486fc9dcac2add9bf92c8073b55903293224 100644 (file)
@@ -96,6 +96,7 @@ void open_sockets_at_port(uint16_t port, sockets_open_bundle *sockets_open_stuff
         debug(2, "listening on %s port %d.", p->ai_family == AF_INET6 ? "IPv6" : "IPv4", port);
         sockets_open_stuff->sockets[sockets_open_stuff->sockets_open].number = fd;
         sockets_open_stuff->sockets[sockets_open_stuff->sockets_open].port = port;
+        sockets_open_stuff->sockets[sockets_open_stuff->sockets_open].family = p->ai_family;
         sockets_open_stuff->sockets_open++;
       }
     }
index 66367a8be2d759c61b800ba62cd44cde75d51068..3d2e933dd92a95e07bd016384bf6a1e97283831c 100644 (file)
@@ -30,6 +30,7 @@
 typedef struct {
   int number;
   uint16_t port;
+  int family; // AF_INET or AF_INET6
 } socket_info;
 
 typedef struct {