Skip to content

Commit

Permalink
Fix Connection::setMAC pattern (#32)
Browse files Browse the repository at this point in the history
* Fix Connection::setMAC regex pattern

Signed-off-by: lbgracioso <[email protected]>

* Run clang format

Signed-off-by: lbgracioso <[email protected]>

---------

Signed-off-by: lbgracioso <[email protected]>
  • Loading branch information
lbgracioso committed Jan 3, 2024
1 parent 589c31f commit 392b81d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ void Connection::setMAC(std::string_view mac)

// This pattern validates whether an MAC address is valid or not.
const std::regex pattern(
R"regex(^
([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})| # Matches MAC address with colons or hyphens or
([0-9A-Fa-f]{4}\.){2}[0-9A-Fa-f]{4} # Matches Cisco MAC format
$)regex");
"^("
"(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}" // Matches MAC address with
// colons or hyphens
"|"
"(?:[0-9a-fA-F]{4}\\.[0-9a-fA-F]{4}\\.[0-9a-fA-F]{4}" // Matches Cisco
// MAC format
"))$");

// regex_match cannot work with std::string_view
if (std::string tempString { mac }; regex_match(tempString, pattern))
Expand Down

0 comments on commit 392b81d

Please sign in to comment.