From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Sun, 2 May 2021 17:25:42 +0000 (+0100) Subject: clang format X-Git-Tag: 1.1-dev~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7efbf27d63cbd2f42e9da45dd0f189a7caa63db0;p=thirdparty%2Fnqptp.git clang format --- diff --git a/nqptp-clock-sources.c b/nqptp-clock-sources.c index 009732a..160a0aa 100644 --- a/nqptp-clock-sources.c +++ b/nqptp-clock-sources.c @@ -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); } } } diff --git a/nqptp-message-handlers.c b/nqptp-message-handlers.c index 448f860..0a9799d 100644 --- a/nqptp-message-handlers.c +++ b/nqptp-message-handlers.c @@ -16,10 +16,10 @@ * * Commercial licensing is also available. */ +#include #include #include #include - #include #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++; diff --git a/nqptp-shm-structures.h b/nqptp-shm-structures.h index 50d9e9a..3e3f0ca 100644 --- a/nqptp-shm-structures.h +++ b/nqptp-shm-structures.h @@ -36,12 +36,12 @@ #include 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 }; diff --git a/nqptp-utilities.c b/nqptp-utilities.c index 86a76c4..6a5904c 100644 --- a/nqptp-utilities.c +++ b/nqptp-utilities.c @@ -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 8db0faa..14efaaa 100644 --- 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;