C socket 绑定 DNS端口错误
// Create a socket
server_s = socket(AF_INET, SOCK_DGRAM/*SOCK_STREAM*/, IPPROTO_UDP/*0*/);
if(server_s == -1){
fprintf(stderr, "socket error.\n");
exit(-1);
}
// Fill-in my socket's address information and bind the socket
memset(&server_addr, 0, sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(53);
server_addr.sin_addr.s_addr = inet_addr("192.168.137.1");/*htonl(INADDR_BROADCAST);*//*htonl(INADDR_ANY);*/
if(bind(server_s, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1){
fprintf(stderr, "Bind error.\n");
exit(-1);
}
在win7下设置防火墙允许访问53端口,绑定192.168.137.1:80可以顺利实现监听,绑定53后bind便会返回-1错误。为什么绑定会失败? 下面是DNS端口抓包:
锈涩的联装炮
10 years, 6 months ago