summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-09-15 01:11:13 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-09-15 01:11:13 +0000
commitba022848411fcbefaf00cce7b34616b58e69e1c2 (patch)
tree7151b386bb8873ebf294136812a1b4a56add97f6
parent73e2c7379e6368ece8dd1c7caa621e76ebec903b (diff)
KNF
-rw-r--r--usr.sbin/rdate/ntp.c63
1 files changed, 30 insertions, 33 deletions
diff --git a/usr.sbin/rdate/ntp.c b/usr.sbin/rdate/ntp.c
index 82bfee6073b..3d2a7a47810 100644
--- a/usr.sbin/rdate/ntp.c
+++ b/usr.sbin/rdate/ntp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntp.c,v 1.24 2004/09/15 01:05:09 henning Exp $ */
+/* $OpenBSD: ntp.c,v 1.25 2004/09/15 01:11:12 henning Exp $ */
/*
* Copyright (c) 1996, 1997 by N.M. Maclaren. All rights reserved.
@@ -162,12 +162,11 @@ ntp_client(const char *hostname, int family, struct timeval *new,
freeaddrinfo(res0);
#ifdef DEBUG
- fprintf(stderr,"Correction: %.6f +/- %.6f\n", offset,error);
+ fprintf(stderr, "Correction: %.6f +/- %.6f\n", offset, error);
#endif
- if (accept < 1) {
+ if (accept < 1)
errx(1, "Unable to get a reasonable time estimate");
- }
create_timeval(offset, new, adjust);
}
@@ -188,7 +187,7 @@ sync_ntp(int fd, const struct sockaddr *peer, double *offset, double *error)
if (connect(fd, peer, SA_LEN(peer)) < 0) {
warn("Failed to connect to server");
- return -1;
+ return (-1);
}
while (accepts < MAX_QUERIES && attempts < 2 * MAX_QUERIES) {
@@ -196,16 +195,16 @@ sync_ntp(int fd, const struct sockaddr *peer, double *offset, double *error)
if (current_time(JAN_1970) > deadline) {
warnx("Not enough valid responses received in time");
- return -1;
+ return (-1);
}
if (write_packet(fd, &data) < 0)
- return -1;
+ return (-1);
ret = read_packet(fd, &data, &x, &y);
if (ret < 0)
- return -1;
+ return (-1);
else if (ret > 0) {
#ifdef DEBUG
print_packet(&data);
@@ -213,15 +212,14 @@ sync_ntp(int fd, const struct sockaddr *peer, double *offset, double *error)
if (++rejects > MAX_QUERIES) {
warnx("Too many bad or lost packets");
- return -1;
+ return (-1);
} else
continue;
} else
++accepts;
#ifdef DEBUG
- fprintf(stderr,"Offset: %.6f +/- %.6f\n",
- x, y);
+ fprintf(stderr, "Offset: %.6f +/- %.6f\n", x, y);
#endif
if ((a = x - *offset) < 0.0)
@@ -235,19 +233,19 @@ sync_ntp(int fd, const struct sockaddr *peer, double *offset, double *error)
}
#ifdef DEBUG
- fprintf(stderr,"Best: %.6f +/- %.6f\n", *offset, *error);
+ fprintf(stderr, "Best: %.6f +/- %.6f\n", *offset, *error);
#endif
if (a > b) {
warnx("Inconsistent times received from NTP server");
- return -1;
+ return (-1);
}
if (*error <= minerr)
break;
}
- return accepts;
+ return (accepts);
}
/* Send out NTP packet. */
@@ -287,10 +285,10 @@ write_packet(int fd, struct ntp_data *data)
if (length != sizeof(packet)) {
warn("Unable to send NTP packet to server");
- return -1;
+ return (-1);
}
- return 0;
+ return (0);
}
/*
@@ -308,8 +306,7 @@ read_packet(int fd, struct ntp_data *data, double *off, double *error)
int length, r;
fd_set *rfds;
- rfds = (fd_set *)calloc(howmany(fd + 1, NFDBITS), sizeof(fd_mask));
-
+ rfds = calloc(howmany(fd + 1, NFDBITS), sizeof(fd_mask));
if (rfds == NULL)
err(1, "calloc");
@@ -328,14 +325,12 @@ retry:
warn("select");
free(rfds);
-
- return r;
+ return (r);
}
if (r != 1 || !FD_ISSET(fd, rfds)) {
free(rfds);
-
- return 1;
+ return (1);
}
free(rfds);
@@ -344,40 +339,40 @@ retry:
if (length < 0) {
warn("Unable to receive NTP packet from server");
- return -1;
+ return (-1);
}
if (length < NTP_PACKET_MIN || length > NTP_PACKET_MAX) {
warnx("Invalid NTP packet size, packet rejected");
- return 1;
+ return (1);
}
unpack_ntp(data, receive);
if (data->recvck != data->xmitck) {
warnx("Invalid cookie received, packet rejected");
- return 1;
+ return (1);
}
if (data->version != NTP_VERSION) {
warnx("Received different NTP version than sent,"
"packet rejected");
- return 1;
+ return (1);
}
if (data->mode != NTP_MODE_SERVER) {
warnx("Invalid NTP server mode, packet rejected");
- return 1;
+ return (1);
}
if (data->stratum > NTP_STRATUM_MAX) {
warnx("Invalid stratum received, packet rejected");
- return 1;
+ return (1);
}
if (data->transmit == 0.0) {
warnx("Server clock invalid, packet rejected");
- return 1;
+ return (1);
}
x = data->receive - data->originate;
@@ -391,7 +386,7 @@ retry:
if (x > *error)
*error = x;
- return 0;
+ return (0);
}
/*
@@ -414,11 +409,13 @@ unpack_ntp(struct ntp_data *data, u_char *packet)
for (i = 0, d = 0.0; i < 8; ++i)
d = 256.0*d+packet[NTP_RECEIVE+i];
- data->receive = d/NTP_SCALE;
+
+ data->receive = d / NTP_SCALE;
for (i = 0, d = 0.0; i < 8; ++i)
d = 256.0*d+packet[NTP_TRANSMIT+i];
- data->transmit = d/NTP_SCALE;
+
+ data->transmit = d / NTP_SCALE;
/* See write_packet for why this isn't an endian problem. */
data->recvck = *(u_int64_t *)(packet + NTP_ORIGINATE);
@@ -446,7 +443,7 @@ current_time(double offset)
if (corrleaps)
ntpleaps_sub(&t);
- return offset + TAI64_TO_SEC(t) + 1.0e-6 * current.tv_usec;
+ return (offset + TAI64_TO_SEC(t) + 1.0e-6 * current.tv_usec);
}
/*