1 /* $NetBSD: printpool_live.c,v 1.1.1.2 2012/07/22 13:44:42 darrenr Exp $ */ 2 3 /* 4 * Copyright (C) 2012 by Darren Reed. 5 * 6 * See the IPFILTER.LICENCE file for details on licencing. 7 */ 8 9 #include <sys/ioctl.h> 10 #include "ipf.h" 11 #include "netinet/ipl.h" 12 13 14 ip_pool_t * 15 printpool_live(pool, fd, name, opts, fields) 16 ip_pool_t *pool; 17 int fd; 18 char *name; 19 int opts; 20 wordtab_t *fields; 21 { 22 ip_pool_node_t entry; 23 ipflookupiter_t iter; 24 int printed, last; 25 ipfobj_t obj; 26 27 if ((name != NULL) && strncmp(name, pool->ipo_name, FR_GROUPLEN)) 28 return pool->ipo_next; 29 30 if (fields == NULL) 31 printpooldata(pool, opts); 32 33 if ((pool->ipo_flags & IPOOL_DELETE) != 0) 34 PRINTF("# "); 35 if ((opts & OPT_DEBUG) == 0) 36 PRINTF("\t{"); 37 38 obj.ipfo_rev = IPFILTER_VERSION; 39 obj.ipfo_type = IPFOBJ_LOOKUPITER; 40 obj.ipfo_ptr = &iter; 41 obj.ipfo_size = sizeof(iter); 42 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); 49 50 last = 0; 51 printed = 0; 52 53 if (pool->ipo_list != NULL) { 54 while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) { 55 if (entry.ipn_next == NULL) 56 last = 1; 57 (void) printpoolnode(&entry, opts, fields); 58 if ((opts & OPT_DEBUG) == 0) 59 putchar(';'); 60 printed++; 61 } 62 } 63 64 if (printed == 0) 65 putchar(';'); 66 67 if ((opts & OPT_DEBUG) == 0) 68 PRINTF(" };\n"); 69 70 (void) ioctl(fd,SIOCIPFDELTOK, &iter.ili_key); 71 72 return pool->ipo_next; 73 } 74