1 /* $NetBSD: printdstlistnode.c,v 1.1.1.1 2012/03/23 21:20:09 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2010 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 } else { 57 PRINTF("Interface: [%s]/%d\n", np->ipfd_names, 58 np->ipfd_dest.fd_name); 59 #ifdef USE_INET6 60 str = inet_ntop(np->ipfd_dest.fd_addr.adf_family, 61 &np->ipfd_dest.fd_ip6, buf, sizeof(buf) - 1); 62 if (str != NULL) { 63 PRINTF("\tAddress: %s\n", str); 64 } 65 #else 66 PRINTF("\tAddress: %s\n", inet_ntoa(np->ipfd_dest.fd_ip)); 67 #endif 68 PRINTF( 69 #ifdef USE_QUAD_T 70 "\t\tStates %d\tRef %d\tName [%s]\tUid %d\n", 71 #else 72 "\t\tStates %d\tRef %d\tName [%s]\tUid %d\n", 73 #endif 74 np->ipfd_states, np->ipfd_ref, 75 np->ipfd_names, np->ipfd_uid); 76 } 77 free(np); 78 return node.ipfd_next; 79 } 80