diff options
-rw-r--r-- | usr.sbin/ntpd/config.c | 24 | ||||
-rw-r--r-- | usr.sbin/ntpd/ntpd.h | 7 | ||||
-rw-r--r-- | usr.sbin/ntpd/parse.y | 13 |
3 files changed, 28 insertions, 16 deletions
diff --git a/usr.sbin/ntpd/config.c b/usr.sbin/ntpd/config.c index b3a0dba19b9..140052de363 100644 --- a/usr.sbin/ntpd/config.c +++ b/usr.sbin/ntpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.9 2004/07/28 16:38:43 henning Exp $ */ +/* $OpenBSD: config.c,v 1.10 2004/08/10 12:41:15 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -20,7 +20,11 @@ #include <sys/socket.h> #include <sys/stat.h> +#include <netinet/in.h> +#include <arpa/nameser.h> + #include <errno.h> +#include <resolv.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -30,6 +34,8 @@ struct ntp_addr *host_v4(const char *); struct ntp_addr *host_v6(const char *); +static u_int32_t maxid = 0; + int host(const char *s, struct ntp_addr **hn) { @@ -115,9 +121,9 @@ host_dns(const char *s, struct ntp_addr **hn) struct sockaddr_in6 *sa_in6; struct ntp_addr *h, *hh = NULL; - memset(&hints, 0, sizeof(hints)); + bzero(&hints, sizeof(hints)); hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; /* DUMMY */ + hints.ai_socktype = SOCK_DGRAM; /* DUMMY */ error = getaddrinfo(s, NULL, &hints, &res0); if (error) { log_warnx("could not parse \"%s\": %s", s, @@ -156,3 +162,15 @@ host_dns(const char *s, struct ntp_addr **hn) *hn = hh; return (cnt); } + +struct ntp_peer * +new_peer(void) +{ + struct ntp_peer *p; + + if ((p = calloc(1, sizeof(struct ntp_peer))) == NULL) + fatal("conf_main server calloc"); + p->id = ++maxid; + + return (p); +} diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h index d093ca5d187..db3efbc8032 100644 --- a/usr.sbin/ntpd/ntpd.h +++ b/usr.sbin/ntpd/ntpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.h,v 1.31 2004/07/29 11:01:48 henning Exp $ */ +/* $OpenBSD: ntpd.h,v 1.32 2004/08/10 12:41:15 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -207,8 +207,9 @@ int parse_config(char *, struct ntpd_conf *); int cmdline_symset(char *); /* config.c */ -int host(const char *, struct ntp_addr **); -int host_dns(const char *, struct ntp_addr **); +int host(const char *, struct ntp_addr **); +int host_dns(const char *, struct ntp_addr **); +struct ntp_peer *new_peer(void); /* ntp_msg.c */ int ntp_getmsg(char *, ssize_t, struct ntp_msg *); diff --git a/usr.sbin/ntpd/parse.y b/usr.sbin/ntpd/parse.y index 508df8d0fe6..00a51546f65 100644 --- a/usr.sbin/ntpd/parse.y +++ b/usr.sbin/ntpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.17 2004/07/29 11:01:48 henning Exp $ */ +/* $OpenBSD: parse.y,v 1.18 2004/08/10 12:41:15 henning Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -41,7 +41,6 @@ static int lineno = 1; static int errors = 0; static int pdebug = 1; char *infile; -static u_int32_t maxid; int yyerror(const char *, ...); int yyparse(void); @@ -169,10 +168,7 @@ conf_main : LISTEN ON address { free($2); YYERROR; } - p = calloc(1, sizeof(struct ntp_peer)); - if (p == NULL) - fatal("conf_main server calloc"); - p->id = ++maxid; + p = new_peer(); h->next = NULL; p->addr = h; p->addr_head.a = h; @@ -189,9 +185,7 @@ conf_main : LISTEN ON address { struct ntp_peer *p; struct ntp_addr *h, *next; - if ((p = calloc(1, sizeof(struct ntp_peer))) == NULL) - fatal("conf_main server calloc"); - p->id = ++maxid; + p = new_peer(); for (h = $2->a; h != NULL; h = next) { next = h->next; if (h->ss.ss_family != AF_INET && @@ -481,7 +475,6 @@ parse_config(char *filename, struct ntpd_conf *xconf) conf = xconf; lineno = 1; errors = 0; - maxid = 0; TAILQ_INIT(&conf->listen_addrs); TAILQ_INIT(&conf->ntp_peers); |