xref: /freebsd/sbin/ipf/libipf/printpoolnode.c (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
1 /*	$FreeBSD$	*/
2 
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  */
8 
9 #include "ipf.h"
10 
11 
12 ip_pool_node_t *
13 printpoolnode(ip_pool_node_t *np, int opts, wordtab_t *fields)
14 {
15 	int i;
16 
17 	if (fields != NULL) {
18 		for (i = 0; fields[i].w_value != 0; i++) {
19 			printpoolfield(np, IPLT_POOL, i);
20 			if (fields[i + 1].w_value != 0)
21 				printf("\t");
22 		}
23 		printf("\n");
24 	} else if ((opts & OPT_DEBUG) == 0) {
25 		putchar(' ');
26 		if (np->ipn_info == 1)
27 			PRINTF("! ");
28 		printip(np->ipn_addr.adf_family,
29 			(u_32_t *)&np->ipn_addr.adf_addr.in4);
30 		printmask(np->ipn_addr.adf_family,
31 			  (u_32_t *)&np->ipn_mask.adf_addr);
32 	} else {
33 #ifdef USE_INET6
34 		if (np->ipn_addr.adf_family == AF_INET6) {
35 			char buf[INET6_ADDRSTRLEN + 1];
36 			const char *str;
37 
38 			buf[0] = '\0';
39 			str = inet_ntop(AF_INET6, &np->ipn_addr.adf_addr.in6,
40 				buf, sizeof(buf) - 1);
41 			if (str == NULL)
42 				str = "???";
43 			PRINTF("\tAddress: %s%s", np->ipn_info ? "! " : "",
44 				str);
45 		} else if (np->ipn_addr.adf_family == AF_INET) {
46 #else
47 		if (np->ipn_addr.adf_family == AF_INET) {
48 #endif
49 			PRINTF("\tAddress: %s%s", np->ipn_info ? "! " : "",
50 				inet_ntoa(np->ipn_addr.adf_addr.in4));
51 		} else {
52 			PRINTF("\tAddress: family: %d\n",
53 				np->ipn_addr.adf_family);
54 		}
55 		printmask(np->ipn_addr.adf_family,
56 			  (u_32_t *)&np->ipn_mask.adf_addr);
57 #ifdef USE_QUAD_T
58 		PRINTF("\n\t\tHits %"PRIu64"\tBytes %"PRIu64"\tName %s\tRef %d\n",
59 			np->ipn_hits, np->ipn_bytes,
60 			np->ipn_name, np->ipn_ref);
61 #else
62 		PRINTF("\n\t\tHits %lu\tBytes %lu\tName %s\tRef %d\n",
63 			np->ipn_hits, np->ipn_bytes,
64 			np->ipn_name, np->ipn_ref);
65 #endif
66 	}
67 	return (np->ipn_next);
68 }
69