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