<html lang='en'>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<title>
GitLab
</title>
</meta>
</head>
<style>
  img {
    max-width: 100%;
    height: auto;
  }
  p.details {
    font-style:italic;
    color:#777
  }
  .footer p {
    font-size:small;
    color:#777
  }
  pre.commit-message {
    white-space: pre-wrap;
  }
  .file-stats a {
    text-decoration: none;
  }
  .file-stats .new-file {
    color: #090;
  }
  .file-stats .deleted-file {
    color: #B00;
  }
</style>
<body>
<div class='content'>
<h3>
Eric S. Raymond pushed to branch master
at <a href="https://gitlab.com/NTPsec/ntpsec">NTPsec / ntpsec</a>
</h3>
<h4>
Commits:
</h4>
<ul>
<li>
<strong><a href="https://gitlab.com/NTPsec/ntpsec/commit/7932ed36a74002601ca61379a13ec002e8670c93">7932ed36</a></strong>
<div>
<span>by Eric S. Raymond</span>
<i>at 2015-12-29T22:26:42Z</i>
</div>
<pre class='commit-message'>Another step towards replay: packets now round-trip through dump and parse.</pre>
</li>
</ul>
<h4>1 changed file:</h4>
<ul>
<li class='file-stats'>
<a href='#diff-0'>
ntpd/ntp_intercept.c
</a>
</li>
</ul>
<h4>Changes:</h4>
<li id='diff-0'>
<a href='https://gitlab.com/NTPsec/ntpsec/commit/7932ed36a74002601ca61379a13ec002e8670c93#diff-0'>
<strong>
ntpd/ntp_intercept.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/ntpd/ntp_intercept.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/ntpd/ntp_intercept.c
</span><span style="color: #aaaaaa">@@ -101,6 +101,8 @@ Reference-clock eventare not yet intercepted.
</span> #include "ntp_assert.h"
 #include "ntp_intercept.h"
 #include "ntp_fp.h"
<span style="color: #000000;background-color: #ddffdd">+#include "lib_strbuf.h"
+#include "ntp_stdlib.h"
</span> #include "ntp_syscall.h"
 #include "ntp_leapsec.h"
 
<span style="color: #aaaaaa">@@ -262,12 +264,6 @@ void intercept_getconfig(const char *configfile)
</span>     }
 }
 
<span style="color: #000000;background-color: #ffdddd">-/*
- * An lfp used as a full date has an an unsigned seconds part.
- * Invert this with atolfp().
- */
-#define lfpdump(n)     ulfptoa(n, 10)
-
</span> void intercept_get_systime(const char *legend, l_fp *now)
 {
     struct timespec ts;        /* seconds and nanoseconds */
<span style="color: #aaaaaa">@@ -618,6 +614,39 @@ intercept_leapsec_load_file(
</span>     return loaded;
 }
 
<span style="color: #000000;background-color: #ddffdd">+#define LFPTOUINT64(lfp)        ((lfp)->l_uf | ((lfp)->l_ui << ))
+
+/*
+ * These functions are requited beaus dplfptoa() is lodssy and won't
+ * invert properly thrpugh atolfp().
+ */
+
+static char *lfpdump(l_fp *fp)
+{
+    char *buf;
+    uint64_t   np;
+
+    LIB_GETBUF(buf);
+
+    np = fp->l_ui;
+    np <<= FRACTION_PREC;
+    np |= fp->l_uf;
+
+    snprintf(buf, LIB_BUFLENGTH, "%lx", np);
+
+    return buf;
+}
+
+static void lfpload(char *str, l_fp *fp)
+{
+    uint64_t   np;
+
+    sscanf(str, "%lx", &np);
+    
+    (fp)->l_uf = (np) & 0xFFFFFFFF;                                     \
+    (fp)->l_ui = (((np) >> FRACTION_PREC) & 0xFFFFFFFF);          \
+}
+
</span> static void packet_dump(char *buf, size_t buflen,
                        sockaddr_u *dest, struct pkt *pkt, size_t len)
 {
<span style="color: #aaaaaa">@@ -643,12 +672,12 @@ static void packet_dump(char *buf, size_t buflen,
</span>   }
 }
 
<span style="color: #000000;background-color: #ffdddd">-static void packet_parse(char *pktbuf, char *macbuf, struct pkt *pkt)
</span><span style="color: #000000;background-color: #ddffdd">+static size_t packet_parse(char *pktbuf, char *macbuf, struct pkt *pkt)
</span> {
     char refbuf[32], orgbuf[32], recbuf[32], xmtbuf[32];
     int fc, li_vn_mode = 0, stratum = 0, ppoll = 0, precision = 0;
<span style="color: #000000;background-color: #ddffdd">+    size_t pktlen;
</span> 
<span style="color: #000000;background-color: #ffdddd">-    printf("Foo! %s\n", pktbuf);
</span>     if ((fc = sscanf(pktbuf, "%d:%d:%d:%d:%u:%u:%u:%[^:]:%[^:]:%[^:]:%[^:]",
                     &li_vn_mode, &stratum,
                     &ppoll, &precision,
<span style="color: #aaaaaa">@@ -665,11 +694,12 @@ static void packet_parse(char *pktbuf, char *macbuf, struct pkt *pkt)
</span>     pkt->stratum = stratum;
     pkt->ppoll = ppoll;
     pkt->precision = precision;
<span style="color: #000000;background-color: #ffdddd">-    atolfp(refbuf, &pkt->reftime);
-    atolfp(orgbuf, &pkt->org);
-    atolfp(recbuf, &pkt->rec);
-    atolfp(xmtbuf, &pkt->xmt);
</span><span style="color: #000000;background-color: #ddffdd">+    lfpload(refbuf, &pkt->reftime);
+    lfpload(orgbuf, &pkt->org);
+    lfpload(recbuf, &pkt->rec);
+    lfpload(xmtbuf, &pkt->xmt);
</span> 
<span style="color: #000000;background-color: #ddffdd">+    pktlen = LEN_PKT_NOMAC;
</span>     memset(pkt->exten, '\0', sizeof(pkt->exten));
     if (strcmp(macbuf, "nomac") != 0) {
        size_t i;
<span style="color: #aaaaaa">@@ -677,8 +707,10 @@ static void packet_parse(char *pktbuf, char *macbuf, struct pkt *pkt)
</span>       int hexval;
            sscanf(macbuf + 2*i, "%02x", &hexval);
            pkt->exten[i] = hexval & 0xff;
<span style="color: #000000;background-color: #ddffdd">+            ++pktlen;
</span>   }
     }
<span style="color: #000000;background-color: #ddffdd">+    return pktlen;
</span> }
 
 static void recvbuf_dump(char *buf, size_t buflen, struct recvbuf *rbufp)
<span style="color: #aaaaaa">@@ -768,14 +800,14 @@ void intercept_replay(void)
</span>           exit(1);
            }
 
<span style="color: #000000;background-color: #ffdddd">-            atolfp(recvbuf, &rbuf.recv_time);
</span><span style="color: #000000;background-color: #ddffdd">+       lfpload(recvbuf, &rbuf.recv_time);
</span>       if (!is_ip_address(srcbuf, AF_UNSPEC, &rbuf.recv_srcadr)) {
                fprintf(stderr, "ntpd: invalid IP address in receive at line %d\n", lineno);
                exit(1);
            }
 
            pkt = &rbuf.recv_pkt;
<span style="color: #000000;background-color: #ffdddd">-            packet_parse(pktbuf, macbuf, pkt);
</span><span style="color: #000000;background-color: #ddffdd">+       rbuf.recv_length = packet_parse(pktbuf, macbuf, pkt);
</span> 
            /*
             * If the packet doesn't dump identically to how it came in,
</code></pre>

<br>
</li>

</div>
<div class='footer' style='margin-top: 10px;'>
<p>

<br>
<a href="https://gitlab.com/NTPsec/ntpsec/commit/7932ed36a74002601ca61379a13ec002e8670c93">View it on GitLab</a>.
<br>
You're receiving this email because of your account on gitlab.com.
If you'd like to receive fewer emails, you can adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Commit","url":"https://gitlab.com/NTPsec/ntpsec/commit/7932ed36a74002601ca61379a13ec002e8670c93"}}</script>
</p>
</div>
</body>
</html>