From: kn Date: Fri, 10 Aug 2018 09:54:06 +0000 (+0000) Subject: Zap bits in host_v4(), use mask parameter X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a7ede25358dad545e0342d2a9f8ef6ce68c6df66;p=openbsd 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 --- 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;