Extract common code. Create subroutine paddr_prefix_size().

This commit is contained in:
dyoung 2008-08-01 22:29:13 +00:00
parent b66028ed66
commit 10b425b514
3 changed files with 13 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ifconfig.c,v 1.212 2008/07/20 01:20:22 lukem Exp $ */
/* $NetBSD: ifconfig.c,v 1.213 2008/08/01 22:29:13 dyoung Exp $ */
/*-
* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@ -63,7 +63,7 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\
The Regents of the University of California. All rights reserved.");
__RCSID("$NetBSD: ifconfig.c,v 1.212 2008/07/20 01:20:22 lukem Exp $");
__RCSID("$NetBSD: ifconfig.c,v 1.213 2008/08/01 22:29:13 dyoung Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -1270,8 +1270,7 @@ setifprefixlen(prop_dictionary_t env, prop_dictionary_t oenv)
if (pfx == NULL)
err(EXIT_FAILURE, "prefixlen_to_mask");
d = prop_data_create_data(pfx,
offsetof(struct paddr_prefix, pfx_addr) + pfx->pfx_addr.sa_len);
d = prop_data_create_data(pfx, paddr_prefix_size(pfx));
if (d == NULL)
err(EXIT_FAILURE, "%s: prop_data_create_data", __func__);

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.11 2008/08/01 18:05:56 dyoung Exp $ */
/* $NetBSD: parse.c,v 1.12 2008/08/01 22:29:14 dyoung Exp $ */
/*-
* Copyright (c) 2008 David Young. All rights reserved.
@ -27,7 +27,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: parse.c,v 1.11 2008/08/01 18:05:56 dyoung Exp $");
__RCSID("$NetBSD: parse.c,v 1.12 2008/08/01 22:29:14 dyoung Exp $");
#endif /* not lint */
#include <err.h>
@ -470,8 +470,7 @@ paddr_match(const struct parser *p, const struct match *im, struct match *om,
return -1;
}
masklen = offsetof(struct paddr_prefix, pfx_addr) +
mask->pfx_addr.sa_len;
masklen = paddr_prefix_size(mask);
d = prop_data_create_data(mask, masklen);
free(mask);

View File

@ -3,6 +3,7 @@
#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <sys/queue.h>
#include <prop/proplib.h>
#include <sys/socket.h>
@ -229,6 +230,12 @@ struct paddr_prefix {
struct sockaddr pfx_addr;
};
static inline size_t
paddr_prefix_size(const struct paddr_prefix *pfx)
{
return offsetof(struct paddr_prefix, pfx_addr) + pfx->pfx_addr.sa_len;
}
struct paddr {
struct parser pa_parser;
const char *pa_addrkey;