From: Dave Hart Date: Tue, 12 May 2009 00:58:59 +0000 (+0000) Subject: [Bug 1183] COM port support should extend past COM3 X-Git-Tag: NTP_4_2_5P175~5^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2c4adc0ec8c25611cf45353260bea7b80b84b34;p=thirdparty%2Fntp.git [Bug 1183] COM port support should extend past COM3 bk: 4a08c9d3lW125gGdeyRNvk4mUlwzYw --- diff --git a/ChangeLog b/ChangeLog index 533eeee8a..be3604bbe 100644 --- 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 * Stale leapsecond file fixes from Dave Mills. (4.2.5p173) 2009/05/08 Released by Harlan Stenn diff --git a/libisc/sockaddr.c b/libisc/sockaddr.c index 33d7a1b91..be8d65988 100644 --- a/libisc/sockaddr.c +++ b/libisc/sockaddr.c @@ -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); diff --git a/ntpd/ntp_control.c b/ntpd/ntp_control.c index c33fcf74e..abad06247 100644 --- a/ntpd/ntp_control.c +++ b/ntpd/ntp_control.c @@ -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) diff --git a/ntpd/ntp_peer.c b/ntpd/ntp_peer.c index 3261a4f54..b3132f3b2 100644 --- a/ntpd/ntp_peer.c +++ b/ntpd/ntp_peer.c @@ -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) { diff --git a/ntpd/ntp_refclock.c b/ntpd/ntp_refclock.c index c28660dab..9ab311c0e 100644 --- a/ntpd/ntp_refclock.c +++ b/ntpd/ntp_refclock.c @@ -41,37 +41,32 @@ /* * 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 diff --git a/ntpd/ntp_scanner.c b/ntpd/ntp_scanner.c index a18d0ccab..24add2bda 100644 --- a/ntpd/ntp_scanner.c +++ b/ntpd/ntp_scanner.c @@ -656,5 +656,4 @@ yylex() return create_string_token(yytext); } } - return 1; } diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index d37448766..d2c4ccd1d 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -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 { diff --git a/ports/winnt/include/config.h b/ports/winnt/include/config.h index 0094842de..40cbce905 100644 --- a/ports/winnt/include/config.h +++ b/ports/winnt/include/config.h @@ -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 diff --git a/ports/winnt/ntpd/win32_io.c b/ports/winnt/ntpd/win32_io.c index c8718464a..b255b79ac 100644 --- a/ports/winnt/ntpd/win32_io.c +++ b/ports/winnt/ntpd/win32_io.c @@ -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