cidr_match.h revision 1.1
1/*	$NetBSD: cidr_match.h,v 1.1 2009/06/23 10:08:59 tron Exp $	*/
2
3#ifndef _CIDR_MATCH_H_INCLUDED_
4#define _CIDR_MATCH_H_INCLUDED_
5
6/*++
7/* NAME
8/*	dict_cidr 3h
9/* SUMMARY
10/*	CIDR-style pattern matching
11/* SYNOPSIS
12/*	#include <cidr_match.h>
13/* DESCRIPTION
14/* .nf
15
16 /*
17  * System library.
18  */
19#include <limits.h>			/* CHAR_BIT */
20
21 /*
22  * Utility library.
23  */
24#include <myaddrinfo.h>			/* MAI_V6ADDR_BYTES etc. */
25#include <vstring.h>
26
27 /*
28  * External interface.
29  *
30  * Address length is protocol dependent. Find out how large our address byte
31  * strings should be.
32  */
33#ifdef HAS_IPV6
34# define CIDR_MATCH_ABYTES	MAI_V6ADDR_BYTES
35#else
36# define CIDR_MATCH_ABYTES	MAI_V4ADDR_BYTES
37#endif
38
39 /*
40  * Each parsed CIDR pattern can be member of a linked list.
41  */
42typedef struct CIDR_MATCH {
43    unsigned char net_bytes[CIDR_MATCH_ABYTES];	/* network portion */
44    unsigned char mask_bytes[CIDR_MATCH_ABYTES];	/* network mask */
45    unsigned char addr_family;		/* AF_XXX */
46    unsigned char addr_byte_count;	/* typically, 4 or 16 */
47    unsigned char addr_bit_count;	/* optimization */
48    unsigned char mask_shift;		/* optimization */
49    struct CIDR_MATCH *next;		/* next entry */
50} CIDR_MATCH;
51
52extern VSTRING *cidr_match_parse(CIDR_MATCH *, char *, VSTRING *);
53extern CIDR_MATCH *cidr_match_execute(CIDR_MATCH *, const char *);
54
55/* LICENSE
56/* .ad
57/* .fi
58/*	The Secure Mailer license must be distributed with this software.
59/* AUTHOR(S)
60/*	Wietse Venema
61/*	IBM T.J. Watson Research
62/*	P.O. Box 704
63/*	Yorktown Heights, NY 10598, USA
64/*--*/
65
66#endif
67