xref: /netbsd-src/external/bsd/ipf/dist/lib/printdstlistnode.c (revision c9d5dc6c77aa32fd07899a7a63638e95ffa433dd)
1*c9d5dc6cSdarrenr /*	$NetBSD: printdstlistnode.c,v 1.1.1.2 2012/07/22 13:44:40 darrenr Exp $	*/
2bc4097aaSchristos 
3bc4097aaSchristos /*
4*c9d5dc6cSdarrenr  * Copyright (C) 2012 by Darren Reed.
5bc4097aaSchristos  *
6bc4097aaSchristos  * See the IPFILTER.LICENCE file for details on licencing.
7bc4097aaSchristos  */
8bc4097aaSchristos 
9bc4097aaSchristos #include "ipf.h"
10bc4097aaSchristos 
11bc4097aaSchristos 
12bc4097aaSchristos ipf_dstnode_t *
printdstlistnode(inp,copyfunc,opts,fields)13bc4097aaSchristos printdstlistnode(inp, copyfunc, opts, fields)
14bc4097aaSchristos 	ipf_dstnode_t *inp;
15bc4097aaSchristos 	copyfunc_t copyfunc;
16bc4097aaSchristos 	int opts;
17bc4097aaSchristos 	wordtab_t *fields;
18bc4097aaSchristos {
19bc4097aaSchristos 	ipf_dstnode_t node, *np;
20bc4097aaSchristos 	int i;
21bc4097aaSchristos #ifdef USE_INET6
22bc4097aaSchristos 	char buf[INET6_ADDRSTRLEN+1];
23bc4097aaSchristos 	const char *str;
24bc4097aaSchristos #endif
25bc4097aaSchristos 
26bc4097aaSchristos 	if ((*copyfunc)(inp, &node, sizeof(node)))
27bc4097aaSchristos 		return NULL;
28bc4097aaSchristos 
29bc4097aaSchristos 	np = calloc(1, node.ipfd_size);
30bc4097aaSchristos 	if (np == NULL)
31bc4097aaSchristos 		return node.ipfd_next;
32bc4097aaSchristos 	if ((*copyfunc)(inp, np, node.ipfd_size))
33bc4097aaSchristos 		return NULL;
34bc4097aaSchristos 
35bc4097aaSchristos 	if (fields != NULL) {
36bc4097aaSchristos 		for (i = 0; fields[i].w_value != 0; i++) {
37bc4097aaSchristos 			printpoolfield(np, IPLT_DSTLIST, i);
38bc4097aaSchristos 			if (fields[i + 1].w_value != 0)
39bc4097aaSchristos 				printf("\t");
40bc4097aaSchristos 		}
41bc4097aaSchristos 		printf("\n");
42bc4097aaSchristos 	} else if ((opts & OPT_DEBUG) == 0) {
43bc4097aaSchristos 		putchar(' ');
44*c9d5dc6cSdarrenr 		if (np->ipfd_dest.fd_name >= 0)
45bc4097aaSchristos 			PRINTF("%s:", np->ipfd_names);
46bc4097aaSchristos 		if (np->ipfd_dest.fd_addr.adf_family == AF_INET) {
47bc4097aaSchristos 			printip(AF_INET, (u_32_t *)&np->ipfd_dest.fd_ip);
48bc4097aaSchristos 		} else {
49bc4097aaSchristos #ifdef USE_INET6
50bc4097aaSchristos 			str = inet_ntop(AF_INET6, &np->ipfd_dest.fd_ip6,
51bc4097aaSchristos 					buf, sizeof(buf) - 1);
52bc4097aaSchristos 			if (str != NULL)
53bc4097aaSchristos 				PRINTF("%s", str);
54bc4097aaSchristos #endif
55bc4097aaSchristos 		}
56*c9d5dc6cSdarrenr 		putchar(';');
57bc4097aaSchristos 	} else {
58bc4097aaSchristos 		PRINTF("Interface: [%s]/%d\n", np->ipfd_names,
59bc4097aaSchristos 		       np->ipfd_dest.fd_name);
60bc4097aaSchristos #ifdef USE_INET6
61bc4097aaSchristos 		str = inet_ntop(np->ipfd_dest.fd_addr.adf_family,
62bc4097aaSchristos 				&np->ipfd_dest.fd_ip6, buf, sizeof(buf) - 1);
63bc4097aaSchristos 		if (str != NULL) {
64bc4097aaSchristos 			PRINTF("\tAddress: %s\n", str);
65bc4097aaSchristos 		}
66bc4097aaSchristos #else
67bc4097aaSchristos 		PRINTF("\tAddress: %s\n", inet_ntoa(np->ipfd_dest.fd_ip));
68bc4097aaSchristos #endif
69bc4097aaSchristos 		PRINTF(
70bc4097aaSchristos #ifdef USE_QUAD_T
71bc4097aaSchristos 		       "\t\tStates %d\tRef %d\tName [%s]\tUid %d\n",
72bc4097aaSchristos #else
73bc4097aaSchristos 		       "\t\tStates %d\tRef %d\tName [%s]\tUid %d\n",
74bc4097aaSchristos #endif
75bc4097aaSchristos 		       np->ipfd_states, np->ipfd_ref,
76bc4097aaSchristos 		       np->ipfd_names, np->ipfd_uid);
77bc4097aaSchristos 	}
78bc4097aaSchristos 	free(np);
79bc4097aaSchristos 	return node.ipfd_next;
80bc4097aaSchristos }
81