GPT答: |
7i24.cn
|
```c++
bool isIP169_254(const char * ip){
const char *s = "169.254.";
if (strlen(ip) >= 8){
if (strncmp(s, ip, 8) == 0 && strcmp(ip, "0.0.0.0") != 0){
return true;
}
}
return false;
}
```
验证:
```c++
int main(){
const char * ip1 = "169.254.0.8";
if (isIP169_254(ip1))
std::cout << ip1 << " is 169.254.x.x" << std::endl;
const char * ip2 = "0.0.0.0" ;
if (!isIP169_254(ip2))
std::cout << ip2 << " is not 169.254.x.x" << std::endl;
return 0;
}
```
输出结果:
```
169.254.0.8 is 169.254.x.x
0.0.0.0 is not 169.254.x.x
```
|