Skip to content

Instantly share code, notes, and snippets.

@rocammo
Created May 15, 2019 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rocammo/c29989a35dced4714a587ac7f5d454cb to your computer and use it in GitHub Desktop.
Save rocammo/c29989a35dced4714a587ac7f5d454cb to your computer and use it in GitHub Desktop.
Checks if a provided MAC address is valid
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