diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-01-22 13:32:01 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-01-22 13:32:01 +0000 |
commit | dae7a6edc446cead0145a4f90b534caffb15ad59 (patch) | |
tree | 2423c7abec3c3fee21c025e57b39baa402f09eca | |
parent | dcc3bd094e1969c3b0801a7baba10d465c7af82a (diff) |
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); } |