summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjakob <>2001-09-02 19:11:46 +0000
committerjakob <>2001-09-02 19:11:46 +0000
commit5b3e056e6db48bf48da609c32dbef8d245f3b012 (patch)
treed3465cfb27f242984c33fa34cc7799281ca57b37 /src
parent96028cf8941691cedc2674d90c1d1f0c2b0d3da1 (diff)
downloadopenbsd-5b3e056e6db48bf48da609c32dbef8d245f3b012.tar.gz
openbsd-5b3e056e6db48bf48da609c32dbef8d245f3b012.tar.bz2
openbsd-5b3e056e6db48bf48da609c32dbef8d245f3b012.zip
KNF + ansi
Diffstat (limited to 'src')
-rw-r--r--src/usr.bin/nc/netcat.c54
1 files changed, 20 insertions, 34 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c
index 5b5202ca78..5e603a7f5e 100644
--- a/src/usr.bin/nc/netcat.c
+++ b/src/usr.bin/nc/netcat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: netcat.c,v 1.36 2001/09/02 19:07:17 jakob Exp $ */ 1/* $OpenBSD: netcat.c,v 1.37 2001/09/02 19:11:46 jakob Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> 3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
4 * 4 *
@@ -79,9 +79,7 @@ int udptest __P((int));
79void usage __P((int)); 79void usage __P((int));
80 80
81int 81int
82main(argc, argv) 82main(int argc, char *argv[])
83 int argc;
84 char *argv[];
85{ 83{
86 int ch, s, ret; 84 int ch, s, ret;
87 char *host, *uport, *endp; 85 char *host, *uport, *endp;
@@ -236,19 +234,18 @@ main(argc, argv)
236 234
237 len = sizeof(z); 235 len = sizeof(z);
238 rv = recvfrom(s, buf, sizeof(buf), MSG_PEEK, 236 rv = recvfrom(s, buf, sizeof(buf), MSG_PEEK,
239 (struct sockaddr *)&z, &len); 237 (struct sockaddr *)&z, &len);
240 if (rv < 0) 238 if (rv < 0)
241 errx(1, "%s", strerror(errno)); 239 errx(1, "%s", strerror(errno));
242 240
243 rv = connect(s, (struct sockaddr *)&z, 241 rv = connect(s, (struct sockaddr *)&z, len);
244 len);
245 if (rv < 0) 242 if (rv < 0)
246 errx(1, "%s", strerror(errno)); 243 errx(1, "%s", strerror(errno));
247 244
248 connfd = s; 245 connfd = s;
249 } else { 246 } else {
250 connfd = accept(s, (struct sockaddr *)&cliaddr, 247 connfd = accept(s, (struct sockaddr *)&cliaddr,
251 &len); 248 &len);
252 } 249 }
253 250
254 readwrite(connfd); 251 readwrite(connfd);
@@ -294,13 +291,13 @@ main(argc, argv)
294 sv = NULL; 291 sv = NULL;
295 else { 292 else {
296 sv = getservbyport( 293 sv = getservbyport(
297 ntohs(atoi(portlist[i])), 294 ntohs(atoi(portlist[i])),
298 uflag ? "udp" : "tcp"); 295 uflag ? "udp" : "tcp");
299 } 296 }
300 297
301 printf("Connection to %s %s port [%s/%s] succeeded!\n", 298 printf("Connection to %s %s port [%s/%s] succeeded!\n",
302 host, portlist[i], uflag ? "udp" : "tcp", 299 host, portlist[i], uflag ? "udp" : "tcp",
303 sv ? sv->s_name : "*"); 300 sv ? sv->s_name : "*");
304 } 301 }
305 if (!zflag) 302 if (!zflag)
306 readwrite(s); 303 readwrite(s);
@@ -319,9 +316,7 @@ main(argc, argv)
319 * port or source address if needed. Return's -1 on failure. 316 * port or source address if needed. Return's -1 on failure.
320 */ 317 */
321int 318int
322remote_connect(host, port, hints) 319remote_connect(char *host, char *port, struct addrinfo hints)
323 char *host, *port;
324 struct addrinfo hints;
325{ 320{
326 struct addrinfo *res, *res0; 321 struct addrinfo *res, *res0;
327 int s, error; 322 int s, error;
@@ -332,7 +327,7 @@ remote_connect(host, port, hints)
332 res0 = res; 327 res0 = res;
333 do { 328 do {
334 if ((s = socket(res0->ai_family, res0->ai_socktype, 329 if ((s = socket(res0->ai_family, res0->ai_socktype,
335 res0->ai_protocol)) < 0) 330 res0->ai_protocol)) < 0)
336 continue; 331 continue;
337 332
338 /* Bind to a local port or source address if specified */ 333 /* Bind to a local port or source address if specified */
@@ -355,7 +350,7 @@ remote_connect(host, port, hints)
355 errx(1, "%s", gai_strerror(error)); 350 errx(1, "%s", gai_strerror(error));
356 351
357 if (bind(s, (struct sockaddr *)ares->ai_addr, 352 if (bind(s, (struct sockaddr *)ares->ai_addr,
358 ares->ai_addrlen) < 0) { 353 ares->ai_addrlen) < 0) {
359 errx(1, "bind failed: %s", strerror(errno)); 354 errx(1, "bind failed: %s", strerror(errno));
360 freeaddrinfo(ares); 355 freeaddrinfo(ares);
361 continue; 356 continue;
@@ -384,9 +379,7 @@ remote_connect(host, port, hints)
384 * address. Return's -1 on failure. 379 * address. Return's -1 on failure.
385 */ 380 */
386int 381int
387local_listen(host, port, hints) 382local_listen(char *host, char *port, struct addrinfo hints)
388 char *host, *port;
389 struct addrinfo hints;
390{ 383{
391 struct addrinfo *res, *res0; 384 struct addrinfo *res, *res0;
392 int s, ret, x = 1; 385 int s, ret, x = 1;
@@ -408,7 +401,7 @@ local_listen(host, port, hints)
408 res0 = res; 401 res0 = res;
409 do { 402 do {
410 if ((s = socket(res0->ai_family, res0->ai_socktype, 403 if ((s = socket(res0->ai_family, res0->ai_socktype,
411 res0->ai_protocol)) == 0) 404 res0->ai_protocol)) == 0)
412 continue; 405 continue;
413 406
414 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); 407 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
@@ -416,7 +409,7 @@ local_listen(host, port, hints)
416 err(1, NULL); 409 err(1, NULL);
417 410
418 if (bind(s, (struct sockaddr *)res0->ai_addr, 411 if (bind(s, (struct sockaddr *)res0->ai_addr,
419 res0->ai_addrlen) == 0) 412 res0->ai_addrlen) == 0)
420 break; 413 break;
421 414
422 close(s); 415 close(s);
@@ -438,8 +431,7 @@ local_listen(host, port, hints)
438 * Loop that polls on the network file descriptor and stdin. 431 * Loop that polls on the network file descriptor and stdin.
439 */ 432 */
440void 433void
441readwrite(nfd) 434readwrite(int nfd)
442 int nfd;
443{ 435{
444 struct pollfd *pfd; 436 struct pollfd *pfd;
445 char buf[BUFSIZ]; 437 char buf[BUFSIZ];
@@ -489,10 +481,7 @@ readwrite(nfd)
489} 481}
490/* Deal with RFC854 WILL/WONT DO/DONT negotiation */ 482/* Deal with RFC854 WILL/WONT DO/DONT negotiation */
491void 483void
492atelnet(nfd, buf, size) 484atelnet(int nfd, unsigned char *buf, unsigned int size)
493 int nfd;
494 unsigned char *buf;
495 unsigned int size;
496{ 485{
497 int ret; 486 int ret;
498 unsigned char *p, *end; 487 unsigned char *p, *end;
@@ -530,8 +519,7 @@ atelnet(nfd, buf, size)
530 * that we should try to connect too. 519 * that we should try to connect too.
531 */ 520 */
532void 521void
533build_ports(p) 522build_ports(char *p)
534 char *p;
535{ 523{
536 char *n, *endp; 524 char *n, *endp;
537 int hi, lo, cp; 525 int hi, lo, cp;
@@ -593,8 +581,7 @@ build_ports(p)
593 * Also fails after around 100 ports checked. 581 * Also fails after around 100 ports checked.
594 */ 582 */
595int 583int
596udptest(s) 584udptest(int s)
597 int s;
598{ 585{
599 int i, rv, ret; 586 int i, rv, ret;
600 587
@@ -633,8 +620,7 @@ help()
633} 620}
634 621
635void 622void
636usage(ret) 623usage(int ret)
637 int ret;
638{ 624{
639 fprintf(stderr, "usage: nc [-46hklnrtuvz] [-i interval] [-p source port]\n"); 625 fprintf(stderr, "usage: nc [-46hklnrtuvz] [-i interval] [-p source port]\n");
640 fprintf(stderr, "\t [-s ip address] [-w timeout] [-x proxy address [:port]]\n"); 626 fprintf(stderr, "\t [-s ip address] [-w timeout] [-x proxy address [:port]]\n");