summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorJason Wright <jason@cvs.openbsd.org>2007-05-02 15:17:12 +0000
committerJason Wright <jason@cvs.openbsd.org>2007-05-02 15:17:12 +0000
commit70e9f2aea1be8962756db82630ca5da40703bb8e (patch)
treef0268cb7b63cccf56b27d16fac06115d0f43c546 /usr.sbin
parent7f1eb8d208053d542a80b3e94acc7374c0c6112d (diff)
- use getaddrinfo() instead of gethostbyname/getservbyname
- reserve a poll descriptor entry for INET6 (not used yet) ok henning
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/syslogd/syslogd.c73
-rw-r--r--usr.sbin/syslogd/syslogd.h3
2 files changed, 51 insertions, 25 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index 350c38e23e9..660148f911e 100644
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: syslogd.c,v 1.97 2007/03/30 18:25:44 canacar Exp $ */
+/* $OpenBSD: syslogd.c,v 1.98 2007/05/02 15:17:11 jason Exp $ */
/*
* Copyright (c) 1983, 1988, 1993, 1994
@@ -39,7 +39,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94";
#else
-static const char rcsid[] = "$OpenBSD: syslogd.c,v 1.97 2007/03/30 18:25:44 canacar Exp $";
+static const char rcsid[] = "$OpenBSD: syslogd.c,v 1.98 2007/05/02 15:17:11 jason Exp $";
#endif
#endif /* not lint */
@@ -299,6 +299,7 @@ main(int argc, char *argv[])
char *p, *line;
char resolve[MAXHOSTNAMELEN];
int lockpipe[2], nullfd;
+ struct addrinfo hints, *res, *res0;
FILE *fp;
while ((ch = getopt(argc, argv, "dnuf:m:p:a:s:")) != -1)
@@ -376,36 +377,60 @@ main(int argc, char *argv[])
pfd[i].events = 0;
}
- if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) != -1) {
- struct servent *sp;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_protocol = IPPROTO_UDP;
+ hints.ai_flags = AI_PASSIVE;
- /* XXX use getaddrinfo */
- sp = getservbyname("syslog", "udp");
- if (sp == NULL) {
- errno = 0;
- logerror("syslog/udp: unknown service");
- die(0);
+ i = getaddrinfo(NULL, "syslog", &hints, &res0);
+ if (i) {
+ errno = 0;
+ logerror("syslog/udp: unknown service");
+ die(0);
+ }
+
+ for (res = res0; res; res = res->ai_next) {
+ struct pollfd *pfdp;
+
+ if (res->ai_family == AF_INET)
+ pfdp = &pfd[PFD_INET];
+ else {
+ /*
+ * XXX AF_INET6 is skipped on purpose, need to
+ * fix '@' handling first.
+ */
+ continue;
}
- memset(&s_in, 0, sizeof(s_in));
- s_in.sin_len = sizeof(s_in);
- s_in.sin_family = AF_INET;
- s_in.sin_port = LogPort = sp->s_port;
- if (bind(fd, (struct sockaddr *)&s_in, sizeof(s_in)) < 0) {
+
+ if (pfdp->fd >= 0)
+ continue;
+
+ fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+ if (fd < 0)
+ continue;
+
+ if (bind(fd, res->ai_addr, res->ai_addrlen) < 0) {
logerror("bind");
+ close(fd);
if (!Debug)
die(0);
- } else {
- InetInuse = 1;
- pfd[PFD_INET].fd = fd;
- if (SecureMode) {
- shutdown(fd, SHUT_RD);
- } else {
- double_rbuf(fd);
- pfd[PFD_INET].events = POLLIN;
- }
+ fd = -1;
+ continue;
+ }
+
+ InetInuse = 1;
+ pfdp->fd = fd;
+ if (SecureMode)
+ shutdown(pfdp->fd, SHUT_RD);
+ else {
+ double_rbuf(pfdp->fd);
+ pfdp->events = POLLIN;
}
}
+ freeaddrinfo(res0);
+
#ifndef SUN_LEN
#define SUN_LEN(unp) (strlen((unp)->sun_path) + 2)
#endif
diff --git a/usr.sbin/syslogd/syslogd.h b/usr.sbin/syslogd/syslogd.h
index 5e40e3eb82f..22fdd4ecc60 100644
--- a/usr.sbin/syslogd/syslogd.h
+++ b/usr.sbin/syslogd/syslogd.h
@@ -50,7 +50,8 @@ extern int Startup;
#define PFD_INET 1 /* Offset of inet socket entry */
#define PFD_CTLSOCK 2 /* Offset of control socket entry */
#define PFD_CTLCONN 3 /* Offset of control connection entry */
-#define PFD_UNIX_0 4 /* Start of Unix socket entries */
+#define PFD_INET6 4 /* Offset of inet6 socket entry */
+#define PFD_UNIX_0 5 /* Start of Unix socket entries */
#define N_PFD (PFD_UNIX_0 + MAXFUNIX) /* # of pollfd entries */
extern struct pollfd pfd[N_PFD];