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