2 * Copyright (C) 1995-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 static const char sccsid
[] = "@(#)ipft_hx.c 1.1 3/9/96 (C) 1996 Darren Reed";
7 static const char rcsid
[] = "@(#)$Id: ipft_hx.c,v 1.11.4.1 2004/12/09 19:41:20 darrenr Exp $";
17 static int hex_open
__P((char *));
18 static int hex_close
__P((void));
19 static int hex_readip
__P((char *, int, char **, int *));
20 static char *readhex
__P((char *, char *));
22 struct ipread iphex
= { hex_open
, hex_close
, hex_readip
, 0 };
23 static FILE *tfp
= NULL
;
26 static int hex_open(fname
)
29 if (tfp
&& tfd
!= -1) {
34 if (!strcmp(fname
, "-")) {
38 tfd
= open(fname
, O_RDONLY
);
40 tfp
= fdopen(tfd
, "r");
46 static int hex_close()
55 static int hex_readip(buf
, cnt
, ifn
, dir
)
59 register char *s
, *t
, *u
;
64 * interpret start of line as possibly "[ifname]" or
72 while (fgets(line
, sizeof(line
)-1, tfp
)) {
73 if ((s
= strchr(line
, '\n'))) {
75 return (char *)ip
- buf
;
78 if ((s
= strchr(line
, '#')))
82 if (!(opts
& OPT_BRIEF
)) {
83 printf("input: %s", line
);
86 if ((*line
== '[') && (s
= strchr(line
, ']'))) {
90 if ((u
= strchr(t
, ',')) && (u
< s
)) {
106 ip
= (ip_t
*)readhex(s
, (char *)ip
);
107 if (!(opts
& OPT_BRIEF
)) {
108 if (opts
& OPT_ASCII
) {
111 while (t
< (char *)ip
) {
112 if (ISPRINT(*t
) && ISASCII(*t
))
127 static char *readhex(src
, dst
)
128 register char *src
, *dst
;
133 while ((c
= *src
++)) {
140 } else if ((c
>= '0' && c
<= '9') || (c
>= 'a' && c
<= 'f') ||
141 (c
>= 'A' && c
<= 'F')) {
142 c
= ISDIGIT(c
) ? (c
- '0') : (TOUPPER(c
) - 55);