1 /* 2 * Copyright (C) 2012 by Darren Reed. 3 * 4 * See the IPFILTER.LICENCE file for details on licencing. 5 * 6 * $Id: printnatfield.c,v 1.6.2.2 2012/01/26 05:44:26 darren_r Exp $ 7 */ 8 9 #include "ipf.h" 10 11 wordtab_t natfields[] = { 12 { "all", -2 }, 13 { "ifp0", 1 }, 14 { "ifp1", 2 }, 15 { "mtu0", 3 }, 16 { "mtu1", 4 }, 17 { "ifname0", 5 }, 18 { "ifname1", 6 }, 19 { "sumd0", 7 }, 20 { "sumd1", 8 }, 21 { "pkts0", 9 }, 22 { "pkts1", 10 }, 23 { "bytes0", 11 }, 24 { "bytes1", 12 }, 25 { "proto0", 13 }, 26 { "proto1", 14 }, 27 { "hash0", 15 }, 28 { "hash1", 16 }, 29 { "ref", 17 }, 30 { "rev", 18 }, 31 { "v0", 19 }, 32 { "redir", 20 }, 33 { "use", 21 }, 34 { "ipsumd", 22 }, 35 { "dir", 23 }, 36 { "olddstip", 24 }, 37 { "oldsrcip", 25 }, 38 { "newdstip", 26 }, 39 { "newsrcip", 27 }, 40 { "olddport", 28 }, 41 { "oldsport", 29 }, 42 { "newdport", 30 }, 43 { "newsport", 31 }, 44 { "age", 32 }, 45 { "v1", 33 }, 46 { NULL, 0 } 47 }; 48 49 50 void 51 printnatfield( nat_t *n, int fieldnum) 52 { 53 int i; 54 55 switch (fieldnum) 56 { 57 case -2 : 58 for (i = 1; natfields[i].w_word != NULL; i++) { 59 if (natfields[i].w_value > 0) { 60 printnatfield(n, i); 61 if (natfields[i + 1].w_value > 0) 62 putchar('\t'); 63 } 64 } 65 break; 66 67 case 1: 68 PRINTF("%#lx", (u_long)n->nat_ifps[0]); 69 break; 70 71 case 2: 72 PRINTF("%#lx", (u_long)n->nat_ifps[1]); 73 break; 74 75 case 3: 76 PRINTF("%d", n->nat_mtu[0]); 77 break; 78 79 case 4: 80 PRINTF("%d", n->nat_mtu[1]); 81 break; 82 83 case 5: 84 PRINTF("%s", n->nat_ifnames[0]); 85 break; 86 87 case 6: 88 PRINTF("%s", n->nat_ifnames[1]); 89 break; 90 91 case 7: 92 PRINTF("%d", n->nat_sumd[0]); 93 break; 94 95 case 8: 96 PRINTF("%d", n->nat_sumd[1]); 97 break; 98 99 case 9: 100 #ifdef USE_QUAD_T 101 PRINTF("%"PRIu64"", n->nat_pkts[0]); 102 #else 103 PRINTF("%lu", n->nat_pkts[0]); 104 #endif 105 break; 106 107 case 10: 108 #ifdef USE_QUAD_T 109 PRINTF("%"PRIu64"", n->nat_pkts[1]); 110 #else 111 PRINTF("%lu", n->nat_pkts[1]); 112 #endif 113 break; 114 115 case 11: 116 #ifdef USE_QUAD_T 117 PRINTF("%"PRIu64"", n->nat_bytes[0]); 118 #else 119 PRINTF("%lu", n->nat_bytes[0]); 120 #endif 121 break; 122 123 case 12: 124 #ifdef USE_QUAD_T 125 PRINTF("%"PRIu64"", n->nat_bytes[1]); 126 #else 127 PRINTF("%lu", n->nat_bytes[1]); 128 #endif 129 break; 130 131 case 13: 132 PRINTF("%d", n->nat_pr[0]); 133 break; 134 135 case 14: 136 PRINTF("%d", n->nat_pr[1]); 137 break; 138 139 case 15: 140 PRINTF("%u", n->nat_hv[0]); 141 break; 142 143 case 16: 144 PRINTF("%u", n->nat_hv[1]); 145 break; 146 147 case 17: 148 PRINTF("%d", n->nat_ref); 149 break; 150 151 case 18: 152 PRINTF("%d", n->nat_rev); 153 break; 154 155 case 19: 156 PRINTF("%d", n->nat_v[0]); 157 break; 158 159 case 33: 160 PRINTF("%d", n->nat_v[0]); 161 break; 162 163 case 20: 164 PRINTF("%d", n->nat_redir); 165 break; 166 167 case 21: 168 PRINTF("%d", n->nat_use); 169 break; 170 171 case 22: 172 PRINTF("%u", n->nat_ipsumd); 173 break; 174 175 case 23: 176 PRINTF("%d", n->nat_dir); 177 break; 178 179 case 24: 180 PRINTF("%s", hostname(n->nat_v[0], &n->nat_odstip)); 181 break; 182 183 case 25: 184 PRINTF("%s", hostname(n->nat_v[0], &n->nat_osrcip)); 185 break; 186 187 case 26: 188 PRINTF("%s", hostname(n->nat_v[1], &n->nat_ndstip)); 189 break; 190 191 case 27: 192 PRINTF("%s", hostname(n->nat_v[1], &n->nat_nsrcip)); 193 break; 194 195 case 28: 196 PRINTF("%hu", ntohs(n->nat_odport)); 197 break; 198 199 case 29: 200 PRINTF("%hu", ntohs(n->nat_osport)); 201 break; 202 203 case 30: 204 PRINTF("%hu", ntohs(n->nat_ndport)); 205 break; 206 207 case 31: 208 PRINTF("%hu", ntohs(n->nat_nsport)); 209 break; 210 211 case 32: 212 PRINTF("%u", n->nat_age); 213 break; 214 215 default: 216 break; 217 } 218 } 219