Reduce amount of macro magic. Use the same special characters as nroff
[netbsd-mini2440.git] / dist / ipf / lib / printhash_live.c
blob241db81a031a1580ce668a652771969a5eb3cdbb
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2002 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
7 */
9 #include <sys/ioctl.h>
10 #include "ipf.h"
11 #include "netinet/ipl.h"
13 #define PRINTF (void)printf
14 #define FPRINTF (void)fprintf
17 iphtable_t *printhash_live(hp, fd, name, opts)
18 iphtable_t *hp;
19 int fd;
20 char *name;
21 int opts;
23 iphtent_t entry, *top, *node;
24 ipflookupiter_t iter;
25 int printed, last;
26 ipfobj_t obj;
28 if ((name != NULL) && strncmp(name, hp->iph_name, FR_GROUPLEN))
29 return hp->iph_next;
31 printhashdata(hp, opts);
33 if ((hp->iph_flags & IPHASH_DELETE) != 0)
34 PRINTF("# ");
36 if ((opts & OPT_DEBUG) == 0)
37 PRINTF("\t{");
39 obj.ipfo_rev = IPFILTER_VERSION;
40 obj.ipfo_type = IPFOBJ_LOOKUPITER;
41 obj.ipfo_ptr = &iter;
42 obj.ipfo_size = sizeof(iter);
44 iter.ili_data = &entry;
45 iter.ili_type = IPLT_HASH;
46 iter.ili_otype = IPFLOOKUPITER_NODE;
47 iter.ili_ival = IPFGENITER_LOOKUP;
48 iter.ili_unit = hp->iph_unit;
49 strncpy(iter.ili_name, hp->iph_name, FR_GROUPLEN);
51 last = 0;
52 top = NULL;
53 printed = 0;
55 while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) {
56 if (entry.ipe_next == NULL)
57 last = 1;
58 entry.ipe_next = top;
59 top = malloc(sizeof(*top));
60 if (top == NULL)
61 break;
62 bcopy(&entry, top, sizeof(entry));
65 while (top != NULL) {
66 node = top;
67 (void) printhashnode(hp, node, bcopywrap, opts);
68 top = node->ipe_next;
69 free(node);
70 printed++;
73 if (printed == 0)
74 putchar(';');
76 if ((opts & OPT_DEBUG) == 0)
77 PRINTF(" };\n");
78 return hp->iph_next;