我如何仅从 perforce 中检出的文件列表中搜索/grep 字符串。我可以使用以下命令获取我检出的文件列表:p4 opens -a | grep“用户名”..
我使用inet_pton来验证输入IP地址是否有效并且不是全零(0.0.0.0或00.00.0.0).
inet_pton(int af, const char *src, void *dst)
Run Code Online (Sandbox Code Playgroud)
如果输入ip(src)地址是0.0.0.0 inet_pton,则将dst设置为值0.如果src值为00.00.00.00,则dst值不为0,但我得到每个跟踪的随机值.为什么inet_pton将0.00.00.00转换为值0
#include <string.h>
#include <arpa/inet.h>
void main( int argc, char *argv[])
{
int s;
struct in_addr ipvalue;
printf("converting %s to network address \n", argv[1]);
s = inet_pton(AF_INET, argv[1], &ipvalue);
if(s < 0)
printf("inet_pton conversion error \n");
printf("converted value = %x \n", ipvalue.s_addr);
}
Run Code Online (Sandbox Code Playgroud)
样本运行
正确的价值观:
./a.out 10.1.2.3
converting 10.1.2.3 to network address
converted value = 302010a
Run Code Online (Sandbox Code Playgroud)
./a.out 0.0.0.0
converting 0.0.0.0 to network address
converted value = 0
Run Code Online (Sandbox Code Playgroud)
结果不正确:
./a.out 00.00.00.0
converting …Run Code Online (Sandbox Code Playgroud)