1 /* $NetBSD: printhash_live.c,v 1.1.1.2 2012/07/22 13:44:40 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 iphtable_t * 15 printhash_live(hp, fd, name, opts, fields) 16 iphtable_t *hp; 17 int fd; 18 char *name; 19 int opts; 20 wordtab_t *fields; 21 { 22 iphtent_t entry, zero; 23 ipflookupiter_t iter; 24 int last, printed; 25 ipfobj_t obj; 26 27 if ((name != NULL) && strncmp(name, hp->iph_name, FR_GROUPLEN)) 28 return hp->iph_next; 29 30 if (fields == NULL) 31 printhashdata(hp, opts); 32 33 if ((hp->iph_flags & IPHASH_DELETE) != 0) 34 PRINTF("# "); 35 36 if ((opts & OPT_DEBUG) == 0) 37 PRINTF("\t{"); 38 39 obj.ipfo_rev = IPFILTER_VERSION; 40 obj.ipfo_type = IPFOBJ_LOOKUPITER; 41 obj.ipfo_ptr = &iter; 42 obj.ipfo_size = sizeof(iter); 43 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); 50 51 last = 0; 52 printed = 0; 53 bzero((char *)&zero, sizeof(zero)); 54 55 while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) { 56 if (entry.ipe_next == NULL) 57 last = 1; 58 if (bcmp(&zero, &entry, sizeof(zero)) == 0) 59 break; 60 (void) printhashnode(hp, &entry, bcopywrap, opts, fields); 61 printed++; 62 } 63 if (last == 0) 64 ipferror(fd, "walking hash nodes:"); 65 66 if (printed == 0) 67 putchar(';'); 68 69 if ((opts & OPT_DEBUG) == 0) 70 PRINTF(" };\n"); 71 return hp->iph_next; 72 } 73