}
}
}
-
}
// check all the entries in the clock array and mark all those that
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
}
// 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)
// 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);
}
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);
}
}
}
*
* 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"
if (msg->header.correctionField != 0)
debug(3, "correctionField: %" PRIx64 ".", msg->header.correctionField);
-
int discard_sync = 0;
// check if we should discard this SYNC
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);
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) &&
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);
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++;
#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
};
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));
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));
}
}
+*/
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;
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;