diff options
author | 2004-01-22 13:32:00 +0000 | |
---|---|---|
committer | 2004-01-22 13:32:00 +0000 | |
commit | 88cd55ab99bae3db8084a001960b25cee0677cd9 (patch) | |
tree | 116ad8cd1c7e78a03e85fb13dcae5e47612007ac | |
parent | -S enables tcp md5 signature option; ok deraadt@, mcbride@ (diff) | |
download | wireguard-openbsd-88cd55ab99bae3db8084a001960b25cee0677cd9.tar.xz wireguard-openbsd-88cd55ab99bae3db8084a001960b25cee0677cd9.zip |
to parse v4 adresses, only use inet_net_pton when we find a /, otherwise
use inet_pton.
helps bob who likes to type 1.2 3.4 instead of 1.2.3.4 and wonders why this
results in two addresses.
PR3638, bob ok
-rw-r--r-- | sbin/pfctl/pfctl_parser.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/sbin/pfctl/pfctl_parser.c b/sbin/pfctl/pfctl_parser.c index a82705b3d64..2210715811b 100644 --- a/sbin/pfctl/pfctl_parser.c +++ b/sbin/pfctl/pfctl_parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl_parser.c,v 1.187 2003/12/31 22:14:41 deraadt Exp $ */ +/* $OpenBSD: pfctl_parser.c,v 1.188 2004/01/22 13:32:00 henning Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -1326,21 +1326,28 @@ host_v4(const char *s, int mask) { struct node_host *h = NULL; struct in_addr ina; - int bits; + int bits = -1; memset(&ina, 0, sizeof(struct in_addr)); - if ((bits = inet_net_pton(AF_INET, s, &ina, sizeof(ina))) > -1) { - h = calloc(1, sizeof(struct node_host)); - if (h == NULL) - err(1, "address: calloc"); - h->ifname = NULL; - h->af = AF_INET; - h->addr.v.a.addr.addr32[0] = ina.s_addr; - set_ipmask(h, bits); - h->next = NULL; - h->tail = h; + if (strrchr(s, '/') != NULL) { + if ((bits = inet_net_pton(AF_INET, s, &ina, sizeof(ina))) == -1) + return (NULL); + } else { + if (inet_pton(AF_INET, s, &ina) != 1) + return (NULL); } + h = calloc(1, sizeof(struct node_host)); + if (h == NULL) + err(1, "address: calloc"); + h->ifname = NULL; + h->af = AF_INET; + h->addr.v.a.addr.addr32[0] = ina.s_addr; + if (bits != -1) + set_ipmask(h, bits); + h->next = NULL; + h->tail = h; + return (h); } |