1/*	$NetBSD: printhash_live.c,v 1.1.1.2 2008/05/20 06:45:02 darrenr Exp $	*/
2
3/*
4 * Copyright (C) 2002 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#define	PRINTF	(void)printf
14#define	FPRINTF	(void)fprintf
15
16
17iphtable_t *printhash_live(hp, fd, name, opts)
18iphtable_t *hp;
19int fd;
20char *name;
21int opts;
22{
23	iphtent_t entry, *top, *node;
24	ipflookupiter_t iter;
25	int printed, last;
26	ipfobj_t obj;
27
28	if ((name != NULL) && strncmp(name, hp->iph_name, FR_GROUPLEN))
29		return hp->iph_next;
30
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	top = NULL;
53	printed = 0;
54
55	while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) {
56		if (entry.ipe_next == NULL)
57			last = 1;
58		entry.ipe_next = top;
59		top = malloc(sizeof(*top));
60		if (top == NULL)
61			break;
62		bcopy(&entry, top, sizeof(entry));
63	}
64
65	while (top != NULL) {
66		node = top;
67		(void) printhashnode(hp, node, bcopywrap, opts);
68		top = node->ipe_next;
69		free(node);
70		printed++;
71	}
72
73	if (printed == 0)
74		putchar(';');
75
76	if ((opts & OPT_DEBUG) == 0)
77		PRINTF(" };\n");
78	return hp->iph_next;
79}
80