Browse Source

in client_addr_init() and client_nextaddr(), do not set up the socket and

connect it, instead leave it at -1.
in client_query, set up and connect the socket if it is -1.
and, the real reason for this change: handle connect failures gracefully
ok otto
OPENBSD_3_7
henning 20 years ago
parent
commit
abc9700cfb
1 changed files with 18 additions and 16 deletions
  1. +18
    -16
      src/usr.sbin/ntpd/client.c

+ 18
- 16
src/usr.sbin/ntpd/client.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: client.c,v 1.36 2004/09/30 10:19:43 henning Exp $ */
/* $OpenBSD: client.c,v 1.37 2004/10/05 11:23:28 henning Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -83,15 +83,7 @@ client_addr_init(struct ntp_peer *p)
} }
} }
if (p->addr != NULL) {
if ((p->query->fd = socket(p->addr->ss.ss_family,
SOCK_DGRAM, 0)) == -1)
fatal("client_query socket");
if (connect(p->query->fd, (struct sockaddr *)&p->addr->ss,
p->addr->ss.ss_len) == -1)
fatal("client_query connect");
}
p->query->fd = -1;
set_next(p, 0); set_next(p, 0);
return (0); return (0);
@ -111,12 +103,6 @@ client_nextaddr(struct ntp_peer *p)
if ((p->addr = p->addr->next) == NULL) if ((p->addr = p->addr->next) == NULL)
p->addr = p->addr_head.a; p->addr = p->addr_head.a;
if ((p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM, 0)) == -1)
fatal("client_query socket");
if (connect(p->query->fd, (struct sockaddr *)&p->addr->ss,
p->addr->ss.ss_len) == -1)
fatal("client_query connect");
p->shift = 0; p->shift = 0;
p->trustlevel = TRUSTLEVEL_PATHETIC; p->trustlevel = TRUSTLEVEL_PATHETIC;
@ -131,6 +117,22 @@ client_query(struct ntp_peer *p)
return (-1); return (-1);
} }
if (p->query->fd == -1) {
if ((p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM,
0)) == -1)
fatal("client_query socket");
if (connect(p->query->fd, (struct sockaddr *)&p->addr->ss,
p->addr->ss.ss_len) == -1) {
if (errno == ECONNREFUSED || errno == ENETUNREACH ||
errno == EHOSTUNREACH) {
client_nextaddr(p);
set_next(p, INTERVAL_QUERY_PATHETIC);
return (-1);
} else
fatal("client_query connect");
}
}
/* /*
* Send out a random 64-bit number as our transmit time. The NTP * Send out a random 64-bit number as our transmit time. The NTP
* server will copy said number into the originate field on the * server will copy said number into the originate field on the


Loading…
Cancel
Save