10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * Copyright (C) 2002 by Darren Reed.
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * See the IPFILTER.LICENCE file for details on licencing.
5*637Sml37995  *
6*637Sml37995  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
7*637Sml37995  * Use is subject to license terms.
80Sstevel@tonic-gate  */
90Sstevel@tonic-gate 
10*637Sml37995 #pragma ident	"%Z%%M%	%I%	%E% SMI"
11*637Sml37995 
120Sstevel@tonic-gate #include "ipf.h"
130Sstevel@tonic-gate 
140Sstevel@tonic-gate #define	PRINTF	(void)printf
150Sstevel@tonic-gate #define	FPRINTF	(void)fprintf
160Sstevel@tonic-gate 
170Sstevel@tonic-gate iphtent_t *printhashnode(iph, ipep, copyfunc, opts)
180Sstevel@tonic-gate iphtable_t *iph;
190Sstevel@tonic-gate iphtent_t *ipep;
200Sstevel@tonic-gate copyfunc_t copyfunc;
210Sstevel@tonic-gate int opts;
220Sstevel@tonic-gate {
230Sstevel@tonic-gate 	iphtent_t ipe;
240Sstevel@tonic-gate 
250Sstevel@tonic-gate 	if ((*copyfunc)(ipep, &ipe, sizeof(ipe)))
260Sstevel@tonic-gate 		return NULL;
270Sstevel@tonic-gate 
28*637Sml37995 	if (ipe.ipe_family == AF_INET) {
29*637Sml37995 		ipe.ipe_addr.in4_addr = htonl(ipe.ipe_addr.in4_addr);
30*637Sml37995 		ipe.ipe_mask.in4_addr = htonl(ipe.ipe_mask.in4_addr);
31*637Sml37995 	}
320Sstevel@tonic-gate 
330Sstevel@tonic-gate 	if ((opts & OPT_DEBUG) != 0) {
34*637Sml37995 #ifdef USE_INET6
35*637Sml37995 		char addinfo[INET6_ADDRSTRLEN];
36*637Sml37995 		PRINTF("\tAddress: %s",
37*637Sml37995 			inet_ntop(ipe.ipe_family, (void *)&ipe.ipe_addr.in4,
38*637Sml37995 				  addinfo, sizeof(addinfo)));
39*637Sml37995 #else
400Sstevel@tonic-gate 		PRINTF("\tAddress: %s",
410Sstevel@tonic-gate 			inet_ntoa(ipe.ipe_addr.in4));
42*637Sml37995 #endif
43*637Sml37995 #ifdef USE_INET6
44*637Sml37995 		if (ipe.ipe_family == AF_INET6)
45*637Sml37995 			printmask(6, (u_32_t *)&ipe.ipe_mask.in6);
46*637Sml37995 		else
47*637Sml37995 #endif
48*637Sml37995 			printmask(4, (u_32_t *)&ipe.ipe_mask.in4_addr);
49*637Sml37995 
500Sstevel@tonic-gate 		PRINTF("\tRef. Count: %d\tValue: %d\n", ipe.ipe_ref,
510Sstevel@tonic-gate 			ipe.ipe_value);
520Sstevel@tonic-gate 	} else {
530Sstevel@tonic-gate 		putchar(' ');
54*637Sml37995 #ifdef USE_INET6
55*637Sml37995 		if (ipe.ipe_family == AF_INET6)
56*637Sml37995 			printhostmask(6, (u_32_t *)&ipe.ipe_addr.in6,
57*637Sml37995 					 (u_32_t *)&ipe.ipe_mask.in6);
58*637Sml37995 		else
59*637Sml37995 #endif
60*637Sml37995 		{
61*637Sml37995 			printip((u_32_t *)&ipe.ipe_addr.in4_addr);
62*637Sml37995 			printmask(4, (u_32_t *)&ipe.ipe_mask.in4_addr);
63*637Sml37995 		}
640Sstevel@tonic-gate 		if (ipe.ipe_value != 0) {
650Sstevel@tonic-gate 			switch (iph->iph_type & ~IPHASH_ANON)
660Sstevel@tonic-gate 			{
670Sstevel@tonic-gate 			case IPHASH_GROUPMAP :
680Sstevel@tonic-gate 				PRINTF(", group = %s", ipe.ipe_group);
690Sstevel@tonic-gate 					break;
700Sstevel@tonic-gate 			}
710Sstevel@tonic-gate 		}
720Sstevel@tonic-gate 		putchar(';');
730Sstevel@tonic-gate 	}
740Sstevel@tonic-gate 	ipep = ipe.ipe_next;
750Sstevel@tonic-gate 	return ipep;
760Sstevel@tonic-gate }
77