我正在使用TCP的原始套接字。每当数据包发送给我时,我的计算机都会发送一个RST数据包。我尝试了http://udi.posterous.com/suppressing-tcp-rst-on-raw-sockets,但无效:
int main(void) {
struct addrinfo *info, hints, *p;
int status, sock;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
status = getaddrinfo(NULL, "3000", &hints, &info);
if (status != 0) function_error("getaddrinfo", 1);
for (p = info; p; p = p->ai_next) {
sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
if (sock == -1) continue;
if (bind(sock, p->ai_addr, p->ai_addrlen) == -1) continue;
break;
}
if (p == NULL) {
fprintf(stderr, "Can't connect. Error = %d\n", errno);
return 2;
}
freeaddrinfo(info);
if (listen(sock, 10) == -1)
function_error("listen", 3);
while (1) sleep(60);
close(sock);
return 0;
}
void function_error(char *func, int code) {
fprintf(stderr, "%s error: %d\n", func, errno);
exit(code);
}
我怎样才能让它停下来?我是否需要在使用原始套接字的相同过程中使用该代码?