name decode refactoring: remove solved flag, add resolved name only if actually resolved
Polished a bit ethernet name resolving
1.1 --- a/src/eth_resolv.h Sun Oct 18 01:44:24 2009 +0200
1.2 +++ b/src/eth_resolv.h Sun Oct 18 11:19:15 2009 +0200
1.3 @@ -34,9 +34,12 @@
1.4 /* get_tcp_port returns the TCP port name or "%d" if not found */
1.5 extern char *get_tcp_port (u_int port);
1.6
1.7 -/* get_ether_name returns the logical name if found in ethers files else
1.8 +/* get_ether_name returns the logical name if found in ethers files.
1.9 + if only_ethers is false and the name is NOT in the file, it returns
1.10 "<vendor>_%02x:%02x:%02x" if the vendor code is known else
1.11 - "%02x:%02x:%02x:%02x:%02x:%02x" */
1.12 -extern char *get_ether_name (const u_char * addr);
1.13 + "%02x:%02x:%02x:%02x:%02x:%02x"
1.14 + The caller must make a copy of data.
1.15 + */
1.16 +extern const char *get_ether_name (const u_char * addr, gboolean only_ethers);
1.17
1.18 #endif /* __ETH_RESOLV_H__ */
2.1 --- a/src/names.c Sun Oct 18 01:44:24 2009 +0200
2.2 +++ b/src/names.c Sun Oct 18 11:19:15 2009 +0200
2.3 @@ -44,7 +44,7 @@
2.4 }
2.5 name_add_t;
2.6
2.7 -typedef void (p_func_t) (name_add_t *);
2.8 +typedef gboolean (p_func_t) (name_add_t *);
2.9
2.10 typedef struct
2.11 {
2.12 @@ -53,29 +53,25 @@
2.13 }
2.14 prot_function_t;
2.15
2.16 -static void get_raw_name (name_add_t *nt);
2.17 -static void get_null_name (name_add_t *nt);
2.18 -static void get_linux_sll_name (name_add_t *nt);
2.19 -static void get_link6_name (name_add_t *nt);
2.20 -static void get_llc_name (name_add_t *nt);
2.21 -static void get_arp_name (name_add_t *nt);
2.22 -static void get_ip_name (name_add_t *nt);
2.23 -static void get_ipx_name (name_add_t *nt);
2.24 -static void get_udp_name (name_add_t *nt);
2.25 -static void get_tcp_name (name_add_t *nt);
2.26 -static void get_ipxsap_name (name_add_t *nt);
2.27 -static void get_nbipx_name (name_add_t *nt);
2.28 -static void get_nbss_name (name_add_t *nt);
2.29 -static void get_nbdgm_name (name_add_t *nt);
2.30 +static gboolean get_null_name (name_add_t *nt);
2.31 +static gboolean get_linux_sll_name (name_add_t *nt);
2.32 +static gboolean get_link6_name (name_add_t *nt);
2.33 +static gboolean get_llc_name (name_add_t *nt);
2.34 +static gboolean get_arp_name (name_add_t *nt);
2.35 +static gboolean get_ip_name (name_add_t *nt);
2.36 +static gboolean get_ipx_name (name_add_t *nt);
2.37 +static gboolean get_udp_name (name_add_t *nt);
2.38 +static gboolean get_tcp_name (name_add_t *nt);
2.39 +static gboolean get_ipxsap_name (name_add_t *nt);
2.40 +static gboolean get_nbss_name (name_add_t *nt);
2.41 +static gboolean get_nbdgm_name (name_add_t *nt);
2.42
2.43 -#define KNOWN_PROTS 18
2.44 -
2.45 -static prot_function_t prot_functions_table[KNOWN_PROTS + 1] = {
2.46 +/* not all protocol types can be useful to get a name */
2.47 +static prot_function_t prot_functions_table[] = {
2.48 {"ETH_II", get_link6_name},
2.49 {"802.2", get_link6_name},
2.50 {"802.3", get_link6_name},
2.51 {"ISL", get_link6_name},
2.52 - {"RAW", get_raw_name},
2.53 {"NULL", get_null_name},
2.54 {"LINUX-SLL", get_linux_sll_name},
2.55 {"FDDI", get_link6_name},
2.56 @@ -87,9 +83,11 @@
2.57 {"TCP", get_tcp_name},
2.58 {"UDP", get_udp_name},
2.59 {"IPX-SAP", get_ipxsap_name},
2.60 - {"IPX-NetBIOS", get_nbipx_name},
2.61 {"NETBIOS-SSN", get_nbss_name},
2.62 - {"NETBIOS-DGM", get_nbdgm_name}
2.63 + {"NETBIOS-DGM", get_nbdgm_name},
2.64 +
2.65 + /* terminator entry, must be last */
2.66 + {NULL, NULL}
2.67 };
2.68
2.69 static void missing_data_msg(const name_add_t *nt, const char *pr)
2.70 @@ -106,7 +104,7 @@
2.71 }
2.72
2.73 static void add_name (const gchar * numeric, const gchar * resolved,
2.74 - gboolean solved, const node_id_t *node_id,
2.75 + const node_id_t *node_id,
2.76 const name_add_t *nt);
2.77 static void decode_next(name_add_t *nt);
2.78
2.79 @@ -131,9 +129,8 @@
2.80
2.81 /* initializes decoders info
2.82 * Note: Level 0 means topmost - first usable is 1
2.83 - * We initialize as 0 because decode_next() preincrements
2.84 */
2.85 - nt.decoder.level = 0;
2.86 + nt.decoder.level = 1;
2.87 nt.decoder.tokens = prot_stack;
2.88 nt.decoder.protos = pstk;
2.89
2.90 @@ -152,28 +149,27 @@
2.91 /* initializes proto table */
2.92 guint i;
2.93 prot_functions = g_tree_new ((GCompareFunc) strcmp);
2.94 - for (i = 0; i <= KNOWN_PROTS; i++)
2.95 + for (i = 0; prot_functions_table[i].prot != NULL ; ++i)
2.96 g_tree_insert (prot_functions,
2.97 prot_functions_table[i].prot,
2.98 &(prot_functions_table[i]));
2.99 }
2.100
2.101 g_assert(nt);
2.102 - g_assert(nt->decoder.tokens->protonames[nt->decoder.level]); /* current level must be valid */
2.103 + while (nt->decoder.tokens->protonames[nt->decoder.level])
2.104 + {
2.105 + next_func = g_tree_lookup (prot_functions, nt->decoder.tokens->protonames[nt->decoder.level]);
2.106 + if (next_func)
2.107 + {
2.108 + /* before calling the next decoder, we check for size overflow */
2.109 + if (nt->packet_size <= nt->offset)
2.110 + return;
2.111 +
2.112 + if (! next_func->function (nt))
2.113 + break; /* can't advance further */
2.114 + }
2.115
2.116 - nt->decoder.level++;
2.117 -
2.118 - if (!nt->decoder.tokens->protonames[nt->decoder.level])
2.119 - return; /* no more levels, exit */
2.120 -
2.121 - next_func = g_tree_lookup (prot_functions, nt->decoder.tokens->protonames[nt->decoder.level]);
2.122 - if (next_func)
2.123 - {
2.124 - /* before calling the next decoder, we check for size overflow */
2.125 - if (nt->packet_size <= nt->offset)
2.126 - return;
2.127 -
2.128 - next_func->function (nt);
2.129 + nt->decoder.level++;
2.130 }
2.131 }
2.132
2.133 @@ -228,32 +224,21 @@
2.134 g_memmove(dt, nt->p + nt->offset + disp, sz);
2.135 }
2.136
2.137 -/* Raw is used for ppp and slip. There is actually no information,
2.138 - * so we just jump to the next protocol */
2.139 -static void
2.140 -get_raw_name (name_add_t *nt)
2.141 -{
2.142 - decode_next(nt);
2.143 -} /* get_raw_name */
2.144 -
2.145 /* Null is used for loopback. There is actually no information,
2.146 * so we just jump to the next protocol */
2.147 /* TODO Are we so sure there is actually no information?
2.148 * Then what are those four bytes? */
2.149 -static void
2.150 -get_null_name (name_add_t *nt)
2.151 +static gboolean get_null_name (name_add_t *nt)
2.152 {
2.153 nt->offset += 4;
2.154 -
2.155 - decode_next(nt);
2.156 + return TRUE;
2.157 } /* get_null_name */
2.158
2.159 /* linux-sll is used for ISDN on linux, I believe.
2.160 * Only one of the MAC addresses involved is shown each time,
2.161 * so by now I will simply not try to decode MAC addresses */
2.162 /* TODO Do something useful with the address that shows */
2.163 -static void
2.164 -get_linux_sll_name (name_add_t *nt)
2.165 +static gboolean get_linux_sll_name (name_add_t *nt)
2.166 {
2.167 /* TODO
2.168 * I'm assuming that the header is always size 16. I don't know
2.169 @@ -261,12 +246,11 @@
2.170 * since ethereal is not decoding a couple of bytes, which then
2.171 * seem to be just padding */
2.172 nt->offset += 16;
2.173 -
2.174 - decode_next(nt);
2.175 + return TRUE;
2.176 } /* get_linux_sll_name */
2.177
2.178 /* common handling for ethernet-like data */
2.179 -static void eth_name_common(apemode_t ethmode, name_add_t *nt)
2.180 +static gboolean eth_name_common(apemode_t ethmode, name_add_t *nt)
2.181 {
2.182 const gchar *numeric, *solved;
2.183 gboolean found_in_ethers = FALSE;
2.184 @@ -277,38 +261,23 @@
2.185 fill_node_id(&nt->node_id, ethmode, nt, ethmode+6, 0);
2.186
2.187 numeric = ether_to_str (nt->node_id.addr.eth);
2.188 - solved = get_ether_name (nt->node_id.addr.eth);
2.189
2.190 - /* get_ether_name will return an ethernet address with
2.191 - * the first three numbers substituted with the manufacter
2.192 - * if it cannot find an /etc/ethers entry. If it is so,
2.193 - * then the last 8 characters (for example ab:cd:ef) will
2.194 - * be the same, and we will note that the name hasn't
2.195 - * been solved */
2.196 + /* solved is not NULL only if the address is in ethers file */
2.197 + solved = get_ether_name (nt->node_id.addr.eth, TRUE);
2.198
2.199 - if (numeric && solved)
2.200 - found_in_ethers = strcmp (numeric + strlen (numeric) - 8,
2.201 - solved + strlen (solved) - 8);
2.202 -
2.203 - if (found_in_ethers)
2.204 - add_name (numeric, solved, TRUE, &nt->node_id, nt);
2.205 - else
2.206 - add_name (numeric, solved, FALSE, &nt->node_id, nt);
2.207 + add_name (numeric, solved, &nt->node_id, nt);
2.208
2.209 nt->offset += 14;
2.210 -
2.211 - decode_next(nt);
2.212 + return TRUE;
2.213 }
2.214
2.215 -static void
2.216 -get_link6_name(name_add_t *nt)
2.217 +static gboolean get_link6_name(name_add_t *nt)
2.218 {
2.219 - eth_name_common(LINK6, nt);
2.220 + return eth_name_common(LINK6, nt);
2.221 }
2.222
2.223 /* LLC is the only supported FDDI link layer type */
2.224 -static void
2.225 -get_llc_name (name_add_t *nt)
2.226 +static gboolean get_llc_name (name_add_t *nt)
2.227 {
2.228 /* TODO IMPORTANT
2.229 * We must decode the llc header to calculate the nt->offset
2.230 @@ -319,13 +288,11 @@
2.231 else if (nt->link_type == DLT_EN10MB)
2.232 nt->offset += 3;
2.233 else
2.234 - return;
2.235 -
2.236 - decode_next(nt);
2.237 + return FALSE; /* no further info */
2.238 + return TRUE;
2.239 } /* get_llc_name */
2.240
2.241 -static void
2.242 -get_arp_name (name_add_t *nt)
2.243 +static gboolean get_arp_name (name_add_t *nt)
2.244 {
2.245 guint16 protocol_type;
2.246 guint8 hardware_len, protocol_len;
2.247 @@ -335,23 +302,23 @@
2.248 * Most of the times the callee will be the broadcast
2.249 * address */
2.250 if (nt->dir == INBOUND)
2.251 - return;
2.252 + return FALSE;
2.253
2.254 if (nt->packet_size <= nt->offset + 4)
2.255 {
2.256 missing_data_msg(nt, "ARP");
2.257 - return;
2.258 + return FALSE;
2.259 }
2.260
2.261 /* We only know about IP ARP queries */
2.262 protocol_type = pntohs ((nt->p + nt->offset + 2));
2.263 if (protocol_type != ARPTYPE_IP)
2.264 - return;
2.265 + return FALSE;
2.266
2.267 if (nt->packet_size <= nt->offset + 7)
2.268 {
2.269 missing_data_msg(nt, "ARP");
2.270 - return;
2.271 + return FALSE;
2.272 }
2.273
2.274 hardware_len = *(guint8 *) (nt->p + nt->offset + 4);
2.275 @@ -361,14 +328,14 @@
2.276
2.277 add_name (ip_to_str (nt->node_id.addr.ip4),
2.278 dns_lookup (pntohl (nt->node_id.addr.ip4), TRUE),
2.279 - TRUE, &nt->node_id, nt);
2.280 + &nt->node_id, nt);
2.281
2.282 /* ARP doesn't carry any other protocol on top, so we return
2.283 * directly */
2.284 + return FALSE;
2.285 } /* get_arp_name */
2.286
2.287 -static void
2.288 -get_ip_name (name_add_t *nt)
2.289 +static gboolean get_ip_name (name_add_t *nt)
2.290 {
2.291
2.292 if (nt->dir == INBOUND)
2.293 @@ -378,29 +345,25 @@
2.294
2.295 if (!pref.name_res)
2.296 add_name (ip_to_str (nt->node_id.addr.ip4),
2.297 - ip_to_str (nt->node_id.addr.ip4), FALSE, &nt->node_id, nt);
2.298 + NULL, &nt->node_id, nt);
2.299 else
2.300 {
2.301 add_name (ip_to_str(nt->node_id.addr.ip4),
2.302 dns_lookup(pntohl (nt->node_id.addr.ip4), TRUE),
2.303 - TRUE, &nt->node_id, nt);
2.304 + &nt->node_id, nt);
2.305 }
2.306
2.307 nt->offset += 20;
2.308 -
2.309 - decode_next(nt);
2.310 + return TRUE;
2.311 } /* get_ip_name */
2.312
2.313 -static void
2.314 -get_ipx_name (name_add_t *nt)
2.315 +static gboolean get_ipx_name (name_add_t *nt)
2.316 {
2.317 nt->offset += 30;
2.318 -
2.319 - decode_next(nt);
2.320 + return TRUE;
2.321 }
2.322
2.323 -static void
2.324 -get_tcp_name (name_add_t *nt)
2.325 +static gboolean get_tcp_name (name_add_t *nt)
2.326 {
2.327 guint8 th_off_x2;
2.328 guint8 tcp_len;
2.329 @@ -425,7 +388,7 @@
2.330 get_tcp_port(nt->node_id.addr.tcp4.port)
2.331 );
2.332
2.333 - add_name (numeric_name, resolved_name, TRUE, &nt->node_id, nt);
2.334 + add_name (numeric_name, resolved_name, &nt->node_id, nt);
2.335
2.336 g_free (numeric_name);
2.337 g_free (resolved_name);
2.338 @@ -434,44 +397,40 @@
2.339 if (nt->packet_size <= nt->offset + 14)
2.340 {
2.341 missing_data_msg(nt, "TCP");
2.342 - return;
2.343 + return FALSE;
2.344 }
2.345
2.346 th_off_x2 = *(guint8 *) (nt->p + nt->offset + 12);
2.347 tcp_len = hi_nibble (th_off_x2) * 4; /* TCP header length, in bytes */
2.348 nt->offset += tcp_len;
2.349 -
2.350 - decode_next(nt);
2.351 + return TRUE;
2.352 } /* get_tcp_name */
2.353
2.354
2.355 /* TODO I still have to properly implement this. Right now it's just
2.356 * a placeholder to get to the UDP/NETBIOS-DGM */
2.357 -static void
2.358 -get_udp_name (name_add_t *nt)
2.359 +static gboolean get_udp_name (name_add_t *nt)
2.360 {
2.361 nt->offset += 8;
2.362 -
2.363 - decode_next(nt);
2.364 + return TRUE;
2.365 } /* get_udp_name */
2.366
2.367
2.368 /* TODO SET UP THE id's FOR THIS NETBIOS NAME FUNCTIONS */
2.369 -static void
2.370 -get_ipxsap_name (name_add_t *nt)
2.371 +static gboolean get_ipxsap_name (name_add_t *nt)
2.372 {
2.373 guint16 sap_type;
2.374 guint16 curpos;
2.375 gchar *name;
2.376
2.377 if (nt->packet_size <= nt->offset + 2)
2.378 - return; /* not a real ipxsap packet */
2.379 + return FALSE; /* not a real ipxsap packet */
2.380
2.381 sap_type = pntohs (nt->p + nt->offset);
2.382
2.383 /* we want responses */
2.384 if (sap_type != 0x0002)
2.385 - return;
2.386 + return FALSE;
2.387
2.388 for (curpos = nt->offset + 4; curpos < nt->packet_size ; ++curpos)
2.389 {
2.390 @@ -481,32 +440,26 @@
2.391 if (curpos >= nt->packet_size)
2.392 {
2.393 missing_data_msg(nt, "IPXSAP");
2.394 - return;
2.395 + return FALSE;
2.396 }
2.397
2.398 name = (gchar *) (nt->p + nt->offset + 4);
2.399
2.400 g_my_debug ("Sap name %s found", name);
2.401
2.402 - add_name (name, name, TRUE, &nt->node_id, nt);
2.403 + add_name (name, name, &nt->node_id, nt);
2.404
2.405 + return FALSE; /* no other names */
2.406 } /* get_ipxsap_name */
2.407
2.408 -static void
2.409 -get_nbipx_name (name_add_t *nt)
2.410 -{
2.411 -
2.412 -}
2.413 -
2.414 -static void
2.415 -get_nbss_name (name_add_t *nt)
2.416 +static gboolean get_nbss_name (name_add_t *nt)
2.417 {
2.418 #define SESSION_REQUEST 0x81
2.419
2.420 guint8 mesg_type;
2.421
2.422 if (nt->packet_size < nt->offset + 1)
2.423 - return; /* not a netbios packet */
2.424 + return FALSE; /* not a netbios packet */
2.425
2.426 mesg_type = *(guint8 *) (nt->p + nt->offset);
2.427 nt->offset += 2;
2.428 @@ -524,7 +477,7 @@
2.429 if (nt->packet_size <= nt->offset + 2)
2.430 {
2.431 missing_data_msg(nt, "NBSS");
2.432 - return;
2.433 + return FALSE;
2.434 }
2.435 length = pntohs ((nt->p + nt->offset + 2));
2.436
2.437 @@ -532,7 +485,7 @@
2.438 if (nt->packet_size <= nt->offset + length)
2.439 {
2.440 missing_data_msg(nt, "NBSS");
2.441 - return;
2.442 + return FALSE;
2.443 }
2.444
2.445 name_len = ethereal_nbns_name ((const gchar *)nt->p, nt->offset, nt->packet_size, name, sizeof(name), &name_type);
2.446 @@ -555,18 +508,17 @@
2.447 g_strdup_printf ("%s %s (%s)", name, name + NETBIOS_NAME_LEN - 1,
2.448 get_netbios_host_type (name_type));
2.449
2.450 - add_name (numeric_name, name, TRUE, &nt->node_id, nt);
2.451 + add_name (numeric_name, name, &nt->node_id, nt);
2.452 g_free (numeric_name);
2.453 }
2.454
2.455 nt->offset += length;
2.456 }
2.457
2.458 - decode_next(nt);
2.459 + return TRUE;
2.460 } /* get_nbss_name */
2.461
2.462 -static void
2.463 -get_nbdgm_name (name_add_t *nt)
2.464 +static gboolean get_nbdgm_name (name_add_t *nt)
2.465 {
2.466 guint8 mesg_type;
2.467 gchar *numeric_name = NULL;
2.468 @@ -577,7 +529,7 @@
2.469 guint i = 0;
2.470
2.471 if (nt->packet_size < nt->offset + 1)
2.472 - return; /* not a real nbgdm packet */
2.473 + return FALSE; /* not a real nbgdm packet */
2.474
2.475 mesg_type = *(guint8 *) (nt->p + nt->offset);
2.476
2.477 @@ -618,15 +570,16 @@
2.478 g_strdup_printf ("%s %s (%s)", name, name + NETBIOS_NAME_LEN - 1,
2.479 get_netbios_host_type (name_type));
2.480
2.481 - add_name (numeric_name, name, TRUE, &nt->node_id, nt);
2.482 + add_name (numeric_name, name, &nt->node_id, nt);
2.483 g_free (numeric_name);
2.484 }
2.485 + return FALSE; /* no other names */
2.486 } /* get_nbdgm_name */
2.487
2.488
2.489 static void
2.490 add_name (const gchar * numeric_name, const gchar * resolved_name,
2.491 - gboolean solved, const node_id_t *node_id, const name_add_t *nt)
2.492 + const node_id_t *node_id, const name_add_t *nt)
2.493 {
2.494 protocol_t *protocol = NULL;
2.495 GList *name_item = NULL;
2.496 @@ -655,7 +608,7 @@
2.497 }
2.498
2.499 if (!pref.name_res)
2.500 - node_name_assign(name, numeric_name, numeric_name, FALSE, nt->packet_size);
2.501 + node_name_assign(name, NULL, numeric_name, nt->packet_size);
2.502 else
2.503 - node_name_assign(name, resolved_name, numeric_name, solved, nt->packet_size);
2.504 + node_name_assign(name, resolved_name, numeric_name, nt->packet_size);
2.505 } /* add_name */
3.1 --- a/src/node.c Sun Oct 18 01:44:24 2009 +0200
3.2 +++ b/src/node.c Sun Oct 18 11:19:15 2009 +0200
3.3 @@ -326,7 +326,7 @@
3.4 if (DEBUG_ENABLED)
3.5 {
3.6 gchar *msgname = node_name_dump(name);
3.7 - if (name->solved || !iter->must_resolve || !pref.name_res)
3.8 + if (name->res_name || !iter->must_resolve || !pref.name_res)
3.9 g_my_debug(" found protocol with name [%s]", msgname);
3.10 else
3.11 g_my_debug(" found protocol with UNRESOLVED name [%s], ignored",
3.12 @@ -336,14 +336,18 @@
3.13
3.14 /* If we require this protocol to be solved and it's not,
3.15 * the we have to go on */
3.16 - if (name->solved || !iter->must_resolve || !pref.name_res)
3.17 + if (name->res_name || !iter->must_resolve || !pref.name_res)
3.18 {
3.19 - if (!node->name || strcmp (node->name->str, name->res_name->str))
3.20 + if (name->res_name)
3.21 {
3.22 - g_my_debug (" set node name from %s to %s",
3.23 - (node->name) ? node->name->str : "none",
3.24 - name->res_name->str);
3.25 - g_string_assign (node->name, name->res_name->str);
3.26 + if (!node->name ||
3.27 + strcmp (node->name->str, name->res_name->str))
3.28 + {
3.29 + g_my_debug (" set node name from %s to %s",
3.30 + (node->name) ? node->name->str : "<none>",
3.31 + name->res_name->str);
3.32 + g_string_assign (node->name, name->res_name->str);
3.33 + }
3.34 }
3.35 if (!node->numeric_name ||
3.36 strcmp(node->numeric_name->str, name->numeric_name->str))
4.1 --- a/src/node_id.c Sun Oct 18 01:44:24 2009 +0200
4.2 +++ b/src/node_id.c Sun Oct 18 11:19:15 2009 +0200
4.3 @@ -195,13 +195,13 @@
4.4 }
4.5
4.6 void node_name_assign(name_t * name, const gchar *nm, const gchar *num_nm,
4.7 - gboolean slv, gdouble sz)
4.8 + gdouble sz)
4.9 {
4.10 if (DEBUG_ENABLED)
4.11 {
4.12 gchar *msgid = node_id_dump(&name->node_id);
4.13 g_my_debug(" node_name_assign: id %s, name %s, num.name %s\n",
4.14 - msgid, nm, num_nm);
4.15 + msgid, (nm) ? nm : "<none>", num_nm);
4.16 g_free(msgid);
4.17 }
4.18 g_assert(name);
4.19 @@ -210,12 +210,13 @@
4.20 else
4.21 g_string_assign (name->numeric_name, num_nm);
4.22
4.23 - if (!name->res_name)
4.24 - name->res_name = g_string_new (nm);
4.25 - else
4.26 - g_string_assign (name->res_name, nm);
4.27 -
4.28 - name->solved = slv;
4.29 + if (nm)
4.30 + {
4.31 + if (!name->res_name)
4.32 + name->res_name = g_string_new (nm);
4.33 + else
4.34 + g_string_assign (name->res_name, nm);
4.35 + }
4.36 name->accumulated += sz;
4.37 }
4.38
4.39 @@ -229,8 +230,11 @@
4.40 nid = node_id_dump(&name->node_id);
4.41 msg = g_strdup_printf("node id: %s, name: %s, numeric_name: %s, solved: %d, "
4.42 "accumulated %f",
4.43 - nid, name->res_name->str, name->numeric_name->str,
4.44 - name->solved, name->accumulated);
4.45 + nid,
4.46 + (name->res_name) ? name->res_name->str : "<none>",
4.47 + name->numeric_name->str,
4.48 + name->res_name != NULL,
4.49 + name->accumulated);
4.50 g_free(nid);
4.51 return msg;
4.52 }
5.1 --- a/src/node_id.h Sun Oct 18 01:44:24 2009 +0200
5.2 +++ b/src/node_id.h Sun Oct 18 11:19:15 2009 +0200
5.3 @@ -51,9 +51,8 @@
5.4 typedef struct
5.5 {
5.6 node_id_t node_id;
5.7 - GString *res_name; /* resolved name */
5.8 GString *numeric_name; /* readable version of node_id */
5.9 - gboolean solved; /* true if the name was resolved */
5.10 + GString *res_name; /* resolved name - NULL if not resolved */
5.11 gdouble accumulated; /* total accumulated traffic */
5.12 }
5.13 name_t;
5.14 @@ -61,7 +60,7 @@
5.15 name_t * node_name_create(const node_id_t *node_id);
5.16 void node_name_delete(name_t * name);
5.17 void node_name_assign(name_t * name, const gchar *nm, const gchar *num_nm,
5.18 - gboolean slv, gdouble sz);
5.19 + gdouble sz);
5.20 gint node_name_id_compare(const name_t *a, const name_t *b);
5.21 gint node_name_freq_compare (gconstpointer a, gconstpointer b);
5.22 gchar *node_name_dump(const name_t *name);
6.1 --- a/src/resolv.c Sun Oct 18 01:44:24 2009 +0200
6.2 +++ b/src/resolv.c Sun Oct 18 11:19:15 2009 +0200
6.3 @@ -398,7 +398,7 @@
6.4
6.5 } /* get_ethent */
6.6
6.7 -static ether_t *
6.8 +static const ether_t *
6.9 get_ethbyaddr (const u_char * addr)
6.10 {
6.11
6.12 @@ -461,10 +461,9 @@
6.13
6.14 } /* add_manuf_name */
6.15
6.16 -static hashmanuf_t *
6.17 +static const hashmanuf_t *
6.18 manuf_name_lookup (const u_char * addr)
6.19 {
6.20 -
6.21 hashmanuf_t *tp;
6.22 hashmanuf_t **table = manuf_table;
6.23
6.24 @@ -514,13 +513,13 @@
6.25
6.26 } /* initialize_ethers */
6.27
6.28 -static char *
6.29 -eth_name_lookup (const u_char * addr)
6.30 +static const char *
6.31 +eth_name_lookup (const u_char * addr, gboolean only_ethers)
6.32 {
6.33 - hashmanuf_t *manufp;
6.34 + const hashmanuf_t *manufp;
6.35 hashether_t *tp;
6.36 hashether_t **table = eth_table;
6.37 - ether_t *eth;
6.38 + const ether_t *eth;
6.39 int i, j;
6.40
6.41 j = (addr[2] << 8) | addr[3];
6.42 @@ -540,7 +539,11 @@
6.43 {
6.44 if (memcmp (tp->addr, addr, sizeof (tp->addr)) == 0)
6.45 {
6.46 - return tp->name;
6.47 + /* addr found */
6.48 + if (!only_ethers || tp->is_name_from_file)
6.49 + return tp->name;
6.50 + else
6.51 + return NULL; /* found, but not in ethers file */
6.52 }
6.53 if (tp->next == NULL)
6.54 {
6.55 @@ -554,14 +557,13 @@
6.56 }
6.57
6.58 /* fill in a new entry */
6.59 -
6.60 memcpy (tp->addr, addr, sizeof (tp->addr));
6.61 tp->next = NULL;
6.62
6.63 - if ((eth = get_ethbyaddr (addr)) == NULL)
6.64 + eth = get_ethbyaddr (addr);
6.65 + if (!eth)
6.66 {
6.67 /* unknown name */
6.68 -
6.69 if ((manufp = manuf_name_lookup (addr)) == NULL)
6.70 snprintf (tp->name, MAXNAMELEN, "%s", ether_to_str ((guint8 *) addr));
6.71 else
6.72 @@ -577,7 +579,11 @@
6.73 tp->is_name_from_file = TRUE;
6.74 }
6.75
6.76 - return (tp->name);
6.77 + if (!only_ethers || tp->is_name_from_file)
6.78 + return tp->name;
6.79 +
6.80 + /* name not found in ethers file */
6.81 + return NULL;
6.82
6.83 } /* eth_name_lookup */
6.84
6.85 @@ -588,8 +594,8 @@
6.86 } /* get_tcp_port */
6.87
6.88
6.89 -extern char *
6.90 -get_ether_name (const u_char * addr)
6.91 +extern const char *
6.92 +get_ether_name (const u_char * addr, gboolean only_ethers)
6.93 {
6.94 if (!eth_resolution_initialized)
6.95 {
6.96 @@ -597,7 +603,7 @@
6.97 eth_resolution_initialized = 1;
6.98 }
6.99
6.100 - return eth_name_lookup (addr);
6.101 + return eth_name_lookup (addr, only_ethers);
6.102
6.103 } /* get_ether_name */
6.104