判斷IP地址,MAC地址合法性-C語言
阿新 • • 發佈:2019-02-08
int isValidMac(char *value)
{
int r; //r=0:valid, else not valid
char *reg="^[0-9A-F]\\([0-9A-F]\\:[0-9A-F]\\)\\{5\\}[0-9A-F]$";
r=ereg(reg,value);
return r;
}
int isValidIp(char *value)
{ int r; //r=0:valid, else not valid char *reg="^[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}$"; r=ereg(reg,value); return r; }
int ereg(char *pattern, char *value)
{
int r,cflags=0;
regmatch_t pm[10];
const size_t nmatch = 10;
regex_t reg;
r=regcomp(®, pattern, cflags);
if(r==0){
r=regexec(®, value, nmatch, pm, cflags);
}
regfree(®);
return r;
}