工作中遇到的一個bug:web前台下發非ip地址導致web退出登錄
增加后台對ip地址的合法性校驗
1 #include <regex> 2 static bool IsIp(const char *ip) { 3 if (ip == NULL) { 4 return false; 5 } 6 std::regex pattern("(?=(\\b|\\D))(((\\d{1,2})|(1\\d{1,2})|(2[0-4]\\d)|(25[0-5]))\\.){3}((\\d{1,2})|(1\\d{1,2})|(2[0-4]\\d)|(25[0-5]))(?=(\\b|\\D))"); 7 if (std::regex_match(ip, pattern)) { 8 return true; 9 } 10 return false; 11 }