diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2016-02-15 12:53:51 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2016-02-15 12:53:51 +0000 |
commit | 114dfafb4f5cc412184f05a4f28b44b48e67eb4c (patch) | |
tree | 219c0dde8ac2824a0123a3212eb79be6ac146a5a | |
parent | 98fba69e0d9a5b781f4a2e0f863bc85c2c46248f (diff) |
Revert previous, semarie@ found a regression.
-rw-r--r-- | usr.sbin/smtpd/to.c | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/usr.sbin/smtpd/to.c b/usr.sbin/smtpd/to.c index 07beeee7a49..5cc2da51bb2 100644 --- a/usr.sbin/smtpd/to.c +++ b/usr.sbin/smtpd/to.c @@ -1,4 +1,4 @@ -/* $OpenBSD: to.c,v 1.25 2016/02/14 15:11:10 mpi Exp $ */ +/* $OpenBSD: to.c,v 1.26 2016/02/15 12:53:50 mpi Exp $ */ /* * Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net> @@ -274,23 +274,42 @@ text_to_netaddr(struct netaddr *netaddr, const char *s) if (strncasecmp("IPv6:", s, 5) == 0) s += 5; - bits = inet_net_pton(AF_INET, s, &ssin.sin_addr, - sizeof(struct in_addr)); - if (bits != -1) { - ssin.sin_family = AF_INET; - memcpy(&ss, &ssin, sizeof(ssin)); - ss.ss_len = sizeof(struct sockaddr_in); + if (strchr(s, '/') != NULL) { + /* dealing with netmask */ + bits = inet_net_pton(AF_INET, s, &ssin.sin_addr, + sizeof(struct in_addr)); + if (bits != -1) { + ssin.sin_family = AF_INET; + memcpy(&ss, &ssin, sizeof(ssin)); + ss.ss_len = sizeof(struct sockaddr_in); + } + else { + bits = inet_net_pton(AF_INET6, s, &ssin6.sin6_addr, + sizeof(struct in6_addr)); + if (bits == -1) { + log_warn("warn: inet_net_pton"); + return 0; + } + ssin6.sin6_family = AF_INET6; + memcpy(&ss, &ssin6, sizeof(ssin6)); + ss.ss_len = sizeof(struct sockaddr_in6); + } } else { - bits = inet_net_pton(AF_INET6, s, &ssin6.sin6_addr, - sizeof(struct in6_addr)); - if (bits == -1) { - log_warn("warn: inet_net_pton"); - return 0; + /* IP address ? */ + if (inet_pton(AF_INET, s, &ssin.sin_addr) == 1) { + ssin.sin_family = AF_INET; + bits = 32; + memcpy(&ss, &ssin, sizeof(ssin)); + ss.ss_len = sizeof(struct sockaddr_in); + } + else if (inet_pton(AF_INET6, s, &ssin6.sin6_addr) == 1) { + ssin6.sin6_family = AF_INET6; + bits = 128; + memcpy(&ss, &ssin6, sizeof(ssin6)); + ss.ss_len = sizeof(struct sockaddr_in6); } - ssin6.sin6_family = AF_INET6; - memcpy(&ss, &ssin6, sizeof(ssin6)); - ss.ss_len = sizeof(struct sockaddr_in6); + else return 0; } netaddr->ss = ss; |