// test1.c - the part of TCP states test (FIN_WAIT1 + ESTABLISHED) #include #include #include #include #include #include #include int main(int argc, char *argv[]) { int fd = socket(AF_INET, SOCK_STREAM, 0); int tmp = 100; struct sockaddr_in addr; addr.sin_addr.s_addr = INADDR_ANY; addr.sin_family = AF_INET; addr.sin_port = htons(6666); if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { fprintf(stderr, "bind error\n"); return 1; } if (listen(fd,10) == -1) { fprintf(stderr, "listen error\n"); return 1; } socklen_t size = sizeof(addr); int fd2 = accept(fd, (struct sockaddr*)&addr, &size); if (fd2 == -1) { fprintf(stderr, "accept error\n"); return 1; } fcntl(fd2, F_SETFL, O_NONBLOCK); while (write(fd2,&tmp,sizeof(tmp)) != -1) ; close(fd2); while (1) { sleep(1); } return 0; }