diff --git a/src/ui/util.c b/src/ui/util.c index df24bde..0d19930 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -30,9 +30,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include #include "util.h" +#include + +regex_t regex; +int reti; +char msgbuf[100]; int find_str(char *find, const char **array, int length) { int i; @@ -86,4 +92,31 @@ int isValidMacAddress(const char* mac) { } return (i == 12 && (s == 5 || s == 0)); -} \ No newline at end of file +} + + +int isValidAcceptedMacs(const char *macs){ + + /* Compile regular expression */ +reti = regcomp(®ex, "^(((([0-9A-Fa-f]{2}):){5}[0-9A-Fa-f]{2}\\s*)(^((([0-9A-Fa-f]{2}):){5}[0-9A-Fa-f]{2}\\s*))*)$", REG_EXTENDED); +if (reti) { + //printf( "Could not compile regex\n"); + return -1; +} + +/* Execute regular expression */ +reti = regexec(®ex, macs, 0, NULL, 0); +if (!reti) { + return 0; +} +else if (reti == REG_NOMATCH) { + //puts("Invalid mac addresses"); + return -1; +} +else { + regerror(reti, ®ex, msgbuf, sizeof(msgbuf)); + //printf("Regex match failed: %s\n", msgbuf); + return -1; +} + +} diff --git a/src/ui/util.h b/src/ui/util.h index 0ccdc0c..7357b88 100644 --- a/src/ui/util.h +++ b/src/ui/util.h @@ -34,5 +34,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. int find_str(char *find, const char **array, int length); void rand_str(char *dest, size_t length); int isValidMacAddress(const char*); +int isValidAcceptedMacs(const char*); #endif //WIHOTSPOT_UTIL_H