Add mac address validator

This commit is contained in:
lakinduakash 2019-04-17 20:10:24 +05:30
parent 0752c84706
commit 487c0cfcb1
2 changed files with 29 additions and 0 deletions

View File

@ -5,6 +5,7 @@
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include "util.h"
int find_str(char *find, const char **array, int length) {
@ -33,3 +34,30 @@ void rand_str(char *dest, size_t length) {
}
*dest = '\0';
}
int isValidMacAddress(const char* mac) {
int i = 0;
int s = 0;
while (*mac) {
if (isxdigit(*mac)) {
i++;
}
else if (*mac == ':' || *mac == '-') {
if (i == 0 || i / 2 - 1 != s)
break;
++s;
}
else {
s = -1;
}
++mac;
}
return (i == 12 && (s == 5 || s == 0));
}

View File

@ -7,5 +7,6 @@
int find_str(char *find, const char **array, int length);
void rand_str(char *dest, size_t length);
int isValidMacAddress(const char*);
#endif //WIHOTSPOT_UTIL_H