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

Ethereal-dev: Re: [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: Guy Harris <gharris@xxxxxxxxx>
Date: Fri, 04 Feb 2005 02:06:02 -0800
Francisco Alcoba (TS/EEM) wrote:

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.

In the case of "address_to_str_buf()", the address conversion is copied into the buffer supplied as an argument.

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

I'd vote for:

	an internal routine that does what "get_addr_name()" does now;

"get_addr_name()", which would work as you describe, calling that internal routine and, if that fails, calling "address_to_str()";

"get_addr_name_buf()", which would take a buffer pointer *and* a buffer size, and would call the internal routine and

if that succeeds, "strncpy()" to the specified buffer using the specified size;

		if that fails, call "address_to_str_buf()";

to avoid an extra string copy.