]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ipfilter/lib/printpool_live.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ipfilter / lib / printpool_live.c
1 /*
2  * Copyright (C) 2012 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  */
6
7 #include <sys/ioctl.h>
8 #include "ipf.h"
9 #include "netinet/ipl.h"
10
11
12 ip_pool_t *
13 printpool_live(pool, fd, name, opts, fields)
14         ip_pool_t *pool;
15         int fd;
16         char *name;
17         int opts;
18         wordtab_t *fields;
19 {
20         ip_pool_node_t entry;
21         ipflookupiter_t iter;
22         int printed, last;
23         ipfobj_t obj;
24
25         if ((name != NULL) && strncmp(name, pool->ipo_name, FR_GROUPLEN))
26                 return pool->ipo_next;
27
28         if (fields == NULL)
29                 printpooldata(pool, opts);
30
31         if ((pool->ipo_flags & IPOOL_DELETE) != 0)
32                 PRINTF("# ");
33         if ((opts & OPT_DEBUG) == 0)
34                 PRINTF("\t{");
35
36         obj.ipfo_rev = IPFILTER_VERSION;
37         obj.ipfo_type = IPFOBJ_LOOKUPITER;
38         obj.ipfo_ptr = &iter;
39         obj.ipfo_size = sizeof(iter);
40
41         iter.ili_data = &entry;
42         iter.ili_type = IPLT_POOL;
43         iter.ili_otype = IPFLOOKUPITER_NODE;
44         iter.ili_ival = IPFGENITER_LOOKUP;
45         iter.ili_unit = pool->ipo_unit;
46         strncpy(iter.ili_name, pool->ipo_name, FR_GROUPLEN);
47
48         last = 0;
49         printed = 0;
50
51         if (pool->ipo_list != NULL) {
52                 while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) {
53                         if (entry.ipn_next == NULL)
54                                 last = 1;
55                         (void) printpoolnode(&entry, opts, fields);
56                         if ((opts & OPT_DEBUG) == 0)
57                                 putchar(';');
58                         printed++;
59                 }
60         }
61
62         if (printed == 0)
63                 putchar(';');
64
65         if ((opts & OPT_DEBUG) == 0)
66                 PRINTF(" };\n");
67
68         (void) ioctl(fd,SIOCIPFDELTOK, &iter.ili_key);
69
70         return pool->ipo_next;
71 }