printhash_live.c revision 170264
1/* 2 * Copyright (C) 2002 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#define PRINTF (void)printf 12#define FPRINTF (void)fprintf 13 14 15iphtable_t *printhash_live(hp, fd, name, opts) 16iphtable_t *hp; 17int fd; 18char *name; 19int opts; 20{ 21 iphtent_t entry, *top, *node; 22 ipflookupiter_t iter; 23 int printed, last; 24 ipfobj_t obj; 25 26 if ((name != NULL) && strncmp(name, hp->iph_name, FR_GROUPLEN)) 27 return hp->iph_next; 28 29 printhashdata(hp, opts); 30 31 if ((hp->iph_flags & IPHASH_DELETE) != 0) 32 PRINTF("# "); 33 34 if ((opts & OPT_DEBUG) == 0) 35 PRINTF("\t{"); 36 37 obj.ipfo_rev = IPFILTER_VERSION; 38 obj.ipfo_type = IPFOBJ_LOOKUPITER; 39 obj.ipfo_ptr = &iter; 40 obj.ipfo_size = sizeof(iter); 41 42 iter.ili_data = &entry; 43 iter.ili_type = IPLT_HASH; 44 iter.ili_otype = IPFLOOKUPITER_NODE; 45 iter.ili_ival = IPFGENITER_LOOKUP; 46 iter.ili_unit = hp->iph_unit; 47 strncpy(iter.ili_name, hp->iph_name, FR_GROUPLEN); 48 49 last = 0; 50 top = NULL; 51 printed = 0; 52 53 while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) { 54 if (entry.ipe_next == NULL) 55 last = 1; 56 entry.ipe_next = top; 57 top = malloc(sizeof(*top)); 58 if (top == NULL) 59 break; 60 bcopy(&entry, top, sizeof(entry)); 61 } 62 63 while (top != NULL) { 64 node = top; 65 (void) printhashnode(hp, node, bcopywrap, opts); 66 top = node->ipe_next; 67 free(node); 68 printed++; 69 } 70 71 if (printed == 0) 72 putchar(';'); 73 74 if ((opts & OPT_DEBUG) == 0) 75 PRINTF(" };\n"); 76 return hp->iph_next; 77} 78