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