]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Backport sntp changes from -dev
authorDave Hart <hart@ntp.org>
Wed, 10 Nov 2010 02:29:39 +0000 (02:29 +0000)
committerDave Hart <hart@ntp.org>
Wed, 10 Nov 2010 02:29:39 +0000 (02:29 +0000)
bk: 4cda0393uZFUH3m8jSJLEE9i932y3g

13 files changed:
m4/ntp_lib_m.m4 [new file with mode: 0644]
sntp/Makefile.am
sntp/configure.ac
sntp/crypto.c
sntp/header.h
sntp/kod_management.c
sntp/log.c
sntp/main.c
sntp/main.h [new file with mode: 0644]
sntp/networking.c
sntp/networking.h
sntp/sntp.c [new file with mode: 0644]
sntp/utilities.c

diff --git a/m4/ntp_lib_m.m4 b/m4/ntp_lib_m.m4
new file mode 100644 (file)
index 0000000..582051a
--- /dev/null
@@ -0,0 +1,16 @@
+dnl ######################################################################
+dnl What do we need for math libraries?
+AC_DEFUN([NTP_LIB_M], [
+LIBM=
+case "$host" in
+ *-*-darwin*)
+    ;;
+ *)
+    _libs=$LIBS
+    AC_SEARCH_LIBS(cos, m, LIBM="-lm")
+    LIBS=$_libs
+    ;;
+esac
+AC_SUBST([LIBM])
+])
+dnl ======================================================================
index ad55a55d25b97684c6e659c96952abe7dd8525b0..bb0952f9b82a2b7e03d7ef5507098b789cbe48ee 100644 (file)
@@ -10,7 +10,7 @@ AM_CPPFLAGS= $(LIBOPTS_CFLAGS) -I$(top_srcdir)/../include \
        -I$(top_srcdir)/../lib/isc/nothreads/include \
        -I$(top_srcdir)/../lib/isc/unix/include
 
-LDADD= $(LIBOPTS_LDADD) -lm ../libntp/libntp.a @LCRYPTO@
+LDADD= $(LIBOPTS_LDADD) $(LIBM) ../libntp/libntp.a @LCRYPTO@
 
 run_ag=                cd $(srcdir) && env PATH="$(abs_builddir):$(PATH)"      \
                autogen -L ../include --writable
@@ -39,8 +39,10 @@ sntp_SOURCES =               \
        log.c           \
        log.h           \
        main.c          \
+       main.h          \
        networking.c    \
        networking.h    \
+       sntp.c          \
        sntp-opts.c     \
        sntp-opts.h     \
        utilities.c     \
index 0eee100dbef9a8e068d49b6bb0ab4342735fe7e4..6ff842f465c8ff6def2e154e680e249aa0be8ef6 100644 (file)
@@ -134,6 +134,7 @@ AC_PROG_LIBTOOL
 NTP_DIR_SEP
 
 # Checks for libraries.
+NTP_LIB_M
 
 AC_CHECK_FUNC([gethostent], ,
        [AC_SEARCH_LIBS([gethostent], [nsl], , , [$libxnet -lsocket])])
index c8fb85e7fc1c8d6b1ea64e1801cb905ab1f54003..0e582a9a2708c487f1dcbb63314f87a9e86d6bfe 100644 (file)
@@ -1,3 +1,4 @@
+#include <config.h>
 #include "crypto.h"
 #include <ctype.h>
 
index 4e3fa9661a10c4120d0734480b7d0e3b9f93ebfc..21805f1950061d65284c9cc4bca3f56f7dd9d319 100644 (file)
@@ -24,7 +24,7 @@ No changes should be needed for any system that is even remotely like Unix. */
 #    define SAVENAME "/etc/sntp.state" /* Stores the recovery state */
 #endif
 
-#define DEBUG
+//#define DEBUG
 
 
 
index 4bdb4e8d93cccc543c069d0e13be0c560f84c56f..dfc989d14bf6f4d340f35ed175a3bd3cec5ce9a5 100644 (file)
@@ -1,3 +1,4 @@
+#include <config.h>
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -6,7 +7,7 @@
 #include "log.h"
 #include "sntp-opts.h"
 #include "ntp_stdlib.h"
-#define DEBUG
+//#define DEBUG
 
 int kod_init = 0, kod_db_cnt = 0;
 const char *kod_db_file;
index 52d9fd25d5fbf882c12713a6541dfabc78ba29d5..5b39acc797d2453cb1572268ef5921c6b35dacfe 100644 (file)
@@ -1,3 +1,4 @@
+#include <config.h>
 #include "log.h"
 #include "sntp-opts.h"
 
@@ -15,7 +16,7 @@ void log_msg(char *message, int type) {
                fprintf(log_file, "%s: %s\n", timestamp, message);
                fflush(log_file);
        } else {
-               syslog(type, message);
+               syslog(type, "%s", message);
        }
 }
 
@@ -31,7 +32,7 @@ void debug_msg(char *message) {
 #ifdef LOG_PERROR
                        | LOG_PERROR
 #endif
-                       | LOG_CONS, message);
+                      | LOG_CONS, "%s", message);
        }
 }
 
index 23ccd4c121ae8b2a3fbdbb0113daf316e09d5ff7..b32800ced538e3303a0e3fcb7643524fa5657075 100644 (file)
@@ -1,24 +1,11 @@
-#include <l_stdlib.h>
-#include <ntp_fp.h>
-#include <ntp.h>
-#include <ntp_stdlib.h>
-#include <ntp_unixtime.h>
-#include <isc/result.h>
-#include <isc/net.h>
-#include <stdio.h>
-
-#include <sntp-opts.h>
-
-#include "crypto.h"
+#include "main.h"
+
 #include "kod_management.h"
 #include "networking.h"
 #include "utilities.h"
 #include "log.h"
 
-char *progname = "sntp";       /* for msyslog */
-
 int ai_fam_pref = AF_UNSPEC;
-volatile int debug;
 
 struct key *keys = NULL;
 
@@ -40,15 +27,6 @@ do {                                                 \
 } while (0)
 
 
-int 
-main (
-       int argc,
-       char **argv
-       ) 
-{
-       return sntp_main(argc, argv);
-}
-
 /*
  * The actual main function.
  */
@@ -178,6 +156,187 @@ static union {
 
 #define r_pkt  rbuf.pkt
 
+int
+generate_pkt (
+       struct pkt *x_pkt,
+       const struct timeval *tv_xmt,
+       int key_id,
+       struct key *pkt_key
+       )
+{
+       l_fp xmt;
+       int pkt_len = LEN_PKT_NOMAC;
+       memset(x_pkt, 0, sizeof(struct pkt));
+       TVTOTS(tv_xmt, &xmt);
+       HTONL_FP(&xmt, &(x_pkt->xmt));
+       x_pkt->stratum = STRATUM_TO_PKT(STRATUM_UNSPEC);
+       x_pkt->ppoll = 8;
+       /* FIXME! Modus broadcast + adr. check -> bdr. pkt */
+       set_li_vn_mode(x_pkt, LEAP_NOTINSYNC, 4, 3);
+       if (pkt_key != NULL) {
+               int mac_size = 20; /* max room for MAC */
+               x_pkt->exten[0] = htonl(key_id);
+               mac_size = make_mac((char *)x_pkt, pkt_len, mac_size, pkt_key, (char *)&x_pkt->exten[1]);
+               if (mac_size)
+                       pkt_len += mac_size + 4;
+       }
+       return pkt_len;
+}
+
+int
+handle_pkt (
+       int rpktl,
+       struct pkt *rpkt,
+       struct addrinfo *host
+       )
+{
+       struct timeval tv_dst;
+       int sw_case, digits;
+       char *hostname = NULL, *log_str, *ref, *ts_str = NULL;
+       double offset, precision, root_dispersion;
+       char addr_buf[INET6_ADDRSTRLEN];
+
+       if(rpktl > 0)
+               sw_case = 1;
+       else
+               sw_case = rpktl;
+
+       switch(sw_case) {
+       case SERVER_UNUSEABLE:
+               return -1;
+               break;
+
+       case PACKET_UNUSEABLE:
+               break;
+       case SERVER_AUTH_FAIL:
+               break;
+
+       case KOD_DEMOBILIZE:
+               /* Received a DENY or RESTR KOD packet */
+               hostname = addrinfo_to_str(host);
+               ref = (char *)&rpkt->refid;
+               add_entry(hostname, ref);
+
+               if (ENABLED_OPT(NORMALVERBOSE))
+                       printf("sntp handle_pkt: Received KOD packet with code: %c%c%c%c from %s, demobilizing all connections\n",
+                                  ref[0], ref[1], ref[2], ref[3],
+                                  hostname);
+
+               log_str = emalloc(INET6_ADDRSTRLEN + 72);
+               snprintf(log_str, INET6_ADDRSTRLEN + 72, 
+                        "Received a KOD packet with code %c%c%c%c from %s, demobilizing all connections", 
+                        ref[0], ref[1], ref[2], ref[3],
+                        hostname);
+               log_msg(log_str, LOG_WARNING | LOG_CONS);
+               free(log_str);
+               break;
+
+       case KOD_RATE:
+               /* Hmm... probably we should sleep a bit here */
+               break;
+
+       case 1:
+               if (ENABLED_OPT(NORMALVERBOSE)) {
+                       getnameinfo(host->ai_addr, host->ai_addrlen, addr_buf, 
+                               sizeof(addr_buf), NULL, 0, NI_NUMERICHOST);
+                       printf("sntp handle_pkt: Received %i bytes from %s\n", rpktl, addr_buf);
+               }
+
+               GETTIMEOFDAY(&tv_dst, (struct timezone *)NULL);
+               tv_dst.tv_sec += JAN_1970;
+
+               offset_calculation(rpkt, rpktl, &tv_dst, &offset, &precision, &root_dispersion);
+
+               for (digits = 0; (precision *= 10.) < 1.; ++digits)
+                       /* empty */ ;
+               if (digits > 6)
+                       digits = 6;
+
+               ts_str = tv_to_str(&tv_dst);
+               printf("%s ", ts_str);
+               if(offset > 0)
+                       printf("+");
+               printf("%.*f", digits, offset);
+               if (root_dispersion > 0.)
+                       printf(" +/- %f secs", root_dispersion);
+               printf("\n");
+               free(ts_str);
+
+               if(ENABLED_OPT(SETTOD) || ENABLED_OPT(ADJTIME))
+                       return set_time(offset); 
+
+               return 0;
+       }
+
+       return 1;
+}
+
+void
+offset_calculation (
+       struct pkt *rpkt,
+       int rpktl,
+       struct timeval *tv_dst,
+       double *offset,
+       double *precision,
+       double *root_dispersion
+       )
+{
+       l_fp p_rec, p_xmt, p_ref, p_org, tmp, dst;
+       u_fp p_rdly, p_rdsp;
+       double t21, t34, delta;
+
+       /* Convert timestamps from network to host byte order */
+       p_rdly = NTOHS_FP(rpkt->rootdelay);
+       p_rdsp = NTOHS_FP(rpkt->rootdisp);
+       NTOHL_FP(&rpkt->reftime, &p_ref);
+       NTOHL_FP(&rpkt->org, &p_org);
+       NTOHL_FP(&rpkt->rec, &p_rec);
+       NTOHL_FP(&rpkt->xmt, &p_xmt);
+
+       *precision = LOGTOD(rpkt->precision);
+#ifdef DEBUG
+       printf("sntp precision: %f\n", *precision);
+#endif /* DEBUG */
+
+       *root_dispersion = FPTOD(p_rdsp);
+
+#ifdef DEBUG
+       printf("sntp rootdelay: %f\n", FPTOD(p_rdly));
+       printf("sntp rootdisp: %f\n", *root_dispersion);
+
+       pkt_output(rpkt, rpktl, stdout);
+
+       printf("sntp offset_calculation: rpkt->reftime:\n");
+       l_fp_output(&(rpkt->reftime), stdout);
+       printf("sntp offset_calculation: rpkt->org:\n");
+       l_fp_output(&(rpkt->org), stdout);
+       printf("sntp offset_calculation: rpkt->rec:\n");
+       l_fp_output(&(rpkt->rec), stdout);
+       printf("sntp offset_calculation: rpkt->rec:\n");
+       l_fp_output_bin(&(rpkt->rec), stdout);
+       printf("sntp offset_calculation: rpkt->rec:\n");
+       l_fp_output_dec(&(rpkt->rec), stdout);
+       printf("sntp offset_calculation: rpkt->xmt:\n");
+       l_fp_output(&(rpkt->xmt), stdout);
+#endif
+
+       /* Compute offset etc. */
+       tmp = p_rec;
+       L_SUB(&tmp, &p_org);
+       LFPTOD(&tmp, t21);
+       TVTOTS(tv_dst, &dst);
+       tmp = p_xmt;
+       L_SUB(&tmp, &dst);
+       LFPTOD(&tmp, t34);
+       *offset = (t21 + t34) / 2.;
+       delta = t21 - t34;
+
+       if(ENABLED_OPT(NORMALVERBOSE))
+               printf("sntp offset_calculation:\tt21: %.6f\t\t t34: %.6f\n\t\tdelta: %.6f\t offset: %.6f\n", 
+                          t21, t34, delta, *offset);
+}
+
 /* The heart of (S)NTP, exchange NTP packets and compute values to correct the local clock */
 int
 on_wire (
@@ -189,8 +348,6 @@ on_wire (
        char addr_buf[INET6_ADDRSTRLEN];
        register int try;
        SOCKET sock;
-       struct pkt x_pkt;
-       char *ref;
        struct key *pkt_key = NULL;
        int key_id = 0;
 
@@ -199,17 +356,12 @@ on_wire (
                get_key(key_id, &pkt_key);
        }
        for(try=0; try<5; try++) {
-               struct timeval tv_xmt, tv_dst;
-               double t21, t34, delta, offset, precision, root_dispersion;
-               int digits, error, rpktl, sw_case;
-               char *hostname = NULL, *ts_str = NULL;
-               char *log_str;
-               u_fp p_rdly, p_rdsp;
-               l_fp p_rec, p_xmt, p_ref, p_org, xmt, tmp, dst;
+               struct timeval tv_xmt;
+               struct pkt x_pkt;
+               int error, rpktl, handle_pkt_res;
 
                memset(&r_pkt, 0, sizeof rbuf);
-               memset(&x_pkt, 0, sizeof(x_pkt));
-
+               
                error = GETTIMEOFDAY(&tv_xmt, (struct timezone *)NULL);
                tv_xmt.tv_sec += JAN_1970;
 
@@ -223,144 +375,17 @@ on_wire (
                        rpktl = recv_bcst_pkt(sock, &r_pkt, sizeof rbuf, (sockaddr_u *)bcast->ai_addr);
                        closesocket(sock);
                } else {
-                       int pkt_len = LEN_PKT_NOMAC;
-                       TVTOTS(&tv_xmt, &xmt);
-                       HTONL_FP(&xmt, &(x_pkt.xmt));
-                       x_pkt.stratum = STRATUM_TO_PKT(STRATUM_UNSPEC);
-                       x_pkt.ppoll = 8;
-                       /* FIXME! Modus broadcast + adr. check -> bdr. pkt */
-                       set_li_vn_mode(&x_pkt, LEAP_NOTINSYNC, 4, 3);
-                       if (pkt_key != NULL) {
-                               int mac_size = 20; /* max room for MAC */
-                               x_pkt.exten[0] = htonl(key_id);
-                               mac_size = make_mac((char *)&x_pkt, pkt_len, mac_size, pkt_key, (char *)&x_pkt.exten[1]);
-                               if (mac_size)
-                                       pkt_len += mac_size + 4;
-                       }
+                       int pkt_len = generate_pkt(&x_pkt, &tv_xmt, key_id, pkt_key);
+
                        create_socket(&sock, (sockaddr_u *)host->ai_addr);
                        sendpkt(sock, (sockaddr_u *)host->ai_addr, &x_pkt, pkt_len);
                        rpktl = recvpkt(sock, &r_pkt, sizeof rbuf, &x_pkt);
                        closesocket(sock);
                }
 
-               if(rpktl > 0)
-                       sw_case = 1;
-               else
-                       sw_case = rpktl;
-
-               switch(sw_case) {
-               case SERVER_UNUSEABLE:
-                       return -1;
-                       break;
-
-               case PACKET_UNUSEABLE:
-                       break;
-
-               case SERVER_AUTH_FAIL:
-                       break;
-
-               case KOD_DEMOBILIZE:
-                       /* Received a DENY or RESTR KOD packet */
-                       hostname = addrinfo_to_str(host);
-                       ref = (char *)&r_pkt.refid;
-                       add_entry(hostname, ref);
-
-                       if (ENABLED_OPT(NORMALVERBOSE))
-                               printf("sntp on_wire: Received KOD packet with code: %c%c%c%c from %s, demobilizing all connections\n",
-                                      ref[0], ref[1], ref[2], ref[3],
-                                      hostname);
-
-                       log_str = emalloc(INET6_ADDRSTRLEN + 72);
-                       snprintf(log_str, INET6_ADDRSTRLEN + 72, 
-                                "Received a KOD packet with code %c%c%c%c from %s, demobilizing all connections", 
-                                ref[0], ref[1], ref[2], ref[3],
-                                hostname);
-                       log_msg(log_str, LOG_WARNING | LOG_CONS);
-                       free(log_str);
-                       break;
-
-               case KOD_RATE:
-                       /* Hmm... probably we should sleep a bit here */
-                       break;
-
-               case 1:
-                       /* Convert timestamps from network to host byte order */
-                       p_rdly = NTOHS_FP(r_pkt.rootdelay);
-                       p_rdsp = NTOHS_FP(r_pkt.rootdisp);
-                       NTOHL_FP(&r_pkt.reftime, &p_ref);
-                       NTOHL_FP(&r_pkt.org, &p_org);
-                       NTOHL_FP(&r_pkt.rec, &p_rec);
-                       NTOHL_FP(&r_pkt.xmt, &p_xmt);
-
-                       if (ENABLED_OPT(NORMALVERBOSE)) {
-                               getnameinfo(host->ai_addr, host->ai_addrlen, addr_buf, 
-                                               sizeof(addr_buf), NULL, 0, NI_NUMERICHOST);
-                               printf("sntp on_wire: Received %i bytes from %s\n", rpktl, addr_buf);
-                       }
-
-                       precision = LOGTOD(r_pkt.precision);
-#ifdef DEBUG
-                       printf("sntp precision: %f\n", precision);
-#endif /* DEBUG */
-                       for (digits = 0; (precision *= 10.) < 1.; ++digits)
-                               /* empty */ ;
-                       if (digits > 6)
-                               digits = 6;
-
-                       root_dispersion = FPTOD(p_rdsp);
-
-#ifdef DEBUG
-                       printf("sntp rootdelay: %f\n", FPTOD(p_rdly));
-                       printf("sntp rootdisp: %f\n", root_dispersion);
-
-                       pkt_output(&r_pkt, rpktl, stdout);
-
-                       printf("sntp on_wire: r_pkt.reftime:\n");
-                       l_fp_output(&(r_pkt.reftime), stdout);
-                       printf("sntp on_wire: r_pkt.org:\n");
-                       l_fp_output(&(r_pkt.org), stdout);
-                       printf("sntp on_wire: r_pkt.rec:\n");
-                       l_fp_output(&(r_pkt.rec), stdout);
-                       printf("sntp on_wire: r_pkt.rec:\n");
-                       l_fp_output_bin(&(r_pkt.rec), stdout);
-                       printf("sntp on_wire: r_pkt.rec:\n");
-                       l_fp_output_dec(&(r_pkt.rec), stdout);
-                       printf("sntp on_wire: r_pkt.xmt:\n");
-                       l_fp_output(&(r_pkt.xmt), stdout);
-#endif
-
-                       /* Compute offset etc. */
-                       GETTIMEOFDAY(&tv_dst, (struct timezone *)NULL);
-                       tv_dst.tv_sec += JAN_1970;
-                       tmp = p_rec;
-                       L_SUB(&tmp, &p_org);
-                       LFPTOD(&tmp, t21);
-                       TVTOTS(&tv_dst, &dst);
-                       tmp = p_xmt;
-                       L_SUB(&tmp, &dst);
-                       LFPTOD(&tmp, t34);
-                       offset = (t21 + t34) / 2.;
-                       delta = t21 - t34;
-
-                       if(ENABLED_OPT(NORMALVERBOSE))
-                               printf("sntp on_wire:\tt21: %.6f\t\t t34: %.6f\n\t\tdelta: %.6f\t offset: %.6f\n", 
-                                       t21, t34, delta, offset);
-
-                       ts_str = tv_to_str(&tv_dst);
-                       printf("%s ", ts_str);
-                       if(offset > 0)
-                               printf("+");
-                       printf("%.*f", digits, offset);
-                       if (root_dispersion > 0.)
-                               printf(" +/- %f secs", root_dispersion);
-                       printf("\n");
-                       free(ts_str);
-
-                       if(ENABLED_OPT(SETTOD) || ENABLED_OPT(ADJTIME))
-                               return set_time(offset); 
-
-                       return 0;
-               }
+               handle_pkt_res = handle_pkt(rpktl, &r_pkt, host);
+               if (handle_pkt_res < 1)
+                       return handle_pkt_res;
        }
 
        getnameinfo(host->ai_addr, host->ai_addrlen, addr_buf, sizeof(addr_buf), NULL, 0, NI_NUMERICHOST);
diff --git a/sntp/main.h b/sntp/main.h
new file mode 100644 (file)
index 0000000..cbdeda2
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef MAIN_H
+#define MAIN_H
+
+#include <config.h>
+#include <l_stdlib.h>
+#include <ntp_fp.h>
+#include <ntp.h>
+#include <ntp_stdlib.h>
+#include <ntp_unixtime.h>
+#include <isc/result.h>
+#include <isc/net.h>
+#include <stdio.h>
+
+#include <sntp-opts.h>
+
+#include "crypto.h"
+
+void set_li_vn_mode (struct pkt *spkt, char leap, char version, char mode); 
+int sntp_main (int argc, char **argv);
+int generate_pkt (struct pkt *x_pkt, const struct timeval *tv_xmt,
+                                 int key_id, struct key *pkt_key);
+int handle_pkt (int rpktl, struct pkt *rpkt, struct addrinfo *host);
+void offset_calculation (struct pkt *rpkt, int rpktl, struct timeval *tv_dst,
+                                                double *offset, double *precision,
+                                                double *root_dispersion);
+int on_wire (struct addrinfo *host, struct addrinfo *bcastaddr);
+int set_time (double offset);
+
+#endif /* MAIN_H */
index d1d9888704f87d001d7db0b7ef97617ba59032bd..07928083ec671bd79f5ca70aad9f261fba1f6d12 100644 (file)
@@ -281,12 +281,13 @@ recv_bcst_data (
        return recv_bytes;
 }
 
-static int
+int
 process_pkt (
        struct pkt *rpkt,
        sockaddr_u *sas,
        int pkt_len,
        int mode,
+       struct pkt *spkt,
        char * func_name
        )
 {
@@ -425,6 +426,23 @@ unusable:
                        printf("sntp %s: Server not in sync, skipping this server\n", func_name);
                return SERVER_UNUSEABLE;
        }
+
+       /*
+        * Decode the org timestamp and make sure we're getting a response
+        * to our last request, but only if we're not in broadcast mode.
+        */
+#ifdef DEBUG
+       printf("rpkt->org:\n");
+       l_fp_output(&rpkt->org, stdout);
+       printf("spkt->xmt:\n");
+       l_fp_output(&spkt->xmt, stdout);
+#endif
+       if (mode != MODE_BROADCAST && !L_ISEQU(&rpkt->org, &spkt->xmt)) {
+               if (ENABLED_OPT(NORMALVERBOSE))
+                       printf("sntp process_pkt: pkt.org and peer.xmt differ\n");
+               return PACKET_UNUSEABLE;
+       }
+
        return pkt_len;
 }
 
@@ -441,7 +459,7 @@ recv_bcst_pkt (
        if (pkt_len < 0) {
                return BROADCAST_FAILED;
        }
-       pkt_len = process_pkt(rpkt, sas, pkt_len, MODE_BROADCAST, "recv_bcst_pkt");
+       pkt_len = process_pkt(rpkt, sas, pkt_len, MODE_BROADCAST, NULL, "recv_bcst_pkt");
        return pkt_len;
 }
 
@@ -487,24 +505,8 @@ recvpkt (
        }
        pkt_len = recvdata(rsock, &sender, (char *)rpkt, rsize);
        if (pkt_len > 0)
-               pkt_len = process_pkt(rpkt, &sender, pkt_len, MODE_SERVER, "recvpkt");
-       if (pkt_len < 0)
-               return pkt_len;
-       /*
-        * Decode the org timestamp and make sure we're getting a response
-        * to our last request. 
-        */
-#ifdef DEBUG
-       printf("rpkt->org:\n");
-       l_fp_output(&rpkt->org, stdout);
-       printf("spkt->xmt:\n");
-       l_fp_output(&spkt->xmt, stdout);
-#endif
-       if (!L_ISEQU(&rpkt->org, &spkt->xmt)) {
-               if (ENABLED_OPT(NORMALVERBOSE))
-                       printf("sntp recvpkt: pkt.org and peer.xmt differ\n");
-               return PACKET_UNUSEABLE;
-       }
+               pkt_len = process_pkt(rpkt, &sender, pkt_len, MODE_SERVER, spkt, "recvpkt");
+
        return pkt_len;
 }
 
index d09531b490fec1530f64d1e69e8ad7deaf8ec86e..8cb72c44d7a5133894c8db33868741586b7fdfb0 100644 (file)
 #include "sntp-opts.h" 
 #include "utilities.h"
 
+/* 
+ * for 4.2.6 only define AUTOKEY if OPENSSL, so that backported 4.2.7
+ * references to AUTOKEY work -- in 4.2.7 AUTOKEY is independent of OPENSSL
+ */
+#ifdef OPENSSL
+#define AUTOKEY
+#endif
+
 /* FIXME To be replaced by the constants in ntp.h */
 #define SERVER_UNUSEABLE -1 /* Skip server */
 #define PACKET_UNUSEABLE -2 /* Discard packet and try to get a useable packet again if not tried too often */
@@ -50,6 +58,8 @@ int recv_bcst_data (SOCKET rsock, char *rdata, int rdata_len, sockaddr_u *sas, s
 
 int recv_bcst_pkt (SOCKET rsock, struct pkt *rpkt, unsigned int rsize, sockaddr_u *sas);
 
+int process_pkt (struct pkt *rpkt, sockaddr_u *sas,    int pkt_len, int mode, struct pkt *spkt, char * func_name);
+
 /* Shortened peer structure. Not absolutely necessary yet */
 struct speer {
        struct speer *next;
@@ -71,7 +81,7 @@ struct speer {
        l_fp reftime;
        keyid_t keyid;
 
-#ifdef OPENSSL
+#ifdef AUTOKEY
 #define clear_to_zero opcode
        u_int32 opcode;         /* last request opcode */
        associd_t assoc;        /* peer association ID */
@@ -99,9 +109,9 @@ struct speer {
        int     keynumber;      /* current key number */
        struct value encrypt;   /* send encrypt values */
        struct value sndval;    /* send autokey values */
-#else /* OPENSSL */
+#else  /* !AUTOKEY follows */
 #define clear_to_zero status
-#endif /* OPENSSL */
+#endif /* !AUTOKEY */
        
        l_fp    rec;            /* receive time stamp */
        l_fp    xmt;            /* transmit time stamp */
diff --git a/sntp/sntp.c b/sntp/sntp.c
new file mode 100644 (file)
index 0000000..28101a0
--- /dev/null
@@ -0,0 +1,13 @@
+#include "main.h"
+
+char *progname = "sntp";       /* for msyslog */
+volatile int debug;
+
+int 
+main (
+       int argc,
+       char **argv
+       ) 
+{
+       return sntp_main(argc, argv);
+}
index f8588cff232b35f8babd3a2680721dac6c8ca11b..6180ecb7ac90f9eb549747b26a03fff2d4bd6edc 100644 (file)
@@ -1,3 +1,4 @@
+#include <config.h>
 #include "utilities.h"
 
 /* Display a NTP packet in hex with leading address offset 
@@ -110,15 +111,15 @@ l_fp_output_dec (
  */
 char *
 addrinfo_to_str (
-               struct addrinfo *addr
-               )
+       struct addrinfo *addr
+       )
 {
-       char *buf = (char *) emalloc(sizeof(char) * INET6_ADDRSTRLEN);
-
-       getnameinfo(addr->ai_addr, addr->ai_addrlen, buf, 
-                       INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
+       sockaddr_u      s;
+       
+       memset(&s, 0, sizeof(s));
+       memcpy(&s, addr->ai_addr, min(sizeof(s), addr->ai_addrlen));
 
-       return buf;
+       return ss_to_str(&s);
 }
 
 /* Convert a sockaddr_u to a string containing the address in
@@ -128,14 +129,13 @@ addrinfo_to_str (
  */
 char *
 ss_to_str (
-               sockaddr_u *saddr
-               )
+       sockaddr_u *saddr
+       )
 {
-       char *buf = (char *) emalloc(sizeof(char) * INET6_ADDRSTRLEN);
-
-       getnameinfo(&saddr->sa, SOCKLEN(saddr), buf,
-                       INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
-
+       char *  buf;
+       
+       buf = emalloc(INET6_ADDRSTRLEN);
+       strncpy(buf, stoa(saddr), INET6_ADDRSTRLEN);
 
        return buf;
 }