diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-02 23:46:25 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-02 23:46:25 +0100 |
commit | 7cb1d6ccf36eccb294bd26e1c6da6866e7fc0ab7 (patch) | |
tree | 6fb1df49aac9e14f24acc86c66a2d2b47f63a908 /networking/ntpd.c | |
parent | 907647fb1540cb5303d90f2316dbfe89120db39c (diff) | |
download | busybox-w32-7cb1d6ccf36eccb294bd26e1c6da6866e7fc0ab7.tar.gz busybox-w32-7cb1d6ccf36eccb294bd26e1c6da6866e7fc0ab7.tar.bz2 busybox-w32-7cb1d6ccf36eccb294bd26e1c6da6866e7fc0ab7.zip |
ntpd: try to avoid DNS requests *during* NTP roundtrip. +23 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/ntpd.c')
-rw-r--r-- | networking/ntpd.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c index 3bca69a4c..375f009a6 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -166,6 +166,15 @@ set_next(ntp_peer_t *p, unsigned t) | |||
166 | p->next_action_time = time(NULL) + t; | 166 | p->next_action_time = time(NULL) + t; |
167 | } | 167 | } |
168 | 168 | ||
169 | static len_and_sockaddr* | ||
170 | resolve_hostname(ntp_peer_t *p) | ||
171 | { | ||
172 | p->lsa = host2sockaddr(p->hostname, 123); | ||
173 | if (p->lsa) | ||
174 | p->dotted = xmalloc_sockaddr2dotted_noport(&p->lsa->u.sa); | ||
175 | return p->lsa; | ||
176 | } | ||
177 | |||
169 | static void | 178 | static void |
170 | add_peers(char *s) | 179 | add_peers(char *s) |
171 | { | 180 | { |
@@ -174,6 +183,7 @@ add_peers(char *s) | |||
174 | p = xzalloc(sizeof(*p)); | 183 | p = xzalloc(sizeof(*p)); |
175 | p->hostname = s; | 184 | p->hostname = s; |
176 | p->dotted = s; | 185 | p->dotted = s; |
186 | resolve_hostname(p); | ||
177 | p->fd = -1; | 187 | p->fd = -1; |
178 | p->msg.m_status = MODE_CLIENT | (NTP_VERSION << 3); | 188 | p->msg.m_status = MODE_CLIENT | (NTP_VERSION << 3); |
179 | p->trustlevel = TRUSTLEVEL_PATHETIC; | 189 | p->trustlevel = TRUSTLEVEL_PATHETIC; |
@@ -300,12 +310,10 @@ send_query_to_peer(ntp_peer_t *p) | |||
300 | //TODO: big ntpd uses all IPs, not just 1st, do we need to mimic that? | 310 | //TODO: big ntpd uses all IPs, not just 1st, do we need to mimic that? |
301 | //TODO: periodically re-resolve DNS names? | 311 | //TODO: periodically re-resolve DNS names? |
302 | if (!p->lsa) { | 312 | if (!p->lsa) { |
303 | p->lsa = host2sockaddr(p->hostname, 123); | 313 | if (!resolve_hostname(p)) { |
304 | if (!p->lsa) { | ||
305 | set_next(p, INTERVAL_QUERY_PATHETIC); | 314 | set_next(p, INTERVAL_QUERY_PATHETIC); |
306 | return -1; | 315 | return -1; |
307 | } | 316 | } |
308 | p->dotted = xmalloc_sockaddr2dotted_noport(&p->lsa->u.sa); | ||
309 | } | 317 | } |
310 | 318 | ||
311 | family = p->lsa->u.sa.sa_family; | 319 | family = p->lsa->u.sa.sa_family; |