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 max_fd = nfd + 1; 159 |
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 |
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; |
176 continue; |
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 } |
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 --- |