diff options
author | kn <kn@cvs.openbsd.org> | 2018-08-10 09:54:07 +0000 |
---|---|---|
committer | kn <kn@cvs.openbsd.org> | 2018-08-10 09:54:07 +0000 |
commit | 5076b9bd3d5cd5fe2172961dae0f611187b1bbad (patch) | |
tree | f377544fa5630479b118363f7ef75c144f90274d /sbin | |
parent | 8f7cdde1bab569260af0393ab33a50c94c1d1b80 (diff) |
Zap bits in host_v4(), use mask parameter
This avoids a duplicate strrchr() call and makes the function consistent
with host_v6() regarding mask handling.
While here, use the destination's size in memcpy instead of hardcoding its
type.
OK sashan
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/pfctl/pfctl_parser.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/sbin/pfctl/pfctl_parser.c b/sbin/pfctl/pfctl_parser.c index dab9e7d0ba4..a670d093b7c 100644 --- a/sbin/pfctl/pfctl_parser.c +++ b/sbin/pfctl/pfctl_parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl_parser.c,v 1.326 2018/07/31 22:48:04 kn Exp $ */ +/* $OpenBSD: pfctl_parser.c,v 1.327 2018/08/10 09:54:06 kn Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -1727,11 +1727,10 @@ host_v4(const char *s, int mask) { struct node_host *h = NULL; struct in_addr ina; - int bits = 32; - memset(&ina, 0, sizeof(struct in_addr)); - if (strrchr(s, '/') != NULL) { - if ((bits = inet_net_pton(AF_INET, s, &ina, sizeof(ina))) == -1) + memset(&ina, 0, sizeof(ina)); + if (mask > -1) { + if (inet_net_pton(AF_INET, s, &ina, sizeof(ina)) == -1) return (NULL); } else { if (inet_pton(AF_INET, s, &ina) != 1) @@ -1744,7 +1743,7 @@ host_v4(const char *s, int mask) h->ifname = NULL; h->af = AF_INET; h->addr.v.a.addr.addr32[0] = ina.s_addr; - set_ipmask(h, bits); + set_ipmask(h, mask > -1 ? mask : 32); h->next = NULL; h->tail = h; |