Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Ethereal-dev: [Ethereal-dev] Proposed change to get_addr_name

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "Francisco Alcoba (TS/EEM)" <francisco.alcoba@xxxxxxxxxxxx>
Date: Fri, 4 Feb 2005 10:05:17 +0100
Hi,

get_addr_name, in addr_resolv.c, returns a name corresponding to an address if the address 
supports name resolution, and NULL if not. I've seen it is used only in column-utils, 
conversations_table and hostlist_table. In all three of them, if it returns NULL, the code calls 
address_to_str or address_to_str_buf immediately afterwards. These two return the address 
conversion if they have received a valid address type, or g_assert if they received an AT_NONE.

I think it would be better if get_addr_name would:

 - resolve to a name if the address supports it
 - call address_to_str if it does not, but the address is valid
 - return "NONE" if it is AT_NONE

In that way, the code would not need to check the result. If the code is broken, instead of 
crashing -the way it would now in the mentioned files- it would just print "NONE" wherever an 
address is expected; and it would be possible to do things like 

	g_snprintf(title2, 80, "Reverse: %s:%u to %s:%u (SSRC=%u)",
		get_addr_name(&(user_data->ip_src_rev)),
		user_data->port_src_rev,
		get_addr_name(&(user_data->ip_dst_rev)),
		user_data->port_dst_rev,
		user_data->ssrc_rev);

in RTP Analysis, where the data is not always available -in this case, because there might be a 
forward stream without a reverse one-, without needing to check every time for the existence.

I guess the reason against doing so would be that it enforces code correctness less than a 
g_assert, but having "NONE" instead of the string you expected should be pretty obvious also. 
Would this be OK?

Regards,

  Francisco