aboutsummaryrefslogtreecommitdiff
path: root/ntpd/refclock_hpgps.c
diff options
context:
space:
mode:
Diffstat (limited to 'ntpd/refclock_hpgps.c')
-rw-r--r--ntpd/refclock_hpgps.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/ntpd/refclock_hpgps.c b/ntpd/refclock_hpgps.c
index 5867a1d7b278..0b45fc74f2f1 100644
--- a/ntpd/refclock_hpgps.c
+++ b/ntpd/refclock_hpgps.c
@@ -156,6 +156,7 @@ hpgps_start(
register struct hpgpsunit *up;
struct refclockproc *pp;
int fd;
+ int speed, ldisc;
char device[20];
/*
@@ -163,23 +164,23 @@ hpgps_start(
* Default is HP 58503A, mode arg selects HP Z3801A
*/
snprintf(device, sizeof(device), DEVICE, unit);
+ ldisc = LDISC_CLK;
+ speed = SPEED232;
/* mode parameter to server config line shares ttl slot */
- if ((peer->ttl == 1)) {
- if (!(fd = refclock_open(device, SPEED232Z,
- LDISC_CLK | LDISC_7O1)))
- return (0);
- } else {
- if (!(fd = refclock_open(device, SPEED232, LDISC_CLK)))
- return (0);
+ if (1 == peer->ttl) {
+ ldisc |= LDISC_7O1;
+ speed = SPEED232Z;
}
+ fd = refclock_open(device, speed, ldisc);
+ if (fd <= 0)
+ return (0);
/*
* Allocate and initialize unit structure
*/
- up = emalloc(sizeof(*up));
- memset(up, 0, sizeof(*up));
+ up = emalloc_zero(sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = hpgps_receive;
- pp->io.srcclock = (caddr_t)peer;
+ pp->io.srcclock = peer;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
@@ -188,7 +189,7 @@ hpgps_start(
free(up);
return (0);
}
- pp->unitptr = (caddr_t)up;
+ pp->unitptr = up;
/*
* Initialize miscellaneous variables
@@ -228,7 +229,7 @@ hpgps_shutdown(
struct refclockproc *pp;
pp = peer->procptr;
- up = (struct hpgpsunit *)pp->unitptr;
+ up = pp->unitptr;
if (-1 != pp->io.fd)
io_closeclock(&pp->io);
if (NULL != up)
@@ -265,9 +266,9 @@ hpgps_receive(
/*
* Initialize pointers and read the receiver response
*/
- peer = (struct peer *)rbufp->recv_srcclock;
+ peer = rbufp->recv_peer;
pp = peer->procptr;
- up = (struct hpgpsunit *)pp->unitptr;
+ up = pp->unitptr;
*pp->a_lastcode = '\0';
pp->lencode = refclock_gtlin(rbufp, pp->a_lastcode, BMAX, &trtmp);
@@ -300,7 +301,7 @@ hpgps_receive(
if (up->linecnt-- > 0) {
if ((int)(pp->lencode + 2) <= (SMAX - (up->lastptr - up->statscrn))) {
*up->lastptr++ = '\n';
- (void)strcpy(up->lastptr, pp->a_lastcode);
+ memcpy(up->lastptr, pp->a_lastcode, pp->lencode);
up->lastptr += pp->lencode;
}
if (up->linecnt == 0)
@@ -333,7 +334,7 @@ hpgps_receive(
*
*/
- (void)strcpy(prompt,pp->a_lastcode);
+ strlcpy(prompt, pp->a_lastcode, sizeof(prompt));
tcp = strrchr(pp->a_lastcode,'>');
if (tcp == NULL)
tcp = pp->a_lastcode;
@@ -608,7 +609,7 @@ hpgps_poll(
* declare a timeout and keep going.
*/
pp = peer->procptr;
- up = (struct hpgpsunit *)pp->unitptr;
+ up = pp->unitptr;
if (up->pollcnt == 0)
refclock_report(peer, CEVNT_TIMEOUT);
else