Skip to content

Commit

Permalink
Parse MAC addresses like ecf4-bb37-ddaa
Browse files Browse the repository at this point in the history
Fixes #6109
  • Loading branch information
jrouzierinverse committed Jan 27, 2021
1 parent 58c10ac commit 0706b6e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go/mac/mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (mac *Mac) InitFromString(s string) error {
}
x += 3
}
case length >= 14 && s[4] == '.':
case length >= 14 && (s[4] == '.' || s[4] == '-'):
// 0123.4567.89ab
// xxxx.xxxx.xxxx
for i, x := 0, 0; i < 14; i += 5 {
Expand Down
16 changes: 15 additions & 1 deletion go/mac/mac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestStringify(t *testing.T) {
{nil, "1122.3344.5566", "11:22:33:44:55:66", "17.34.51.68.85.102", 0x0001112233445566},
{nil, "a00000000009", "a0:00:00:00:00:09", "160.0.0.0.0.9", 0x0001a00000000009},
{nil, "1122.3344.5566:Bob SSID", "11:22:33:44:55:66", "17.34.51.68.85.102", 0x0001112233445566},
{nil, "1122-3344-5566:Bob SSID", "11:22:33:44:55:66", "17.34.51.68.85.102", 0x0001112233445566},
{nil, "112.233.445.566", "11:22:33:44:55:66", "17.34.51.68.85.102", 0x0001112233445566},
{nil, "112.233.445.566:Bob SSID", "11:22:33:44:55:66", "17.34.51.68.85.102", 0x0001112233445566},
{nil, "11:22:33:44:55:66", "11:22:33:44:55:66", "17.34.51.68.85.102", 0x0001112233445566},
Expand All @@ -58,7 +59,20 @@ func TestStringify(t *testing.T) {
for i, test := range newFromStringTests {
mac, err := NewFromString(test.fromStr)
if err != test.err {
t.Errorf("Test %d) Error is not valid expected '%s', got '%s'.", i, test.err, err)
var expectedStr, gotStr string
if test.err != nil {
expectedStr = test.err.Error()
} else {
expectedStr = "nil"
}

if err != nil {
gotStr = err.Error()
} else {
gotStr = "nil"
}

t.Errorf("Test %d) Error is not valid expected '%s', got '%s'.", i, expectedStr, gotStr)
}

if mac.String() != test.macStr {
Expand Down

0 comments on commit 0706b6e

Please sign in to comment.