]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Check SOCK protocol version
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 24 Nov 2009 16:48:30 +0000 (17:48 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 25 Nov 2009 13:37:41 +0000 (14:37 +0100)
refclock_sock.c

index 91dbbc9c1f3798034f88dfc18132b1c89f08b16f..65f071e9201f98ceb6fe963c138771f99329bbe1 100644 (file)
 #include <sys/un.h>
 #include <unistd.h>
 
+#define SOCK_MAGIC 0x534f434b
+
 struct sock_sample {
   struct timeval tv;
   double offset;
   int pulse;
   int leap;
+  int _pad;
+  int magic;
 };
 
 static void read_sample(void *anything)
 {
   struct sock_sample sample;
   RCL_Instance instance;
-  int sockfd;
+  int sockfd, s;
 
   instance = (RCL_Instance)anything;
   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;
+  }
+
+  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) {
     RCL_AddPulse(instance, &sample.tv, sample.offset);