17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (C) 2002 by Darren Reed.
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * See the IPFILTER.LICENCE file for details on licencing.
57663b816Sml  *
6*de22af4eSJohn Ojemann  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
77c478bd9Sstevel@tonic-gate  */
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate #include "ipf.h"
107c478bd9Sstevel@tonic-gate 
117c478bd9Sstevel@tonic-gate #define	PRINTF	(void)printf
127c478bd9Sstevel@tonic-gate #define	FPRINTF	(void)fprintf
137c478bd9Sstevel@tonic-gate 
printhashnode(iph,ipep,copyfunc,opts)147c478bd9Sstevel@tonic-gate iphtent_t *printhashnode(iph, ipep, copyfunc, opts)
157c478bd9Sstevel@tonic-gate iphtable_t *iph;
167c478bd9Sstevel@tonic-gate iphtent_t *ipep;
177c478bd9Sstevel@tonic-gate copyfunc_t copyfunc;
187c478bd9Sstevel@tonic-gate int opts;
197c478bd9Sstevel@tonic-gate {
207c478bd9Sstevel@tonic-gate 	iphtent_t ipe;
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate 	if ((*copyfunc)(ipep, &ipe, sizeof(ipe)))
237c478bd9Sstevel@tonic-gate 		return NULL;
247c478bd9Sstevel@tonic-gate 
257663b816Sml 	if (ipe.ipe_family == AF_INET) {
267663b816Sml 		ipe.ipe_addr.in4_addr = htonl(ipe.ipe_addr.in4_addr);
277663b816Sml 		ipe.ipe_mask.in4_addr = htonl(ipe.ipe_mask.in4_addr);
287663b816Sml 	}
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 	if ((opts & OPT_DEBUG) != 0) {
317663b816Sml #ifdef USE_INET6
327663b816Sml 		char addinfo[INET6_ADDRSTRLEN];
337663b816Sml 		PRINTF("\tAddress: %s",
347663b816Sml 			inet_ntop(ipe.ipe_family, (void *)&ipe.ipe_addr.in4,
357663b816Sml 				  addinfo, sizeof(addinfo)));
367663b816Sml #else
377c478bd9Sstevel@tonic-gate 		PRINTF("\tAddress: %s",
387c478bd9Sstevel@tonic-gate 			inet_ntoa(ipe.ipe_addr.in4));
397663b816Sml #endif
407663b816Sml #ifdef USE_INET6
417663b816Sml 		if (ipe.ipe_family == AF_INET6)
427663b816Sml 			printmask(6, (u_32_t *)&ipe.ipe_mask.in6);
437663b816Sml 		else
447663b816Sml #endif
457663b816Sml 			printmask(4, (u_32_t *)&ipe.ipe_mask.in4_addr);
467663b816Sml 
47*de22af4eSJohn Ojemann #ifdef USE_QUAD_T
48*de22af4eSJohn Ojemann 		PRINTF("\tHits %qu\tBytes %qu", ipe.ipe_hits, ipe.ipe_bytes);
49*de22af4eSJohn Ojemann #else
50*de22af4eSJohn Ojemann 		PRINTF("\tHits %lu\tBytes %lu", ipe.ipe_hits, ipe.ipe_bytes);
51*de22af4eSJohn Ojemann #endif
52ab25eeb5Syz 		PRINTF("\tRef. Count: %d\tGroup: %s\n", ipe.ipe_ref,
53ab25eeb5Syz 			ipe.ipe_group);
547c478bd9Sstevel@tonic-gate 	} else {
557c478bd9Sstevel@tonic-gate 		putchar(' ');
567663b816Sml #ifdef USE_INET6
577663b816Sml 		if (ipe.ipe_family == AF_INET6)
587663b816Sml 			printhostmask(6, (u_32_t *)&ipe.ipe_addr.in6,
597663b816Sml 					 (u_32_t *)&ipe.ipe_mask.in6);
607663b816Sml 		else
617663b816Sml #endif
627663b816Sml 		{
637663b816Sml 			printip((u_32_t *)&ipe.ipe_addr.in4_addr);
647663b816Sml 			printmask(4, (u_32_t *)&ipe.ipe_mask.in4_addr);
657663b816Sml 		}
667c478bd9Sstevel@tonic-gate 		if (ipe.ipe_value != 0) {
677c478bd9Sstevel@tonic-gate 			switch (iph->iph_type & ~IPHASH_ANON)
687c478bd9Sstevel@tonic-gate 			{
697c478bd9Sstevel@tonic-gate 			case IPHASH_GROUPMAP :
70ab25eeb5Syz 				if (strncmp(ipe.ipe_group, iph->iph_name,
71ab25eeb5Syz 					    FR_GROUPLEN))
72ab25eeb5Syz 					PRINTF(", group = %s", ipe.ipe_group);
73ab25eeb5Syz 				break;
747c478bd9Sstevel@tonic-gate 			}
757c478bd9Sstevel@tonic-gate 		}
767c478bd9Sstevel@tonic-gate 		putchar(';');
777c478bd9Sstevel@tonic-gate 	}
787c478bd9Sstevel@tonic-gate 	ipep = ipe.ipe_next;
797c478bd9Sstevel@tonic-gate 	return ipep;
807c478bd9Sstevel@tonic-gate }
81