Skip to content

Commit

Permalink
Makes the separator character configurable in mac_to_string helper fu…
Browse files Browse the repository at this point in the history
…nction. (#668)
  • Loading branch information
balazsracz authored Oct 16, 2022
1 parent 01cde51 commit 5c78956
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/utils/format_utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ string string_to_hex(const string &arg)
return ret;
}

string mac_to_string(uint8_t mac[6], bool colon)
string mac_to_string(uint8_t mac[6], char colon)
{
string ret;
ret.reserve(12+6);
Expand All @@ -257,7 +257,7 @@ string mac_to_string(uint8_t mac[6], bool colon)
ret += tmp;
if (colon)
{
ret.push_back(':');
ret.push_back(colon);
}
}
if (colon)
Expand Down
11 changes: 6 additions & 5 deletions src/utils/format_utils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,14 @@ string string_to_hex(const string& arg);
///
/// @param mac a 6-byte array storing the MAC address. mac[0] will be printed
/// at the beginning.
/// @param colons true to print colons, else false to exclude the colon
/// seperators
/// @param colons Specifies byte separators. Leave as default (':') to print
/// colons, an alternate character to use as separator, or set to 0 to exclude
/// the seperators entirely.
///
/// @return a string containing a colon-separated hexadecimal printout of the
/// given MAC address.
/// @return a string containing a hexadecimal printout of the given MAC
/// address.
///
string mac_to_string(uint8_t mac[6], bool colons = true);
string mac_to_string(uint8_t mac[6], char colon = ':');

/// Formats an IPv4 address to string.
///
Expand Down

0 comments on commit 5c78956

Please sign in to comment.