ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/cidr.C
(Generate patch)

Comparing ermyth/src/cidr.C (file contents):
Revision 1.3 by pippijn, Sat Jul 21 13:23:21 2007 UTC vs.
Revision 1.4 by pippijn, Tue Aug 28 17:08:12 2007 UTC

4 * 4 *
5 * Most code in this file has been copied from ratbox, src/match.c and 5 * Most code in this file has been copied from ratbox, src/match.c and
6 * src/irc_string.c. It provides CIDR matching for IPv4 and IPv6 without 6 * src/irc_string.c. It provides CIDR matching for IPv4 and IPv6 without
7 * special OS support. 7 * special OS support.
8 * 8 *
9 * Copyright © 1996-2002 Hybrid Development Team 9 * Copyright © 1996-2002 Hybrid Development Team
10 * Copyright © 2002-2005 ircd-ratbox development team 10 * Copyright © 2002-2005 ircd-ratbox development team
11 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) 11 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
12 */ 12 */
13 13
14static char const rcsid[] = "$Id: cidr.C,v 1.3 2007/07/21 13:23:21 pippijn Exp $"; 14static char const rcsid[] = "$Id: cidr.C,v 1.4 2007/08/28 17:08:12 pippijn Exp $";
15 15
16#include "atheme.h" 16#include "atheme.h"
17 17
18#ifndef INADDRSZ 18#ifndef INADDRSZ
19#define INADDRSZ 4 19#define INADDRSZ 4
42 return (0); 42 return (0);
43} 43}
44 44
45/* 45/*
46 * inet_pton4() and inet_pton6() are 46 * inet_pton4() and inet_pton6() are
47 * Copyright © 1996-1999 by Internet Software Consortium. 47 * Copyright © 1996-1999 by Internet Software Consortium.
48 * 48 *
49 * Permission to use, copy, modify, and distribute this software for any 49 * Permission to use, copy, modify, and distribute this software for any
50 * purpose with or without fee is hereby granted, provided that the above 50 * purpose with or without fee is hereby granted, provided that the above
51 * copyright notice and this permission notice appear in all copies. 51 * copyright notice and this permission notice appear in all copies.
52 * 52 *
132static int 132static int
133inet_pton6 (char const *src, unsigned char *dst) 133inet_pton6 (char const *src, unsigned char *dst)
134{ 134{
135 static const char xdigits[] = "0123456789abcdef"; 135 static const char xdigits[] = "0123456789abcdef";
136 unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp; 136 unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
137 const char *curtok; 137 char const *curtok;
138 int ch, saw_xdigit; 138 int ch, saw_xdigit;
139 unsigned val; 139 unsigned val;
140 140
141 tp = static_cast<unsigned char *> (memset (tmp, '\0', IN6ADDRSZ)); 141 tp = static_cast<unsigned char *> (memset (tmp, '\0', IN6ADDRSZ));
142 endp = tp + IN6ADDRSZ; 142 endp = tp + IN6ADDRSZ;
148 curtok = src; 148 curtok = src;
149 saw_xdigit = 0; 149 saw_xdigit = 0;
150 val = 0; 150 val = 0;
151 while ((ch = tolower (*src++)) != '\0') 151 while ((ch = tolower (*src++)) != '\0')
152 { 152 {
153 const char *pch; 153 char const *pch;
154 154
155 pch = strchr (xdigits, ch); 155 pch = strchr (xdigits, ch);
156 if (pch != NULL) 156 if (pch != NULL)
157 { 157 {
158 val <<= 4; 158 val <<= 4;
234 * Input - cidr ip mask, address 234 * Input - cidr ip mask, address
235 * Output - 0 = Matched 1 = Did not match 235 * Output - 0 = Matched 1 = Did not match
236 * switched 0 and 1 to be consistent with match() -- jilles 236 * switched 0 and 1 to be consistent with match() -- jilles
237 */ 237 */
238int 238int
239match_ips (const char *s1, const char *s2) 239match_ips (char const * const s1, char const * const s2)
240{ 240{
241 unsigned char ipaddr[IN6ADDRSZ], maskaddr[IN6ADDRSZ]; 241 unsigned char ipaddr[IN6ADDRSZ], maskaddr[IN6ADDRSZ];
242 char ipmask[BUFSIZE]; 242 char ipmask[BUFSIZE];
243 char ip[HOSTLEN + 1]; 243 char ip[HOSTLEN + 1];
244 char *len; 244 char *len;
286 * Input - mask n!u@i/c, address n!u@i 286 * Input - mask n!u@i/c, address n!u@i
287 * Output - 0 = Matched 1 = Did not match 287 * Output - 0 = Matched 1 = Did not match
288 * switched 0 and 1 to be consistent with match() -- jilles 288 * switched 0 and 1 to be consistent with match() -- jilles
289 */ 289 */
290int 290int
291match_cidr (const char *s1, const char *s2) 291match_cidr (char const * const s1, char const * const s2)
292{ 292{
293 unsigned char ipaddr[IN6ADDRSZ], maskaddr[IN6ADDRSZ]; 293 unsigned char ipaddr[IN6ADDRSZ], maskaddr[IN6ADDRSZ];
294 char mask[BUFSIZE]; 294 char mask[BUFSIZE];
295 char address[NICKLEN + USERLEN + HOSTLEN + 6]; 295 char address[NICKLEN + USERLEN + HOSTLEN + 6];
296 char *ipmask; 296 char *ipmask;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines