xref: /titanic_52/usr/src/cmd/ipf/lib/common/printhashnode.c (revision b6c3f7863936abeae522e48a13887dddeb691a45)
1 /*
2  * Copyright (C) 2002 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
7  * Use is subject to license terms.
8  */
9 
10 #pragma ident	"%Z%%M%	%I%	%E% SMI"
11 
12 #include "ipf.h"
13 
14 #define	PRINTF	(void)printf
15 #define	FPRINTF	(void)fprintf
16 
17 iphtent_t *printhashnode(iph, ipep, copyfunc, opts)
18 iphtable_t *iph;
19 iphtent_t *ipep;
20 copyfunc_t copyfunc;
21 int opts;
22 {
23 	iphtent_t ipe;
24 
25 	if ((*copyfunc)(ipep, &ipe, sizeof(ipe)))
26 		return NULL;
27 
28 	if (ipe.ipe_family == AF_INET) {
29 		ipe.ipe_addr.in4_addr = htonl(ipe.ipe_addr.in4_addr);
30 		ipe.ipe_mask.in4_addr = htonl(ipe.ipe_mask.in4_addr);
31 	}
32 
33 	if ((opts & OPT_DEBUG) != 0) {
34 #ifdef USE_INET6
35 		char addinfo[INET6_ADDRSTRLEN];
36 		PRINTF("\tAddress: %s",
37 			inet_ntop(ipe.ipe_family, (void *)&ipe.ipe_addr.in4,
38 				  addinfo, sizeof(addinfo)));
39 #else
40 		PRINTF("\tAddress: %s",
41 			inet_ntoa(ipe.ipe_addr.in4));
42 #endif
43 #ifdef USE_INET6
44 		if (ipe.ipe_family == AF_INET6)
45 			printmask(6, (u_32_t *)&ipe.ipe_mask.in6);
46 		else
47 #endif
48 			printmask(4, (u_32_t *)&ipe.ipe_mask.in4_addr);
49 
50 		PRINTF("\tRef. Count: %d\tGroup: %s\n", ipe.ipe_ref,
51 			ipe.ipe_group);
52 	} else {
53 		putchar(' ');
54 #ifdef USE_INET6
55 		if (ipe.ipe_family == AF_INET6)
56 			printhostmask(6, (u_32_t *)&ipe.ipe_addr.in6,
57 					 (u_32_t *)&ipe.ipe_mask.in6);
58 		else
59 #endif
60 		{
61 			printip((u_32_t *)&ipe.ipe_addr.in4_addr);
62 			printmask(4, (u_32_t *)&ipe.ipe_mask.in4_addr);
63 		}
64 		if (ipe.ipe_value != 0) {
65 			switch (iph->iph_type & ~IPHASH_ANON)
66 			{
67 			case IPHASH_GROUPMAP :
68 				if (strncmp(ipe.ipe_group, iph->iph_name,
69 					    FR_GROUPLEN))
70 					PRINTF(", group = %s", ipe.ipe_group);
71 				break;
72 			}
73 		}
74 		putchar(';');
75 	}
76 	ipep = ipe.ipe_next;
77 	return ipep;
78 }
79