diff options
Diffstat (limited to 'libmailutils/cidr/match.c')
-rw-r--r-- | libmailutils/cidr/match.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/libmailutils/cidr/match.c b/libmailutils/cidr/match.c new file mode 100644 index 000000000..dff9194ee --- /dev/null +++ b/libmailutils/cidr/match.c | |||
@@ -0,0 +1,38 @@ | |||
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2011 Free Software Foundation, Inc. | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 3 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General | ||
15 | Public License along with this library. If not, see | ||
16 | <http://www.gnu.org/licenses/>. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | #include <mailutils/cidr.h> | ||
22 | #include <mailutils/errno.h> | ||
23 | |||
24 | int | ||
25 | mu_cidr_match (struct mu_cidr *a, struct mu_cidr *b) | ||
26 | { | ||
27 | int i; | ||
28 | |||
29 | if (a->family != b->family) | ||
30 | return 1; | ||
31 | for (i = 0; i < a->len; i++) | ||
32 | { | ||
33 | if (a->address[i] != (b->address[i] & a->netmask[i])) | ||
34 | return 1; | ||
35 | } | ||
36 | return 0; | ||
37 | } | ||
38 | |||