2 * Copyright (C) 1995-1998 by Darren Reed.
4 * Redistribution and use in source and binary forms are permitted
5 * provided that this notice is preserved and due credit is given
6 * to the original author and the contributors.
12 #include <sys/types.h>
13 #if !defined(__SVR4) && !defined(__svr4__)
16 #include <sys/byteorder.h>
18 #include <sys/param.h>
23 #include <sys/socket.h>
24 #include <sys/ioctl.h>
25 #include <netinet/in.h>
26 #include <netinet/in_systm.h>
28 #include <netinet/ip_var.h>
30 #include <netinet/ip.h>
31 #include <netinet/udp.h>
32 #include <netinet/tcp.h>
33 #include <netinet/ip_icmp.h>
36 #include <arpa/nameser.h>
38 #include "ip_compat.h"
39 #include <netinet/tcpip.h>
44 static const char sccsid[] = "@(#)ipft_hx.c 1.1 3/9/96 (C) 1996 Darren Reed";
45 static const char rcsid[] = "@(#)$Id: ipft_hx.c,v 2.1 1999/08/04 17:30:03 darrenr Exp $";
50 static int hex_open __P((char *));
51 static int hex_close __P((void));
52 static int hex_readip __P((char *, int, char **, int *));
53 static char *readhex __P((char *, char *));
55 struct ipread iphex = { hex_open, hex_close, hex_readip };
56 static FILE *tfp = NULL;
59 static int hex_open(fname)
62 if (tfp && tfd != -1) {
67 if (!strcmp(fname, "-")) {
71 tfd = open(fname, O_RDONLY);
73 tfp = fdopen(tfd, "r");
79 static int hex_close()
88 static int hex_readip(buf, cnt, ifn, dir)
92 register char *s, *t, *u;
97 while (fgets(line, sizeof(line)-1, tfp)) {
98 if ((s = index(line, '\n'))) {
100 return (char *)ip - buf;
103 if ((s = index(line, '#')))
107 if (!(opts & OPT_BRIEF)) {
108 printf("input: %s\n", line);
113 * interpret start of line as possibly "[ifname]" or
120 if ((*buf == '[') && (s = index(line, ']'))) {
123 if ((u = index(t, ',')) && (u < s)) {
139 ip = (ip_t *)readhex(s, (char *)ip);
145 static char *readhex(src, dst)
146 register char *src, *dst;
151 while ((c = *src++)) {
158 } else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
159 (c >= 'A' && c <= 'F')) {
160 c = isdigit(c) ? (c - '0') : (toupper(c) - 55);