[Git][NTPsec/ntpsec][master] TESTFRAME: Resurrect packet_parse(), we'll need it soon.
Eric S. Raymond
gitlab at mg.gitlab.com
Thu Sep 15 11:04:47 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
af26e62d by Eric S. Raymond at 2016-09-15T07:04:34-04:00
TESTFRAME: Resurrect packet_parse(), we'll need it soon.
- - - - -
1 changed file:
- ntpd/ntp_intercept.c
Changes:
=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -690,6 +690,61 @@ static void packet_dump(char *buf, size_t buflen,
}
}
+#ifdef __unused__
+static void lfpload(char *str, l_fp *fp)
+{
+ uint64_t np;
+
+ if (sscanf(str, "%" PRIu64, &np) != 1)
+ replay_fail("bad fp format\n");
+
+
+ (fp)->l_uf = (np) & 0xFFFFFFFF; \
+ (fp)->l_ui = (((np) >> FRACTION_PREC) & 0xFFFFFFFF); \
+}
+
+static size_t packet_parse(char *pktbuf, struct pkt *pkt)
+{
+ char refbuf[32], orgbuf[32], recbuf[32], xmtbuf[32], macbuf[BUFSIZ];
+ int li_vn_mode = 0, stratum = 0, ppoll = 0, precision = 0;
+ size_t pktlen;
+
+ if (sscanf(pktbuf, "%d:%d:%d:%d:%u:%u:%u:%[^:]:%[^:]:%[^:]:%[^:] %s",
+ &li_vn_mode, &stratum,
+ &ppoll, &precision,
+ &pkt->rootdelay, &pkt->rootdisp,
+ &pkt->refid,
+ refbuf, orgbuf, recbuf, xmtbuf, macbuf) != 11)
+ replay_fail("garbled event format\n");
+
+ /* extra transfers required because the struct members are int8_t */
+ pkt->li_vn_mode = (uint8_t)li_vn_mode;
+ pkt->stratum = (uint8_t)stratum;
+ pkt->ppoll = (uint8_t)ppoll;
+ pkt->precision = (int8_t)precision;
+ lfpload(refbuf, &pkt->reftime);
+ lfpload(orgbuf, &pkt->org);
+ lfpload(recbuf, &pkt->rec);
+ lfpload(xmtbuf, &pkt->xmt);
+
+ pktlen = LEN_PKT_NOMAC;
+ memset(pkt->exten, '\0', sizeof(pkt->exten));
+ if (strcmp(macbuf, "nomac") != 0) {
+ size_t i;
+ for (i = 0; i < strlen(macbuf)/2; i++) {
+ int hexval;
+ if (sscanf(macbuf + 2*i, "%02x", &hexval) != 1) {
+ fprintf(stderr, "ntpd: bad hexval format at line %d\n", lineno);
+ exit(1);
+ }
+ pkt->exten[i] = hexval & 0xff;
+ ++pktlen;
+ }
+ }
+ return pktlen;
+}
+#endif
+
void intercept_sendpkt(const char *legend,
sockaddr_u *dest, struct interface *ep, int ttl,
void *pkt, int len)
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/af26e62d07ad2fdde68f71235b57b61ab9d51304
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160915/ea7e211f/attachment.html>
More information about the vc
mailing list