mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 18:25:07 -05:00
Check SOCK protocol version
This commit is contained in:
@@ -35,24 +35,48 @@
|
|||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define SOCK_MAGIC 0x534f434b
|
||||||
|
|
||||||
struct sock_sample {
|
struct sock_sample {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
double offset;
|
double offset;
|
||||||
int pulse;
|
int pulse;
|
||||||
int leap;
|
int leap;
|
||||||
|
int _pad;
|
||||||
|
int magic;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void read_sample(void *anything)
|
static void read_sample(void *anything)
|
||||||
{
|
{
|
||||||
struct sock_sample sample;
|
struct sock_sample sample;
|
||||||
RCL_Instance instance;
|
RCL_Instance instance;
|
||||||
int sockfd;
|
int sockfd, s;
|
||||||
|
|
||||||
instance = (RCL_Instance)anything;
|
instance = (RCL_Instance)anything;
|
||||||
sockfd = (long)RCL_GetDriverData(instance);
|
sockfd = (long)RCL_GetDriverData(instance);
|
||||||
|
|
||||||
if (recv(sockfd, &sample, sizeof (sample), 0) != sizeof (sample))
|
s = recv(sockfd, &sample, sizeof (sample), 0);
|
||||||
|
|
||||||
|
if (s < 0) {
|
||||||
|
#if 0
|
||||||
|
LOG(LOGS_INFO, LOGF_Refclock, "Error reading from SOCK socket : %s", strerror(errno));
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s != sizeof (sample)) {
|
||||||
|
#if 0
|
||||||
|
LOG(LOGS_INFO, LOGF_Refclock, "Unexpected length of SOCK sample : %d != %d", s, sizeof (sample));
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sample.magic != SOCK_MAGIC) {
|
||||||
|
#if 0
|
||||||
|
LOG(LOGS_INFO, LOGF_Refclock, "Unexpected magic number in SOCK sample : %x != %x", sample.magic, SOCK_MAGIC);
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (sample.pulse) {
|
if (sample.pulse) {
|
||||||
RCL_AddPulse(instance, &sample.tv, sample.offset);
|
RCL_AddPulse(instance, &sample.tv, sample.offset);
|
||||||
|
|||||||
Reference in New Issue
Block a user