diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2016-02-14 15:11:11 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2016-02-14 15:11:11 +0000 |
commit | 3f7be81b6c2755201bd9b0097e8c45eb3082315d (patch) | |
tree | 006b66519b3048527c36f07c3929e053989a5fab | |
parent | 11b45e8ba8381277ee22d1b0d5d6ad0968a92606 (diff) |
Simplify address parsing code by only using inet_net_pton(3).
There's no need to have a separate case for non-CIDR addresses using
inet_pton(3) as inet_net_pton(3) handles them as well.
This simplification is valid for all our daemons parsing addresses,
it is a common patern.
ok gilles@, millert@, jung@
-rw-r--r-- | usr.sbin/smtpd/to.c | 49 |
1 files changed, 15 insertions, 34 deletions
diff --git a/usr.sbin/smtpd/to.c b/usr.sbin/smtpd/to.c index de3d82e8083..07beeee7a49 100644 --- a/usr.sbin/smtpd/to.c +++ b/usr.sbin/smtpd/to.c @@ -1,4 +1,4 @@ -/* $OpenBSD: to.c,v 1.24 2015/12/28 22:08:30 jung Exp $ */ +/* $OpenBSD: to.c,v 1.25 2016/02/14 15:11:10 mpi Exp $ */ /* * Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net> @@ -274,42 +274,23 @@ text_to_netaddr(struct netaddr *netaddr, const char *s) if (strncasecmp("IPv6:", s, 5) == 0) s += 5; - 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); - } + 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 { - /* 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); + 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; } - else return 0; + ssin6.sin6_family = AF_INET6; + memcpy(&ss, &ssin6, sizeof(ssin6)); + ss.ss_len = sizeof(struct sockaddr_in6); } netaddr->ss = ss; |