summaryrefslogtreecommitdiffstats
path: root/libexec/spamd
diff options
context:
space:
mode:
Diffstat (limited to 'libexec/spamd')
-rw-r--r--libexec/spamd/spamd.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/libexec/spamd/spamd.c b/libexec/spamd/spamd.c
index 86a97ebed1b..22acebf2072 100644
--- a/libexec/spamd/spamd.c
+++ b/libexec/spamd/spamd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: spamd.c,v 1.147 2016/11/30 07:54:36 mestre Exp $ */
+/* $OpenBSD: spamd.c,v 1.148 2017/01/17 23:28:04 mestre Exp $ */
/*
* Copyright (c) 2015 Henning Brauer <henning@openbsd.org>
@@ -1236,6 +1236,10 @@ main(int argc, char *argv[])
const char *errstr;
char *sync_iface = NULL;
char *sync_baddr = NULL;
+ struct addrinfo hints, *res;
+ char *addr;
+ char portstr[6];
+ int error;
tzset();
openlog_r("spamd", LOG_PID | LOG_NDELAY, LOG_DAEMON, &sdata);
@@ -1426,18 +1430,20 @@ main(int argc, char *argv[])
sizeof(one)) == -1)
return (-1);
- memset(&sin, 0, sizeof sin);
- sin.sin_len = sizeof(sin);
- if (bind_address) {
- if (inet_pton(AF_INET, bind_address, &sin.sin_addr) != 1)
- err(1, "inet_pton");
- } else
- sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- sin.sin_family = AF_INET;
- sin.sin_port = htons(port);
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ addr = bind_address;
+ snprintf(portstr, sizeof(portstr), "%hu", port);
- if (bind(smtplisten, (struct sockaddr *)&sin, sizeof sin) == -1)
+ if ((error = getaddrinfo(addr, portstr, &hints, &res)) != 0) {
+ errx(1, "getaddrinfo: %s", gai_strerror(error));
+ }
+
+ if (bind(smtplisten, res->ai_addr, res->ai_addrlen) == -1) {
+ freeaddrinfo(res);
err(1, "bind");
+ }
+ freeaddrinfo(res);
memset(&lin, 0, sizeof sin);
lin.sin_len = sizeof(sin);