如何防止内核从mac os x上的原始套接字发送RST数据包?

时间:2010-06-28 17:12:28

标签: c sockets tcp

我正在使用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);
}

我怎样才能让它停下来?我是否需要在使用原始套接字的相同过程中使用该代码?

0 个答案:

没有答案