4 * Copyright (C) 2012 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$";
21 static int hex_open __P((char *));
22 static int hex_close __P((void));
23 static int hex_readip __P((mb_t *, 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(mb, ifn, dir)
64 register char *s, *t, *u;
70 buf = (char *)mb->mb_buf;
71 cnt = sizeof(mb->mb_buf);
73 * interpret start of line as possibly "[ifname]" or
81 while (fgets(line, sizeof(line)-1, tfp)) {
82 if ((s = strchr(line, '\n'))) {
84 mb->mb_len = (char *)ip - buf;
89 if ((s = strchr(line, '#')))
93 if ((opts & OPT_DEBUG) != 0) {
94 printf("input: %s", line);
97 if ((*line == '[') && (s = strchr(line, ']'))) {
101 if ((u = strchr(t, ',')) && (u < s)) {
115 while (*s++ == '+') {
116 if (!strncasecmp(s, "mcast", 5)) {
117 mb->mb_flags |= M_MCAST;
120 if (!strncasecmp(s, "bcast", 5)) {
121 mb->mb_flags |= M_BCAST;
124 if (!strncasecmp(s, "mbcast", 6)) {
125 mb->mb_flags |= M_MBCAST;
134 ip = (ip_t *)readhex(s, (char *)ip);
135 if ((opts & OPT_DEBUG) != 0) {
136 if (opts & OPT_ASCII) {
140 while (t < (char *)ip) {
141 if (isprint(c) && isascii(c))
158 static char *readhex(src, dst)
159 register char *src, *dst;
164 while ((c = *src++)) {
171 } else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
172 (c >= 'A' && c <= 'F')) {
173 c = ISDIGIT(c) ? (c - '0') : (TOUPPER(c) - 55);