4 * Copyright (C) 2000-2005 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
9 static const char sccsid
[] = "@(#)ipft_hx.c 1.1 3/9/96 (C) 1996 Darren Reed";
10 static const char rcsid
[] = "@(#)Id: ipft_hx.c,v 1.11.4.4 2006/06/16 17:21:03 darrenr Exp";
21 static int hex_open
__P((char *));
22 static int hex_close
__P((void));
23 static int hex_readip
__P((char *, int, char **, int *));
24 static char *readhex
__P((char *, char *));
26 struct ipread iphex
= { hex_open
, hex_close
, hex_readip
, 0 };
27 static FILE *tfp
= NULL
;
30 static int hex_open(fname
)
33 if (tfp
&& tfd
!= -1) {
38 if (!strcmp(fname
, "-")) {
42 tfd
= open(fname
, O_RDONLY
);
44 tfp
= fdopen(tfd
, "r");
50 static int hex_close()
59 static int hex_readip(buf
, cnt
, ifn
, dir
)
63 register char *s
, *t
, *u
;
68 * interpret start of line as possibly "[ifname]" or
76 while (fgets(line
, sizeof(line
)-1, tfp
)) {
77 if ((s
= strchr(line
, '\n'))) {
79 return (char *)ip
- buf
;
82 if ((s
= strchr(line
, '#')))
86 if ((opts
& OPT_DEBUG
) != 0) {
87 printf("input: %s", line
);
90 if ((*line
== '[') && (s
= strchr(line
, ']'))) {
94 if ((u
= strchr(t
, ',')) && (u
< s
)) {
110 ip
= (ip_t
*)readhex(s
, (char *)ip
);
111 if ((opts
& OPT_DEBUG
) != 0) {
112 if (opts
& OPT_ASCII
) {
115 while (t
< (char *)ip
) {
116 if (ISPRINT(*t
) && ISASCII(*t
))
133 static char *readhex(src
, dst
)
134 register char *src
, *dst
;
139 while ((c
= *src
++)) {
146 } else if ((c
>= '0' && c
<= '9') || (c
>= 'a' && c
<= 'f') ||
147 (c
>= 'A' && c
<= 'F')) {
148 c
= ISDIGIT(c
) ? (c
- '0') : (TOUPPER(c
) - 55);