-/* $OpenBSD: pfctl_parser.c,v 1.347 2022/11/09 23:00:00 sashan Exp $ */
+/* $OpenBSD: pfctl_parser.c,v 1.348 2023/04/18 13:31:14 tb Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
#include "pfctl_parser.h"
#include "pfctl.h"
+#ifndef nitems
+#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
+#endif
+
void print_op (u_int8_t, const char *, const char *);
void print_port (u_int8_t, u_int16_t, u_int16_t, const char *, int);
void print_ugid (u_int8_t, id_t, id_t, const char *);
const struct icmptypeent *
geticmptypebynumber(u_int8_t type, sa_family_t af)
{
- unsigned int i;
+ size_t i;
if (af != AF_INET6) {
- for (i=0; i < (sizeof (icmp_type) / sizeof(icmp_type[0]));
- i++) {
+ for (i = 0; i < nitems(icmp_type); i++) {
if (type == icmp_type[i].type)
return (&icmp_type[i]);
}
} else {
- for (i=0; i < (sizeof (icmp6_type) /
- sizeof(icmp6_type[0])); i++) {
+ for (i = 0; i < nitems(icmp6_type); i++) {
if (type == icmp6_type[i].type)
return (&icmp6_type[i]);
}
const struct icmptypeent *
geticmptypebyname(char *w, sa_family_t af)
{
- unsigned int i;
+ size_t i;
if (af != AF_INET6) {
- for (i=0; i < (sizeof (icmp_type) / sizeof(icmp_type[0]));
- i++) {
+ for (i = 0; i < nitems(icmp_type); i++) {
if (!strcmp(w, icmp_type[i].name))
return (&icmp_type[i]);
}
} else {
- for (i=0; i < (sizeof (icmp6_type) /
- sizeof(icmp6_type[0])); i++) {
+ for (i = 0; i < nitems(icmp6_type); i++) {
if (!strcmp(w, icmp6_type[i].name))
return (&icmp6_type[i]);
}
const struct icmpcodeent *
geticmpcodebynumber(u_int8_t type, u_int8_t code, sa_family_t af)
{
- unsigned int i;
+ size_t i;
if (af != AF_INET6) {
- for (i=0; i < (sizeof (icmp_code) / sizeof(icmp_code[0]));
- i++) {
+ for (i = 0; i < nitems(icmp_code); i++) {
if (type == icmp_code[i].type &&
code == icmp_code[i].code)
return (&icmp_code[i]);
}
} else {
- for (i=0; i < (sizeof (icmp6_code) /
- sizeof(icmp6_code[0])); i++) {
+ for (i = 0; i < nitems(icmp6_code); i++) {
if (type == icmp6_code[i].type &&
code == icmp6_code[i].code)
return (&icmp6_code[i]);
const struct icmpcodeent *
geticmpcodebyname(u_long type, char *w, sa_family_t af)
{
- unsigned int i;
+ size_t i;
if (af != AF_INET6) {
- for (i=0; i < (sizeof (icmp_code) / sizeof(icmp_code[0]));
- i++) {
+ for (i = 0; i < nitems(icmp_code); i++) {
if (type == icmp_code[i].type &&
!strcmp(w, icmp_code[i].name))
return (&icmp_code[i]);
}
} else {
- for (i=0; i < (sizeof (icmp6_code) /
- sizeof(icmp6_code[0])); i++) {
+ for (i = 0; i < nitems(icmp6_code); i++) {
if (type == icmp6_code[i].type &&
!strcmp(w, icmp6_code[i].name))
return (&icmp6_code[i]);
-/* $OpenBSD: parse.y,v 1.447 2023/04/18 12:11:27 claudio Exp $ */
+/* $OpenBSD: parse.y,v 1.448 2023/04/18 13:31:14 tb Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
#include "rde.h"
#include "log.h"
+#ifndef nitems
+#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
+#endif
+
#define MACRO_NAME_LEN 128
TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
};
const struct keywords *p;
- p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
- sizeof(keywords[0]), kw_cmp);
+ p = bsearch(s, keywords, nitems(keywords), sizeof(keywords[0]), kw_cmp);
if (p)
return (p->k_val);
};
const struct keywords *p;
- p = bsearch(s, toswords, sizeof(toswords)/sizeof(toswords[0]),
- sizeof(toswords[0]), kw_casecmp);
+ p = bsearch(s, toswords, nitems(toswords), sizeof(toswords[0]),
+ kw_casecmp);
if (p) {
*val = p->k_val;
static int
geticmptypebyname(char *w, uint8_t aid)
{
- unsigned int i;
+ size_t i;
switch (aid) {
case AID_INET:
- for (i = 0; i < (sizeof(icmp_type) / sizeof(icmp_type[0]));
- i++) {
+ for (i = 0; i < nitems(icmp_type); i++) {
if (!strcmp(w, icmp_type[i].name))
return (icmp_type[i].type);
}
break;
case AID_INET6:
- for (i = 0; i < (sizeof(icmp6_type) / sizeof(icmp6_type[0]));
- i++) {
+ for (i = 0; i < nitems(icmp6_type); i++) {
if (!strcmp(w, icmp6_type[i].name))
return (icmp6_type[i].type);
}
static int
geticmpcodebyname(u_long type, char *w, uint8_t aid)
{
- unsigned int i;
+ size_t i;
switch (aid) {
case AID_INET:
- for (i = 0; i < (sizeof(icmp_code) / sizeof(icmp_code[0]));
- i++) {
+ for (i = 0; i < nitems(icmp_code); i++) {
if (type == icmp_code[i].type &&
!strcmp(w, icmp_code[i].name))
return (icmp_code[i].code);
}
break;
case AID_INET6:
- for (i = 0; i < (sizeof(icmp6_code) / sizeof(icmp6_code[0]));
- i++) {
+ for (i = 0; i < nitems(icmp6_code); i++) {
if (type == icmp6_code[i].type &&
!strcmp(w, icmp6_code[i].name))
return (icmp6_code[i].code);