diff options
author | vincent <> | 2002-07-01 15:40:40 +0000 |
---|---|---|
committer | vincent <> | 2002-07-01 15:40:40 +0000 |
commit | 2684b388137a84a7908486fee2ca8825bb711ed0 (patch) | |
tree | c0f692266e2340ed4b85bd84e9687d40abe547f0 /src/usr.bin | |
parent | 6ab363350120175a35ec0eb4710d1bc9182dd9ce (diff) | |
download | openbsd-2684b388137a84a7908486fee2ca8825bb711ed0.tar.gz openbsd-2684b388137a84a7908486fee2ca8825bb711ed0.tar.bz2 openbsd-2684b388137a84a7908486fee2ca8825bb711ed0.zip |
use SUN_LEN to calculate AF_UNIX sockaddr's length. + some style
ok ericj@
Diffstat (limited to 'src/usr.bin')
-rw-r--r-- | src/usr.bin/nc/netcat.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index 67e33de490..c0eb685d02 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.49 2002/05/30 09:37:38 hugh Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.50 2002/07/01 15:40:40 vincent Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
4 | * | 4 | * |
@@ -213,7 +213,7 @@ main(int argc, char *argv[]) | |||
213 | if (nflag) | 213 | if (nflag) |
214 | hints.ai_flags |= AI_NUMERICHOST; | 214 | hints.ai_flags |= AI_NUMERICHOST; |
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | if (xflag) { | 218 | if (xflag) { |
219 | if (uflag) | 219 | if (uflag) |
@@ -309,7 +309,6 @@ main(int argc, char *argv[]) | |||
309 | 309 | ||
310 | /* Cycle through portlist, connecting to each port */ | 310 | /* Cycle through portlist, connecting to each port */ |
311 | for (i = 0; portlist[i] != NULL; i++) { | 311 | for (i = 0; portlist[i] != NULL; i++) { |
312 | |||
313 | if (s) | 312 | if (s) |
314 | close(s); | 313 | close(s); |
315 | 314 | ||
@@ -326,7 +325,7 @@ main(int argc, char *argv[]) | |||
326 | if (vflag || zflag) { | 325 | if (vflag || zflag) { |
327 | /* For UDP, make sure we are connected */ | 326 | /* For UDP, make sure we are connected */ |
328 | if (uflag) { | 327 | if (uflag) { |
329 | if ((udptest(s)) == -1) { | 328 | if (udptest(s) == -1) { |
330 | ret = 1; | 329 | ret = 1; |
331 | continue; | 330 | continue; |
332 | } | 331 | } |
@@ -340,7 +339,7 @@ main(int argc, char *argv[]) | |||
340 | ntohs(atoi(portlist[i])), | 339 | ntohs(atoi(portlist[i])), |
341 | uflag ? "udp" : "tcp"); | 340 | uflag ? "udp" : "tcp"); |
342 | } | 341 | } |
343 | 342 | ||
344 | printf("Connection to %s %s port [%s/%s] succeeded!\n", | 343 | printf("Connection to %s %s port [%s/%s] succeeded!\n", |
345 | host, portlist[i], uflag ? "udp" : "tcp", | 344 | host, portlist[i], uflag ? "udp" : "tcp", |
346 | sv ? sv->s_name : "*"); | 345 | sv ? sv->s_name : "*"); |
@@ -367,20 +366,18 @@ unix_connect(char *path) | |||
367 | int s; | 366 | int s; |
368 | 367 | ||
369 | if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) | 368 | if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) |
370 | return (-1); | 369 | return (-1); |
371 | (void)fcntl(s, F_SETFD, 1); | 370 | (void)fcntl(s, F_SETFD, 1); |
372 | 371 | ||
373 | memset(&sun, 0, sizeof(struct sockaddr_un)); | 372 | memset(&sun, 0, sizeof(struct sockaddr_un)); |
374 | sun.sun_len = sizeof(path); | ||
375 | sun.sun_family = AF_UNIX; | 373 | sun.sun_family = AF_UNIX; |
376 | strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); | 374 | strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); |
377 | 375 | if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) { | |
378 | if (connect(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) { | 376 | close(s); |
379 | close(s); | 377 | return (-1); |
380 | return (-1); | ||
381 | } | 378 | } |
382 | return (s); | 379 | return (s); |
383 | 380 | ||
384 | } | 381 | } |
385 | 382 | ||
386 | /* | 383 | /* |
@@ -397,10 +394,9 @@ unix_listen(char *path) | |||
397 | if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) | 394 | if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) |
398 | return (-1); | 395 | return (-1); |
399 | 396 | ||
400 | sun.sun_family = AF_UNIX; | ||
401 | strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); | 397 | strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); |
402 | 398 | sun.sun_family = AF_UNIX; | |
403 | if (bind(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) { | 399 | if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) { |
404 | close(s); | 400 | close(s); |
405 | return (-1); | 401 | return (-1); |
406 | } | 402 | } |
@@ -452,7 +448,7 @@ remote_connect(char *host, char *port, struct addrinfo hints) | |||
452 | errx(1, "%s", gai_strerror(error)); | 448 | errx(1, "%s", gai_strerror(error)); |
453 | 449 | ||
454 | if (bind(s, (struct sockaddr *)ares->ai_addr, | 450 | if (bind(s, (struct sockaddr *)ares->ai_addr, |
455 | ares->ai_addrlen) < 0) { | 451 | ares->ai_addrlen) < 0) { |
456 | errx(1, "bind failed: %s", strerror(errno)); | 452 | errx(1, "bind failed: %s", strerror(errno)); |
457 | freeaddrinfo(ares); | 453 | freeaddrinfo(ares); |
458 | continue; | 454 | continue; |
@@ -573,14 +569,16 @@ readwrite(int nfd) | |||
573 | } | 569 | } |
574 | 570 | ||
575 | if (pfd[1].revents & POLLIN) { | 571 | if (pfd[1].revents & POLLIN) { |
576 | if ((n = read(wfd, buf, sizeof(buf))) < 0) { | 572 | if ((n = read(wfd, buf, sizeof(buf))) < 0) |
577 | return; | 573 | return; |
578 | } else | 574 | else { |
579 | if((ret = atomicio(write, nfd, buf, n)) != n) | 575 | if((ret = atomicio(write, nfd, buf, n)) != n) |
580 | return; | 576 | return; |
577 | } | ||
581 | } | 578 | } |
582 | } | 579 | } |
583 | } | 580 | } |
581 | |||
584 | /* Deal with RFC854 WILL/WONT DO/DONT negotiation */ | 582 | /* Deal with RFC854 WILL/WONT DO/DONT negotiation */ |
585 | void | 583 | void |
586 | atelnet(int nfd, unsigned char *buf, unsigned int size) | 584 | atelnet(int nfd, unsigned char *buf, unsigned int size) |
@@ -598,12 +596,10 @@ atelnet(int nfd, unsigned char *buf, unsigned int size) | |||
598 | 596 | ||
599 | obuf[0] = IAC; | 597 | obuf[0] = IAC; |
600 | p++; | 598 | p++; |
601 | if ((*p == WILL) || (*p == WONT)) { | 599 | if ((*p == WILL) || (*p == WONT)) |
602 | obuf[1] = DONT; | 600 | obuf[1] = DONT; |
603 | } | 601 | if ((*p == DO) || (*p == DONT)) |
604 | if ((*p == DO) || (*p == DONT)) { | ||
605 | obuf[1] = WONT; | 602 | obuf[1] = WONT; |
606 | } | ||
607 | if (obuf) { | 603 | if (obuf) { |
608 | p++; | 604 | p++; |
609 | obuf[2] = *p; | 605 | obuf[2] = *p; |