xref: /freebsd-src/sbin/ipf/libipf/printdstlistnode.c (revision 44bc30192139b0b3c95510ab3b35802bcc6d63e4)
141edb306SCy Schubert /*
241edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
341edb306SCy Schubert  *
441edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
541edb306SCy Schubert  */
641edb306SCy Schubert 
741edb306SCy Schubert #include "ipf.h"
841edb306SCy Schubert 
941edb306SCy Schubert 
1041edb306SCy Schubert ipf_dstnode_t *
printdstlistnode(ipf_dstnode_t * inp,copyfunc_t copyfunc,int opts,wordtab_t * fields)11efeb8bffSCy Schubert printdstlistnode(ipf_dstnode_t *inp, copyfunc_t copyfunc, int opts,
12efeb8bffSCy Schubert 	wordtab_t *fields)
1341edb306SCy Schubert {
1441edb306SCy Schubert 	ipf_dstnode_t node, *np;
1541edb306SCy Schubert 	int i;
1641edb306SCy Schubert #ifdef USE_INET6
1741edb306SCy Schubert 	char buf[INET6_ADDRSTRLEN+1];
1841edb306SCy Schubert 	const char *str;
1941edb306SCy Schubert #endif
2041edb306SCy Schubert 
2141edb306SCy Schubert 	if ((*copyfunc)(inp, &node, sizeof(node)))
22*2582ae57SCy Schubert 		return (NULL);
2341edb306SCy Schubert 
2441edb306SCy Schubert 	np = calloc(1, node.ipfd_size);
2541edb306SCy Schubert 	if (np == NULL)
26*2582ae57SCy Schubert 		return (node.ipfd_next);
2741edb306SCy Schubert 	if ((*copyfunc)(inp, np, node.ipfd_size))
28*2582ae57SCy Schubert 		return (NULL);
2941edb306SCy Schubert 
3041edb306SCy Schubert 	if (fields != NULL) {
3141edb306SCy Schubert 		for (i = 0; fields[i].w_value != 0; i++) {
3241edb306SCy Schubert 			printpoolfield(np, IPLT_DSTLIST, i);
3341edb306SCy Schubert 			if (fields[i + 1].w_value != 0)
3441edb306SCy Schubert 				printf("\t");
3541edb306SCy Schubert 		}
3641edb306SCy Schubert 		printf("\n");
3741edb306SCy Schubert 	} else if ((opts & OPT_DEBUG) == 0) {
3841edb306SCy Schubert 		putchar(' ');
3941edb306SCy Schubert 		if (np->ipfd_dest.fd_name >= 0)
4041edb306SCy Schubert 			PRINTF("%s:", np->ipfd_names);
4141edb306SCy Schubert 		if (np->ipfd_dest.fd_addr.adf_family == AF_INET) {
4241edb306SCy Schubert 			printip(AF_INET, (u_32_t *)&np->ipfd_dest.fd_ip);
4341edb306SCy Schubert 		} else {
4441edb306SCy Schubert #ifdef USE_INET6
4541edb306SCy Schubert 			str = inet_ntop(AF_INET6, &np->ipfd_dest.fd_ip6,
4641edb306SCy Schubert 					buf, sizeof(buf) - 1);
4741edb306SCy Schubert 			if (str != NULL)
4841edb306SCy Schubert 				PRINTF("%s", str);
4941edb306SCy Schubert #endif
5041edb306SCy Schubert 		}
5141edb306SCy Schubert 		putchar(';');
5241edb306SCy Schubert 	} else {
5341edb306SCy Schubert 		PRINTF("Interface: [%s]/%d\n", np->ipfd_names,
5441edb306SCy Schubert 		       np->ipfd_dest.fd_name);
5541edb306SCy Schubert #ifdef USE_INET6
5641edb306SCy Schubert 		str = inet_ntop(np->ipfd_dest.fd_addr.adf_family,
5741edb306SCy Schubert 				&np->ipfd_dest.fd_ip6, buf, sizeof(buf) - 1);
5841edb306SCy Schubert 		if (str != NULL) {
5941edb306SCy Schubert 			PRINTF("\tAddress: %s\n", str);
6041edb306SCy Schubert 		}
6141edb306SCy Schubert #else
6241edb306SCy Schubert 		PRINTF("\tAddress: %s\n", inet_ntoa(np->ipfd_dest.fd_ip));
6341edb306SCy Schubert #endif
6441edb306SCy Schubert 		PRINTF(
6541edb306SCy Schubert #ifdef USE_QUAD_T
6641edb306SCy Schubert 		       "\t\tStates %d\tRef %d\tName [%s]\tUid %d\n",
6741edb306SCy Schubert #else
6841edb306SCy Schubert 		       "\t\tStates %d\tRef %d\tName [%s]\tUid %d\n",
6941edb306SCy Schubert #endif
7041edb306SCy Schubert 		       np->ipfd_states, np->ipfd_ref,
7141edb306SCy Schubert 		       np->ipfd_names, np->ipfd_uid);
7241edb306SCy Schubert 	}
7341edb306SCy Schubert 	free(np);
74*2582ae57SCy Schubert 	return (node.ipfd_next);
7541edb306SCy Schubert }
76