Created
May 15, 2019 12:43
-
-
Save rocammo/c29989a35dced4714a587ac7f5d454cb to your computer and use it in GitHub Desktop.
Checks if a provided MAC address is valid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool check_valid_mac(u_char *mac) { | |
/* Check for the colons */ | |
for (int i = 2; i < strlen((char*)mac); i += 3) { | |
if (mac[i] != ':') { | |
return false; | |
} | |
} | |
/* Check that the rest are valid characters */ | |
for (int i = 0; i < strlen((char*)mac); i++) { | |
if (mac[i] != ':') { | |
if (!isalpha(mac[i]) && !isdigit(mac[i])) { | |
return false; | |
} | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment