xref: /freebsd-src/sbin/ipf/libipf/printpoolnode.c (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
141edb306SCy Schubert 
241edb306SCy Schubert /*
341edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
441edb306SCy Schubert  *
541edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
641edb306SCy Schubert  */
741edb306SCy Schubert 
841edb306SCy Schubert #include "ipf.h"
941edb306SCy Schubert 
1041edb306SCy Schubert 
1141edb306SCy Schubert ip_pool_node_t *
printpoolnode(ip_pool_node_t * np,int opts,wordtab_t * fields)12efeb8bffSCy Schubert printpoolnode(ip_pool_node_t *np, int opts, wordtab_t *fields)
1341edb306SCy Schubert {
1441edb306SCy Schubert 	int i;
1541edb306SCy Schubert 
1641edb306SCy Schubert 	if (fields != NULL) {
1741edb306SCy Schubert 		for (i = 0; fields[i].w_value != 0; i++) {
1841edb306SCy Schubert 			printpoolfield(np, IPLT_POOL, i);
1941edb306SCy Schubert 			if (fields[i + 1].w_value != 0)
2041edb306SCy Schubert 				printf("\t");
2141edb306SCy Schubert 		}
2241edb306SCy Schubert 		printf("\n");
2341edb306SCy Schubert 	} else if ((opts & OPT_DEBUG) == 0) {
2441edb306SCy Schubert 		putchar(' ');
2541edb306SCy Schubert 		if (np->ipn_info == 1)
2641edb306SCy Schubert 			PRINTF("! ");
2741edb306SCy Schubert 		printip(np->ipn_addr.adf_family,
2841edb306SCy Schubert 			(u_32_t *)&np->ipn_addr.adf_addr.in4);
2941edb306SCy Schubert 		printmask(np->ipn_addr.adf_family,
3041edb306SCy Schubert 			  (u_32_t *)&np->ipn_mask.adf_addr);
3141edb306SCy Schubert 	} else {
3241edb306SCy Schubert #ifdef USE_INET6
3341edb306SCy Schubert 		if (np->ipn_addr.adf_family == AF_INET6) {
3441edb306SCy Schubert 			char buf[INET6_ADDRSTRLEN + 1];
3541edb306SCy Schubert 			const char *str;
3641edb306SCy Schubert 
3741edb306SCy Schubert 			buf[0] = '\0';
3841edb306SCy Schubert 			str = inet_ntop(AF_INET6, &np->ipn_addr.adf_addr.in6,
3941edb306SCy Schubert 				buf, sizeof(buf) - 1);
4041edb306SCy Schubert 			if (str == NULL)
4141edb306SCy Schubert 				str = "???";
4241edb306SCy Schubert 			PRINTF("\tAddress: %s%s", np->ipn_info ? "! " : "",
4341edb306SCy Schubert 				str);
4441edb306SCy Schubert 		} else if (np->ipn_addr.adf_family == AF_INET) {
4541edb306SCy Schubert #else
4641edb306SCy Schubert 		if (np->ipn_addr.adf_family == AF_INET) {
4741edb306SCy Schubert #endif
4841edb306SCy Schubert 			PRINTF("\tAddress: %s%s", np->ipn_info ? "! " : "",
4941edb306SCy Schubert 				inet_ntoa(np->ipn_addr.adf_addr.in4));
5041edb306SCy Schubert 		} else {
5141edb306SCy Schubert 			PRINTF("\tAddress: family: %d\n",
5241edb306SCy Schubert 				np->ipn_addr.adf_family);
5341edb306SCy Schubert 		}
5441edb306SCy Schubert 		printmask(np->ipn_addr.adf_family,
5541edb306SCy Schubert 			  (u_32_t *)&np->ipn_mask.adf_addr);
5641edb306SCy Schubert #ifdef USE_QUAD_T
5741edb306SCy Schubert 		PRINTF("\n\t\tHits %"PRIu64"\tBytes %"PRIu64"\tName %s\tRef %d\n",
5841edb306SCy Schubert 			np->ipn_hits, np->ipn_bytes,
5941edb306SCy Schubert 			np->ipn_name, np->ipn_ref);
6041edb306SCy Schubert #else
6141edb306SCy Schubert 		PRINTF("\n\t\tHits %lu\tBytes %lu\tName %s\tRef %d\n",
6241edb306SCy Schubert 			np->ipn_hits, np->ipn_bytes,
6341edb306SCy Schubert 			np->ipn_name, np->ipn_ref);
6441edb306SCy Schubert #endif
6541edb306SCy Schubert 	}
66*2582ae57SCy Schubert 	return (np->ipn_next);
6741edb306SCy Schubert }
68