tcpsocktimewait.c (157401) | tcpsocktimewait.c (157402) |
---|---|
1/*- 2 * Copyright (c) 2006 Robert N. M. Watson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 2006 Robert N. M. Watson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/tools/regression/netinet/tcpsocktimewait/tcpsocktimewait.c 157401 2006-04-02 11:03:05Z rwatson $ | 26 * $FreeBSD: head/tools/regression/netinet/tcpsocktimewait/tcpsocktimewait.c 157402 2006-04-02 11:09:37Z rwatson $ |
27 */ 28 29/* 30 * TCP regression test that opens a loopback TCP session, then closes one end 31 * while shutting down the other. This triggers an unusual TCP stack case in 32 * which an open file descriptor / socket is associated with a closed TCP 33 * connection. 34 */ --- 16 unchanged lines hidden (view full) --- 51tcp_server(pid_t partner) 52{ 53 int error, listen_fd, accept_fd; 54 struct sockaddr_in sin; 55 56 listen_fd = socket(PF_INET, SOCK_STREAM, 0); 57 if (listen_fd < 0) { 58 error = errno; | 27 */ 28 29/* 30 * TCP regression test that opens a loopback TCP session, then closes one end 31 * while shutting down the other. This triggers an unusual TCP stack case in 32 * which an open file descriptor / socket is associated with a closed TCP 33 * connection. 34 */ --- 16 unchanged lines hidden (view full) --- 51tcp_server(pid_t partner) 52{ 53 int error, listen_fd, accept_fd; 54 struct sockaddr_in sin; 55 56 listen_fd = socket(PF_INET, SOCK_STREAM, 0); 57 if (listen_fd < 0) { 58 error = errno; |
59 (void)kill(partner, SIGKILL); | 59 (void)kill(partner, SIGTERM); |
60 errno = error; 61 err(-1, "tcp_server: socket"); 62 } 63 64 bzero(&sin, sizeof(sin)); 65 sin.sin_family = AF_INET; 66 sin.sin_len = sizeof(sin); 67 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 68 sin.sin_port = htons(TCP_PORT); 69 70 if (bind(listen_fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { 71 error = errno; | 60 errno = error; 61 err(-1, "tcp_server: socket"); 62 } 63 64 bzero(&sin, sizeof(sin)); 65 sin.sin_family = AF_INET; 66 sin.sin_len = sizeof(sin); 67 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 68 sin.sin_port = htons(TCP_PORT); 69 70 if (bind(listen_fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { 71 error = errno; |
72 (void)kill(partner, SIGKILL); | 72 (void)kill(partner, SIGTERM); |
73 errno = error; 74 err(-1, "tcp_server: bind"); 75 } 76 77 if (listen(listen_fd, -1) < 0) { 78 error = errno; | 73 errno = error; 74 err(-1, "tcp_server: bind"); 75 } 76 77 if (listen(listen_fd, -1) < 0) { 78 error = errno; |
79 (void)kill(partner, SIGKILL); | 79 (void)kill(partner, SIGTERM); |
80 errno = error; 81 err(-1, "tcp_server: listen"); 82 } 83 84 accept_fd = accept(listen_fd, NULL, NULL); 85 if (accept_fd < 0) { 86 error = errno; | 80 errno = error; 81 err(-1, "tcp_server: listen"); 82 } 83 84 accept_fd = accept(listen_fd, NULL, NULL); 85 if (accept_fd < 0) { 86 error = errno; |
87 (void)kill(partner, SIGKILL); | 87 (void)kill(partner, SIGTERM); |
88 errno = error; 89 err(-1, "tcp_server: accept"); 90 } 91 close(accept_fd); 92 close(listen_fd); 93} 94 95static void 96tcp_client(pid_t partner, int secs) 97{ 98 struct sockaddr_in sin; 99 int error, sock; 100 101 sleep(1); 102 103 sock = socket(PF_INET, SOCK_STREAM, 0); 104 if (sock < 0) { 105 error = errno; | 88 errno = error; 89 err(-1, "tcp_server: accept"); 90 } 91 close(accept_fd); 92 close(listen_fd); 93} 94 95static void 96tcp_client(pid_t partner, int secs) 97{ 98 struct sockaddr_in sin; 99 int error, sock; 100 101 sleep(1); 102 103 sock = socket(PF_INET, SOCK_STREAM, 0); 104 if (sock < 0) { 105 error = errno; |
106 (void)kill(partner, SIGKILL); | 106 (void)kill(partner, SIGTERM); |
107 errno = error; 108 err(-1, "socket"); 109 } 110 111 bzero(&sin, sizeof(sin)); 112 sin.sin_family = AF_INET; 113 sin.sin_len = sizeof(sin); 114 sin.sin_addr.s_addr = ntohl(INADDR_LOOPBACK); 115 sin.sin_port = htons(TCP_PORT); 116 117 if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) { 118 error = errno; | 107 errno = error; 108 err(-1, "socket"); 109 } 110 111 bzero(&sin, sizeof(sin)); 112 sin.sin_family = AF_INET; 113 sin.sin_len = sizeof(sin); 114 sin.sin_addr.s_addr = ntohl(INADDR_LOOPBACK); 115 sin.sin_port = htons(TCP_PORT); 116 117 if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) { 118 error = errno; |
119 (void)kill(partner, SIGKILL); | 119 (void)kill(partner, SIGTERM); |
120 errno = error; 121 err(-1, "connect"); 122 } 123 124 if (shutdown(sock, SHUT_RDWR) < 0) { 125 error = errno; | 120 errno = error; 121 err(-1, "connect"); 122 } 123 124 if (shutdown(sock, SHUT_RDWR) < 0) { 125 error = errno; |
126 (void)kill(partner, SIGKILL); | 126 (void)kill(partner, SIGTERM); |
127 errno = error; 128 err(-1, "shutdown"); 129 } 130 131 sleep(secs); 132 close(sock); 133} 134 --- 12 unchanged lines hidden (view full) --- 147 */ 148 parent_pid = getpid(); 149 child_pid = fork(); 150 if (child_pid < 0) 151 err(-1, "fork"); 152 if (child_pid == 0) { 153 child_pid = getpid(); 154 tcp_server(child_pid); | 127 errno = error; 128 err(-1, "shutdown"); 129 } 130 131 sleep(secs); 132 close(sock); 133} 134 --- 12 unchanged lines hidden (view full) --- 147 */ 148 parent_pid = getpid(); 149 child_pid = fork(); 150 if (child_pid < 0) 151 err(-1, "fork"); 152 if (child_pid == 0) { 153 child_pid = getpid(); 154 tcp_server(child_pid); |
155 exit(0); |
|
155 } else 156 tcp_client(parent_pid, 1); | 156 } else 157 tcp_client(parent_pid, 1); |
158 (void)kill(child_pid, SIGTERM); 159 sleep(5); |
|
157 158 parent_pid = getpid(); 159 child_pid = fork(); 160 if (child_pid < 0) 161 err(-1, "fork"); 162 if (child_pid == 0) { 163 child_pid = getpid(); 164 tcp_server(parent_pid); 165 } else 166 tcp_client(child_pid, 800); 167 168 return (0); 169} | 160 161 parent_pid = getpid(); 162 child_pid = fork(); 163 if (child_pid < 0) 164 err(-1, "fork"); 165 if (child_pid == 0) { 166 child_pid = getpid(); 167 tcp_server(parent_pid); 168 } else 169 tcp_client(child_pid, 800); 170 171 return (0); 172} |