mirror of
https://github.com/lakinduakash/linux-wifi-hotspot.git
synced 2024-11-21 19:40:11 +00:00
Add function to validate ip address
This commit is contained in:
parent
31f9b44aec
commit
99e4f06374
@ -98,25 +98,56 @@ int isValidMacAddress(const char* mac) {
|
||||
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) {
|
||||
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) {
|
||||
/* Execute regular expression */
|
||||
reti = regexec(®ex, macs, 0, NULL, 0);
|
||||
if (!reti) {
|
||||
return 0;
|
||||
}
|
||||
else if (reti == REG_NOMATCH) {
|
||||
}
|
||||
else if (reti == REG_NOMATCH) {
|
||||
//puts("Invalid mac addresses");
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
regerror(reti, ®ex, msgbuf, sizeof(msgbuf));
|
||||
//printf("Regex match failed: %s\n", msgbuf);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int isValidIPaddress(const char * ip){
|
||||
|
||||
|
||||
/* Compile regular expression */
|
||||
reti = regcomp(®ex,
|
||||
"^([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))."
|
||||
"([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))."
|
||||
"([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))."
|
||||
"([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))$", REG_EXTENDED);
|
||||
if (reti) {
|
||||
//printf( "Could not compile regex\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Execute regular expression */
|
||||
reti = regexec(®ex, ip, 0, NULL, 0);
|
||||
if (!reti) {
|
||||
return 0;
|
||||
}
|
||||
else if (reti == REG_NOMATCH) {
|
||||
//puts("Invalid ip addresses");
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
regerror(reti, ®ex, msgbuf, sizeof(msgbuf));
|
||||
//printf("Regex match failed: %s\n", msgbuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user