Fix markup. Fix backslashes to surive roff.
[netbsd-mini2440.git] / dist / ipf / lib / printpool_live.c
blob26dc0c6cb8f02b5df734ef634d43e6c472e64bbb
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 ip_pool_t *printpool_live(pool, fd, name, opts)
18 ip_pool_t *pool;
19 int fd;
20 char *name;
21 int opts;
23 ip_pool_node_t entry, *top, *node;
24 ipflookupiter_t iter;
25 int printed, last;
26 ipfobj_t obj;
28 if ((name != NULL) && strncmp(name, pool->ipo_name, FR_GROUPLEN))
29 return pool->ipo_next;
31 printpooldata(pool, opts);
33 if ((pool->ipo_flags & IPOOL_DELETE) != 0)
34 PRINTF("# ");
35 if ((opts & OPT_DEBUG) == 0)
36 PRINTF("\t{");
38 obj.ipfo_rev = IPFILTER_VERSION;
39 obj.ipfo_type = IPFOBJ_LOOKUPITER;
40 obj.ipfo_ptr = &iter;
41 obj.ipfo_size = sizeof(iter);
43 iter.ili_data = &entry;
44 iter.ili_type = IPLT_POOL;
45 iter.ili_otype = IPFLOOKUPITER_NODE;
46 iter.ili_ival = IPFGENITER_LOOKUP;
47 iter.ili_unit = pool->ipo_unit;
48 strncpy(iter.ili_name, pool->ipo_name, FR_GROUPLEN);
50 last = 0;
51 top = NULL;
52 printed = 0;
54 while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) {
55 if (entry.ipn_next == NULL)
56 last = 1;
57 node = malloc(sizeof(*top));
58 if (node == NULL)
59 break;
60 bcopy(&entry, node, sizeof(entry));
61 node->ipn_next = top;
62 top = node;
65 while (top != NULL) {
66 node = top;
67 (void) printpoolnode(node, opts);
68 if ((opts & OPT_DEBUG) == 0)
69 putchar(';');
70 top = node->ipn_next;
71 free(node);
72 printed++;
75 if (printed == 0)
76 putchar(';');
78 if ((opts & OPT_DEBUG) == 0)
79 PRINTF(" };\n");
81 if (ioctl(fd, SIOCIPFDELTOK, &iter.ili_key) != 0)
82 perror("SIOCIPFDELTOK");
84 return pool->ipo_next;