term.c (5579:29cd33ac16cb) | term.c (5580:6be5ac0eb1ea) |
---|---|
1/* $OpenBSD: netcat.c,v 1.57 2002/12/30 18:00:18 stevesk Exp $ */ 2/* 3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> 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 * --- 141 unchanged lines hidden (view full) --- 150 int wfd = fileno(stdin), n, ret, max_fd; 151 int lfd = fileno(stdout); 152 int escape = 0; 153 struct timeval timeout; 154 155 if (nfd == -1) 156 return; 157 | 1/* $OpenBSD: netcat.c,v 1.57 2002/12/30 18:00:18 stevesk Exp $ */ 2/* 3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> 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 * --- 141 unchanged lines hidden (view full) --- 150 int wfd = fileno(stdin), n, ret, max_fd; 151 int lfd = fileno(stdout); 152 int escape = 0; 153 struct timeval timeout; 154 155 if (nfd == -1) 156 return; 157 |
158 FD_ZERO(&read_fds); 159 160 FD_SET(wfd, &read_fds); 161 FD_SET(nfd, &read_fds); | |
162 max_fd = nfd + 1; 163 | 158 max_fd = nfd + 1; 159 |
164 timeout.tv_sec = 1; 165 timeout.tv_usec = 0; 166 | |
167 while (1) { | 160 while (1) { |
161 FD_ZERO(&read_fds); 162 FD_SET(wfd, &read_fds); 163 FD_SET(nfd, &read_fds); 164 timeout.tv_sec = 1; 165 timeout.tv_usec = 0; 166 |
|
168 n = select(max_fd, &read_fds, NULL, NULL, &timeout); 169 if (n < 0) { 170 close(nfd); 171 perror("Select Error:"); 172 } 173 174 if (n == 0) { 175 if (read(nfd, buf, 0) < 0) 176 return; | 167 n = select(max_fd, &read_fds, NULL, NULL, &timeout); 168 if (n < 0) { 169 close(nfd); 170 perror("Select Error:"); 171 } 172 173 if (n == 0) { 174 if (read(nfd, buf, 0) < 0) 175 return; |
177 goto setup_select; | 176 continue; |
178 } 179 180 if (read(nfd, buf, 0) < 0) 181 return; 182 183 if (FD_ISSET(nfd, &read_fds)) { 184 if ((n = read(nfd, buf, sizeof(buf))) < 0) 185 return; --- 27 unchanged lines hidden (view full) --- 213 if (escape) 214 continue; 215 } 216 217 if ((ret = atomicio(write, nfd, buf, n)) != n) 218 return; 219 } 220 } | 177 } 178 179 if (read(nfd, buf, 0) < 0) 180 return; 181 182 if (FD_ISSET(nfd, &read_fds)) { 183 if ((n = read(nfd, buf, sizeof(buf))) < 0) 184 return; --- 27 unchanged lines hidden (view full) --- 212 if (escape) 213 continue; 214 } 215 216 if ((ret = atomicio(write, nfd, buf, n)) != n) 217 return; 218 } 219 } |
221setup_select: 222 FD_ZERO(&read_fds); 223 FD_SET(wfd, &read_fds); 224 FD_SET(nfd, &read_fds); 225 timeout.tv_sec = 1; 226 timeout.tv_usec = 0; | |
227 } // while 228} 229 230void 231usage(int ret) 232{ 233 fprintf(stderr, "usage: %s hostname port\n", progname); 234 if (ret) --- 96 unchanged lines hidden --- | 220 } // while 221} 222 223void 224usage(int ret) 225{ 226 fprintf(stderr, "usage: %s hostname port\n", progname); 227 if (ret) --- 96 unchanged lines hidden --- |