]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1183] COM port support should extend past COM3
authorDave Hart <hart@ntp.org>
Tue, 12 May 2009 00:58:59 +0000 (00:58 +0000)
committerDave Hart <hart@ntp.org>
Tue, 12 May 2009 00:58:59 +0000 (00:58 +0000)
bk: 4a08c9d3lW125gGdeyRNvk4mUlwzYw

ChangeLog
libisc/sockaddr.c
ntpd/ntp_control.c
ntpd/ntp_peer.c
ntpd/ntp_refclock.c
ntpd/ntp_scanner.c
ntpd/ntpd.c
ports/winnt/include/config.h
ports/winnt/ntpd/win32_io.c

index 533eeee8a2979af9b86edb37b046ec47cf88cef2..be3604bbe8568e5bf625091e82cf4d925b63960d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+* [Bug 1183] COM port support should extend past COM3
 (4.2.5p174) 2009/05/09 Released by Harlan Stenn <stenn@ntp.org>
 * Stale leapsecond file fixes from Dave Mills.
 (4.2.5p173) 2009/05/08 Released by Harlan Stenn <stenn@ntp.org>
index 33d7a1b9178a7561816384c4d609f241764398fa..be8d6598864f10eca723757424805c77762f859c 100644 (file)
@@ -371,7 +371,7 @@ isc_sockaddr_fromnetaddr(isc_sockaddr_t *sockaddr, const isc_netaddr_t *na,
                    in_port_t port)
 {
        memset(sockaddr, 0, sizeof(*sockaddr));
-       sockaddr->type.sin.sin_family = na->family;
+       sockaddr->type.sin.sin_family = (short)na->family;
        switch (na->family) {
        case AF_INET:
                sockaddr->length = sizeof(sockaddr->type.sin);
index c33fcf74eafeae9e22f99440b41fb3b0ad975a67..abad0624738268c88a8f4d06d9486445b1e9160d 100644 (file)
@@ -2814,7 +2814,7 @@ report_event(
                char    *src;
                u_char  errlast;
 
-               errlast = err & ~PEER_EVENT; 
+               errlast = (u_char)err & ~PEER_EVENT; 
                if (peer->last_event == errlast)
                        peer->num_events = 0;
                if (peer->num_events >= CTL_PEER_MAXEVENTS)
index 3261a4f54fcf623061426edaa88062d4b9457dfb..b3132f3b290cd0cc344bb406570fe3afcc855238 100644 (file)
@@ -196,19 +196,16 @@ findexistingpeer(
         * start_peer is included so we can locate instances of the
         * same peer through different interfaces in the hash table.
         */
-       if (start_peer == 0)
+       if (NULL == start_peer)
                peer = peer_hash[NTP_HASH_ADDR(addr)];
        else
                peer = start_peer->next;
        
-       while (peer != 0) {
+       while (NULL != peer) {
                if (SOCKCMP(addr, &peer->srcadr)
-                   && NSRCPORT(addr) == NSRCPORT(&peer->srcadr)) {
-                       if (mode == -1)
-                               return (peer);
-                       else if (peer->hmode == mode)
-                               break;
-               }
+                   && NSRCPORT(addr) == NSRCPORT(&peer->srcadr)
+                   && (-1 == mode || peer->hmode == mode))
+                       break;
                peer = peer->next;
        }
        return (peer);
@@ -820,8 +817,8 @@ newpeer(
            cast_flags));
        peer->hmode = (u_char)hmode;
        peer->version = (u_char)version;
-       peer->minpoll = max(ntp_minpoll, minpoll);
-       peer->maxpoll = min(NTP_MAXPOLL, maxpoll);
+       peer->minpoll = (u_char)max(ntp_minpoll, minpoll);
+       peer->maxpoll = (u_char)min(NTP_MAXPOLL, maxpoll);
        peer->flags = flags;
 #ifdef DEBUG
        if (debug > 2) {
index c28660dab3c0ab848cc2458fe21f37814679b9d2..9ab311c0e282a7ad3e229610032f2f3c40776628 100644 (file)
 
 /*
  * Reference clock support is provided here by maintaining the fiction
- * that the clock is actually a peer. As no packets are exchanged with a
- * reference clock, however, we replace the transmit, receive and packet
- * procedures with separate code to simulate them. Routines
+ * that the clock is actually a peer.  As no packets are exchanged with
+ * a reference clock, however, we replace the transmit, receive and
+ * packet procedures with separate code to simulate them.  Routines
  * refclock_transmit() and refclock_receive() maintain the peer
  * variables in a state analogous to an actual peer and pass reference
- * clock data on through the filters. Routines refclock_peer() and
+ * clock data on through the filters.  Routines refclock_peer() and
  * refclock_unpeer() are called to initialize and terminate reference
- * clock associations. A set of utility routines is included to open
+ * clock associations.  A set of utility routines is included to open
  * serial devices, process sample data, edit input lines to extract
- * embedded timestamps and to peform various debugging functions.
+ * embedded timestamps and to perform various debugging functions.
  *
  * The main interface used by these routines is the refclockproc
- * structure, which contains for most drivers the decimal equivalants of
- * the year, day, month, hour, second and millisecond/microsecond
- * decoded from the ASCII timecode. Additional information includes the
- * receive timestamp, exception report, statistics tallies, etc. In
- * addition, there may be a driver-specific unit structure used for
+ * structure, which contains for most drivers the decimal equivalants
+ * of the year, day, month, hour, second and millisecond/microsecond
+ * decoded from the ASCII timecode.  Additional information includes
+ * the receive timestamp, exception report, statistics tallies, etc. 
+ * In addition, there may be a driver-specific unit structure used for
  * local control of the device.
  *
  * The support routines are passed a pointer to the peer structure,
- * which is used for all peer-specific processing and contains a pointer
- * to the refclockproc structure, which in turn containes a pointer to
- * the unit structure, if used. The peer structure is identified by an
- * interface address in the dotted quad form 127.127.t.u (for now only
- * IPv4 addresses are used, so we need to be sure the address is it),
- * where t is the clock type and u the unit. Some legacy drivers derive
- * the refclockproc structure pointer from the table
- * typeunit[type][unit]. This interface is strongly discouraged and may
- * be abandoned in future.
+ * which is used for all peer-specific processing and contains a
+ * pointer to the refclockproc structure, which in turn contains a
+ * pointer to the unit structure, if used.  The peer structure is 
+ * identified by an interface address in the dotted quad form 
+ * 127.127.t.u, where t is the clock type and u the unit.
  */
-#define MAXUNIT        4       /* max units */
 #define FUDGEFAC       .1      /* fudge correction factor */
 #define LF             0x0a    /* ASCII LF */
 
@@ -81,13 +76,6 @@ int  fdpps;                  /* ppsclock legacy */
 
 int    cal_enable;             /* enable refclock calibrate */
 
-/*
- * Type/unit peer index. Used to find the peer structure for control and
- * debugging. When all clock drivers have been converted to new style,
- * this dissapears.
- */
-static struct peer *typeunit[REFCLK_MAX + 1][MAXUNIT];
-
 /*
  * Forward declarations
  */
@@ -120,30 +108,30 @@ refclock_report(
 
        switch (code) {
 
-               case CEVNT_TIMEOUT:
-                       pp->noreply++;
-                       break;
+       case CEVNT_TIMEOUT:
+               pp->noreply++;
+               break;
 
-               case CEVNT_BADREPLY:
-                       pp->badformat++;
-                       break;
+       case CEVNT_BADREPLY:
+               pp->badformat++;
+               break;
 
-               case CEVNT_FAULT:
-                       break;
+       case CEVNT_FAULT:
+               break;
 
-               case CEVNT_BADDATE:
-               case CEVNT_BADTIME:
-                       pp->baddata++;
-                       break;
+       case CEVNT_BADDATE:
+       case CEVNT_BADTIME:
+               pp->baddata++;
+               break;
 
-               default:
-                       /* ignore others */
-                       break;
+       default:
+               /* ignore others */
+               break;
        }
        if (pp->lastevent < 15)
                pp->lastevent++;
        if (pp->currentstatus != code) {
-               pp->currentstatus = code;
+               pp->currentstatus = (u_char)code;
                report_event(PEVNT_CLOCK, peer, ceventstr(code));
        }
 }
@@ -159,14 +147,11 @@ refclock_report(
 void
 init_refclock(void)
 {
-       int i, j;
+       int i;
 
-       for (i = 0; i < (int)num_refclock_conf; i++) {
+       for (i = 0; i < (int)num_refclock_conf; i++)
                if (refclock_conf[i]->clock_init != noentry)
                        (refclock_conf[i]->clock_init)();
-               for (j = 0; j < MAXUNIT; j++)
-                       typeunit[i][j] = 0;
-       }
 }
 
 
@@ -197,10 +182,10 @@ refclock_newpeer(
         */
        if (peer->srcadr.ss_family != AF_INET) {
                msyslog(LOG_ERR,
-                      "refclock_newpeer: clock address %s invalid, address family not implemented for refclock",
-                        stoa(&peer->srcadr));
-                return (0);
-        }
+                       "refclock_newpeer: clock address %s invalid, address family not implemented for refclock",
+                       stoa(&peer->srcadr));
+               return (0);
+       }
        if (!ISREFCLOCKADR(&peer->srcadr)) {
                msyslog(LOG_ERR,
                        "refclock_newpeer: clock address %s invalid",
@@ -209,7 +194,7 @@ refclock_newpeer(
        }
        clktype = (u_char)REFCLOCKTYPE(&peer->srcadr);
        unit = REFCLOCKUNIT(&peer->srcadr);
-       if (clktype >= num_refclock_conf || unit >= MAXUNIT ||
+       if (clktype >= num_refclock_conf ||
                refclock_conf[clktype]->clock_start == noentry) {
                msyslog(LOG_ERR,
                        "refclock_newpeer: clock type %d invalid\n",
@@ -220,12 +205,8 @@ refclock_newpeer(
        /*
         * Allocate and initialize interface structure
         */
-       pp = (struct refclockproc *)emalloc(sizeof(struct refclockproc));
-       if (pp == NULL)
-               return (0);
-
-       memset((char *)pp, 0, sizeof(struct refclockproc));
-       typeunit[clktype][unit] = peer;
+       pp = emalloc(sizeof(*pp));
+       memset(pp, 0, sizeof(*pp));
        peer->procptr = pp;
 
        /*
@@ -281,7 +262,7 @@ refclock_unpeer(
         * Wiggle the driver to release its resources, then give back
         * the interface structure.
         */
-       if (!peer->procptr)
+       if (NULL == peer->procptr)
                return;
 
        clktype = peer->refclktype;
@@ -289,7 +270,7 @@ refclock_unpeer(
        if (refclock_conf[clktype]->clock_shutdown != noentry)
                (refclock_conf[clktype]->clock_shutdown)(unit, peer);
        free(peer->procptr);
-       peer->procptr = 0;
+       peer->procptr = NULL;
 }
 
 
@@ -1060,14 +1041,10 @@ refclock_control(
 
        clktype = (u_char)REFCLOCKTYPE(srcadr);
        unit = REFCLOCKUNIT(srcadr);
-       if (clktype >= num_refclock_conf || unit >= MAXUNIT)
-               return;
 
-       peer = typeunit[clktype][unit];
-       if (peer == NULL)
-               return;
+       peer = findexistingpeer(srcadr, NULL, -1);
 
-       if (peer->procptr == NULL)
+       if (NULL == peer || NULL == peer->procptr)
                return;
 
        pp = peer->procptr;
@@ -1124,7 +1101,7 @@ refclock_control(
                out->currentstatus = pp->currentstatus;
                out->type = pp->type;
                out->clockdesc = pp->clockdesc;
-               out->lencode = pp->lencode;
+               out->lencode = (u_short)pp->lencode;
                out->p_lastcode = pp->a_lastcode;
        }
 
@@ -1151,9 +1128,9 @@ refclock_buginfo(
 {
        struct peer *peer;
        struct refclockproc *pp;
-       u_char clktype;
+       int clktype;
        int unit;
-       int i;
+       unsigned u;
 
        /*
         * Check for valid address and peer structure
@@ -1166,11 +1143,10 @@ refclock_buginfo(
 
        clktype = (u_char) REFCLOCKTYPE(srcadr);
        unit = REFCLOCKUNIT(srcadr);
-       if (clktype >= num_refclock_conf || unit >= MAXUNIT)
-               return;
 
-       peer = typeunit[clktype][unit];
-       if (peer == NULL)
+       peer = findexistingpeer(srcadr, NULL, -1);
+
+       if (NULL == peer || NULL == peer->procptr)
                return;
 
        pp = peer->procptr;
@@ -1191,8 +1167,8 @@ refclock_buginfo(
        bug->stimes = 0xfffffffc;
        bug->times[0] = pp->lastref;
        bug->times[1] = pp->lastrec;
-       for (i = 2; i < (int)bug->ntimes; i++)
-               DTOLFP(pp->filter[i - 2], &bug->times[i]);
+       for (u = 2; u < bug->ntimes; u++)
+               DTOLFP(pp->filter[u - 2], &bug->times[u]);
 
        /*
         * Give the stuff to the clock
index a18d0ccabe3046a15dc2294b050c1f78abae240b..24add2bdadb02857cc220224783b3509a9edcadc 100644 (file)
@@ -656,5 +656,4 @@ yylex()
                        return create_string_token(yytext);
                }
        }
-       return 1;
 }
index d37448766c18362285631d456185d9b57b6efa74..d2c4ccd1d43b051fff86976b4e944d58b93c56eb 100644 (file)
@@ -1081,10 +1081,10 @@ getgroup:
                         */
                        timer();
                        was_alarmed = 0;
-                        BLOCK_IO_AND_ALARM();
+                       BLOCK_IO_AND_ALARM();
                }
 
-#endif /* HAVE_IO_COMPLETION_PORT */
+#endif /* HAVE_IO_COMPLETION_PORT */
 
 #ifdef DEBUG_TIMING
                {
index 0094842de51298f38409339f66a0b06e0ceb19f8..40cbce9058ba28fc5a7155c820b61a871ffbd9ac 100644 (file)
@@ -265,7 +265,7 @@ char *NTstrerror(int errnum);
 # define CLOCK_HOPF_PCI                /* device 39, hopf DCF77/GPS PCI-Bus receiver  */
 # define CLOCK_NMEA
 # define CLOCK_PALISADE                /* from ntpd.mak */
-# define CLOCK_DUMBCLOCK
+/* # define CLOCK_DUMBCLOCK */ /* refclock_dumbclock.c needs work to open COMx: */
 # define CLOCK_TRIMBLEDC
 # define CLOCK_TRIMTSIP 1
 # define CLOCK_JUPITER
index c8718464a7b384806b81535731fa3e95d084e39d..b255b79ace60c3e9c2a2a6eda60136053e79d57a 100644 (file)
@@ -11,7 +11,7 @@
 #include "ntp_refclock.h"
 #include "win32_io.h"
 
-#define MAX_SERIAL 16  /* COM1-COM16 */
+#define MAX_SERIAL 255 /* COM1: - COM255: */
 
 
 /*
@@ -25,7 +25,8 @@ HANDLE common_serial_open(
        char *dev
        )
 {
-       static HANDLE SerialHandles[MAX_SERIAL+1] = {0};
+       /* SerialHandles[0] is unused, hence MAX_SERIAL + 1 */
+       static HANDLE SerialHandles[MAX_SERIAL + 1] = {0};
        HANDLE RetHandle;
        int unit;
 
@@ -83,8 +84,9 @@ int pps_open(
        /*
         * there never is a COM0: but this is the ntp convention
         */
-       _snprintf(windev, sizeof(windev)-1, "COM%d:", unit);
-       windev[sizeof(windev)-1] = 0; 
+       _snprintf(windev, sizeof(windev) - 1, "COM%d:", unit);
+       /* _snprintf doesn't always terminate */
+       windev[sizeof(windev) - 1] = 0; 
 
        /*
         * open communication port handle