mirror of
https://github.com/lakinduakash/linux-wifi-hotspot.git
synced 2024-11-10 14:10:10 +00:00
Add mac address validator
This commit is contained in:
parent
0752c84706
commit
487c0cfcb1
@ -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));
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user