]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
clang format
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 2 May 2021 17:25:42 +0000 (18:25 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 2 May 2021 17:25:42 +0000 (18:25 +0100)
nqptp-clock-sources.c
nqptp-message-handlers.c
nqptp-shm-structures.h
nqptp-utilities.c
nqptp.c

index 009732aff1d5daf98fb21cee5f7824ec56b4d285..160a0aae4d096d3ea2ed2ee1fd725949800a01a7 100644 (file)
@@ -106,7 +106,6 @@ void manage_clock_sources(uint64_t reception_time, clock_source_private_data *cl
       }
     }
   }
-
 }
 
 // check all the entries in the clock array and mark all those that
@@ -159,7 +158,7 @@ void update_master() {
   for (i = 0; i < MAX_CLOCKS; i++) {
     if ((clocks_private[i].flags & (1 << clock_is_master)) != 0)
       if (old_master == -1)
-        old_master = i;                                     // find old master
+        old_master = i;                                 // find old master
     clocks_private[i].flags &= ~(1 << clock_is_master); // turn them all off
   }
 
@@ -204,7 +203,7 @@ void update_master() {
     // no master clock
     if (old_master != -1) {
       // but there was a master clock, so remove it
-      debug(1,"shm interface -- remove master clock designation");
+      debug(1, "shm interface -- remove master clock designation");
       update_master_clock_info(0, NULL, 0, 0);
     }
     if (timing_peer_count == 0)
@@ -217,7 +216,7 @@ void update_master() {
     // master_clock_index = best_so_far;
     if (old_master != best_so_far) {
       update_master_clock_info(clocks_private[best_so_far].clock_id,
-                               &clocks_private[best_so_far].ip,
+                               (const char *)&clocks_private[best_so_far].ip,
                                clocks_private[best_so_far].local_time,
                                clocks_private[best_so_far].local_to_source_time_offset);
     }
@@ -225,30 +224,34 @@ void update_master() {
 
   int records_in_use = 0;
   for (i = 0; i < MAX_CLOCKS; i++)
-   if (clocks_private[i].in_use != 0)
-     records_in_use++;
+    if (clocks_private[i].in_use != 0)
+      records_in_use++;
   if (records_in_use > 0) {
-    debug(1,"");
-    debug(1,"Current NQPTP Status:");
+    debug(1, "");
+    debug(1, "Current NQPTP Status:");
     uint32_t peer_mask = (1 << clock_is_a_timing_peer);
-    uint32_t peer_clock_mask =  peer_mask | (1 << clock_is_valid);
+    uint32_t peer_clock_mask = peer_mask | (1 << clock_is_valid);
     uint32_t peer_master_mask = peer_clock_mask | (1 << clock_is_master);
-    uint32_t non_peer_clock_mask =  (1 << clock_is_valid);
+    uint32_t non_peer_clock_mask = (1 << clock_is_valid);
     uint32_t non_peer_master_mask = non_peer_clock_mask | (1 << clock_is_master);
     for (i = 0; i < MAX_CLOCKS; i++) {
       if (clocks_private[i].in_use != 0) {
         if ((clocks_private[i].flags & peer_master_mask) == peer_master_mask) {
-          debug(1,"  Peer Master:     %" PRIx64 "  %s.", clocks_private[i].clock_id, clocks_private[i].ip);
+          debug(1, "  Peer Master:     %" PRIx64 "  %s.", clocks_private[i].clock_id,
+                clocks_private[i].ip);
         } else if ((clocks_private[i].flags & peer_clock_mask) == peer_clock_mask) {
-          debug(1,"  Peer Clock:      %" PRIx64 "  %s.", clocks_private[i].clock_id, clocks_private[i].ip);
+          debug(1, "  Peer Clock:      %" PRIx64 "  %s.", clocks_private[i].clock_id,
+                clocks_private[i].ip);
         } else if ((clocks_private[i].flags & peer_mask) == peer_mask) {
-          debug(1,"  Peer:                              %s.",clocks_private[i].ip);
+          debug(1, "  Peer:                              %s.", clocks_private[i].ip);
         } else if ((clocks_private[i].flags & non_peer_master_mask) == non_peer_master_mask) {
-          debug(1,"  Non Peer Master: %" PRIx64 "  %s.", clocks_private[i].clock_id, clocks_private[i].ip);
+          debug(1, "  Non Peer Master: %" PRIx64 "  %s.", clocks_private[i].clock_id,
+                clocks_private[i].ip);
         } else if ((clocks_private[i].flags & non_peer_clock_mask) == non_peer_clock_mask) {
-          debug(1,"  Non Peer Clock:  %" PRIx64 "  %s.", clocks_private[i].clock_id, clocks_private[i].ip);
+          debug(1, "  Non Peer Clock:  %" PRIx64 "  %s.", clocks_private[i].clock_id,
+                clocks_private[i].ip);
         } else {
-          debug(1,"  Non Peer Record:                   %s.",clocks_private[i].ip);
+          debug(1, "  Non Peer Record:                   %s.", clocks_private[i].ip);
         }
       }
     }
index 448f8602c4d8916cb3de46807e913c4f2b6a26d4..0a9799d6206fc9705f8316f4286c0bc484849d70 100644 (file)
  *
  * Commercial licensing is also available.
  */
+#include <arpa/inet.h>
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
- #include <arpa/inet.h>
 
 #include "debug.h"
 #include "general-utilities.h"
@@ -238,7 +238,6 @@ void handle_sync(char *buf, __attribute__((unused)) ssize_t recv_len,
   if (msg->header.correctionField != 0)
     debug(3, "correctionField: %" PRIx64 ".", msg->header.correctionField);
 
-
   int discard_sync = 0;
 
   // check if we should discard this SYNC
@@ -311,31 +310,32 @@ void handle_sync(char *buf, __attribute__((unused)) ssize_t recv_len,
       header.msg_iov->iov_len = sizeof(m);
       header.msg_iovlen = 1;
 
-/*
-      void *destination_addr = NULL;
-      uint16_t destination_port = 0;
+      /*
+            void *destination_addr = NULL;
+            uint16_t destination_port = 0;
 
-      sa_family_t connection_ip_family = to_sock_addr->SAFAMILY;
+            sa_family_t connection_ip_family = to_sock_addr->SAFAMILY;
 
-#ifdef AF_INET6
-      if (connection_ip_family == AF_INET6) {
-        struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)to_sock_addr;
-        destination_addr = &(sa6->sin6_addr);
-        destination_port = ntohs(sa6->sin6_port);
-      }
-#endif
-      if (connection_ip_family == AF_INET) {
-        struct sockaddr_in *sa4 = (struct sockaddr_in *)to_sock_addr;
-        destination_addr = &(sa4->sin_addr);
-        destination_port = ntohs(sa4->sin_port);
-      }
+      #ifdef AF_INET6
+            if (connection_ip_family == AF_INET6) {
+              struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)to_sock_addr;
+              destination_addr = &(sa6->sin6_addr);
+              destination_port = ntohs(sa6->sin6_port);
+            }
+      #endif
+            if (connection_ip_family == AF_INET) {
+              struct sockaddr_in *sa4 = (struct sockaddr_in *)to_sock_addr;
+              destination_addr = &(sa4->sin_addr);
+              destination_port = ntohs(sa4->sin_port);
+            }
 
 
-      char destination_string[256];
-      memset(destination_string, 0, sizeof(destination_string));
-      inet_ntop(connection_ip_family, destination_addr, destination_string, sizeof(destination_string));
-       debug(1,"Send Delay_Req to %s:%u",  &destination_string, destination_port);
-*/
+            char destination_string[256];
+            memset(destination_string, 0, sizeof(destination_string));
+            inet_ntop(connection_ip_family, destination_addr, destination_string,
+      sizeof(destination_string)); debug(1,"Send Delay_Req to %s:%u",  &destination_string,
+      destination_port);
+      */
       clock_private_info->t3 = get_time_now(); // in case nothing better works
       if ((sendmsg(socket_number, &header, 0)) == -1) {
         // debug(1, "Error in sendmsg [errno = %d] to socket %d.", errno, socket_number);
@@ -390,7 +390,7 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
 void handle_delay_resp(char *buf, __attribute__((unused)) ssize_t recv_len,
                        clock_source_private_data *clock_private_info,
                        __attribute__((unused)) uint64_t reception_time) {
-    // debug(1,"Delay_Resp from %s", clock_private_info->ip);
+  // debug(1,"Delay_Resp from %s", clock_private_info->ip);
   struct ptp_delay_resp_message *msg = (struct ptp_delay_resp_message *)buf;
 
   if ((clock_private_info->current_stage == follow_up_seen) &&
@@ -482,7 +482,7 @@ void handle_delay_resp(char *buf, __attribute__((unused)) ssize_t recv_len,
       uint32_t old_flags = clock_private_info->flags;
 
       if ((clock_private_info->flags & (1 << clock_is_valid)) == 0) {
-        debug(1,"clock %" PRIx64 " is now valid at: %s", packet_clock_id, clock_private_info->ip);
+        debug(1, "clock %" PRIx64 " is now valid at: %s", packet_clock_id, clock_private_info->ip);
       }
       clock_private_info->clock_id = packet_clock_id;
       clock_private_info->flags |= (1 << clock_is_valid);
@@ -494,10 +494,9 @@ void handle_delay_resp(char *buf, __attribute__((unused)) ssize_t recv_len,
       if (old_flags != clock_private_info->flags) {
         update_master();
       } else if ((clock_private_info->flags & (1 << clock_is_master)) != 0) {
-        update_master_clock_info(clock_private_info->clock_id,
-                                 &clock_private_info->ip,
-                                 clock_private_info->local_time,
-                                 clock_private_info->local_to_source_time_offset);
+        update_master_clock_info(
+            clock_private_info->clock_id, (const char *)&clock_private_info->ip,
+            clock_private_info->local_time, clock_private_info->local_to_source_time_offset);
       }
 
       clock_private_info->next_sample_goes_here++;
index 50d9e9aacc5544c73528ce4c0106afde9e8a137d..3e3f0cabac1ec87dee3fef7b580e961e893dcabc 100644 (file)
 #include <pthread.h>
 
 struct shm_structure {
-  pthread_mutex_t shm_mutex; // for safely accessing the structure
-  uint16_t version;          // check this is equal to NQPTP_SHM_STRUCTURES_VERSION
-  uint32_t flags;            // unused
-  uint64_t master_clock_id;  // the current master clock
-  char master_clock_ip[64];  // where it's coming from
-  uint64_t local_time;       // the time when the offset was calculated
+  pthread_mutex_t shm_mutex;            // for safely accessing the structure
+  uint16_t version;                     // check this is equal to NQPTP_SHM_STRUCTURES_VERSION
+  uint32_t flags;                       // unused
+  uint64_t master_clock_id;             // the current master clock
+  char master_clock_ip[64];             // where it's coming from
+  uint64_t local_time;                  // the time when the offset was calculated
   uint64_t local_to_master_time_offset; // add this to the local time to get master clock time
 };
 
index 86a76c47c34a3e474601495f4873830aa8491c95..6a5904cfe537074168b98436d8648a86fdef9340 100644 (file)
@@ -209,6 +209,7 @@ uint64_t get_self_clock_id() {
   return result;
 }
 
+/*
 void send_delay_req_message(int socket_number, SOCKADDR *from_sock_addr, uint16_t seqno) {
   struct ptp_delay_req_message m;
   memset(&m, 0, sizeof(m));
@@ -236,6 +237,7 @@ void send_delay_req_message(int socket_number, SOCKADDR *from_sock_addr, uint16_
   if ((sendmsg(socket_number, &header, 0)) == -1) {
     debug(1, "Error in sendmsg [errno = %d]", errno);
   } else {
-    debug_print_buffer(1, &m, sizeof(m));
+    debug_print_buffer(1, (char *)&m, sizeof(m));
   }
 }
+*/
diff --git a/nqptp.c b/nqptp.c
index 8db0faafd1d9cb6e1290ec64119457f7cb1d36da..14efaaa3ffb7265857cc1311b13c5e3c19291caa 100644 (file)
--- a/nqptp.c
+++ b/nqptp.c
@@ -84,7 +84,8 @@ void update_master_clock_info(uint64_t master_clock_id, const char *ip, uint64_t
     warn("Can't acquire mutex to update master clock!");
   shared_memory->master_clock_id = master_clock_id;
   if (ip != NULL)
-    strncpy((char *)&shared_memory->master_clock_ip, ip, FIELD_SIZEOF(struct shm_structure, master_clock_ip) - 1);
+    strncpy((char *)&shared_memory->master_clock_ip, ip,
+            FIELD_SIZEOF(struct shm_structure, master_clock_ip) - 1);
   else
     shared_memory->master_clock_ip[0] = '\0';
   shared_memory->local_time = local_time;
@@ -130,7 +131,8 @@ int main(int argc, char **argv) {
   for (i = 1; i < argc; ++i) {
     if (argv[i][0] == '-') {
       if (strcmp(argv[i] + 1, "V") == 0) {
-        fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", VERSION, NQPTP_SHM_STRUCTURES_VERSION);
+        fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", VERSION,
+                NQPTP_SHM_STRUCTURES_VERSION);
         exit(EXIT_SUCCESS);
       } else if (strcmp(argv[i] + 1, "vvv") == 0) {
         debug_level = 3;