diff options
author | ericj <> | 2001-06-26 20:53:14 +0000 |
---|---|---|
committer | ericj <> | 2001-06-26 20:53:14 +0000 |
commit | 1c723c1432496046a48f42b968895c86d6edf3ee (patch) | |
tree | 63123b641bb7dbd4eccc89640aef804b9f3c98b5 /src | |
parent | af8f11035baccd4cb6d2dc3cecbe82f7b7e3448c (diff) | |
download | openbsd-1c723c1432496046a48f42b968895c86d6edf3ee.tar.gz openbsd-1c723c1432496046a48f42b968895c86d6edf3ee.tar.bz2 openbsd-1c723c1432496046a48f42b968895c86d6edf3ee.zip |
rewrite telnet negotiation
Diffstat (limited to 'src')
-rw-r--r-- | src/usr.bin/nc/netcat.c | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index 980f335f24..dd1e589420 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.23 2001/06/26 19:31:10 ericj Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.24 2001/06/26 20:53:14 ericj Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
4 | * | 4 | * |
@@ -26,9 +26,8 @@ | |||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | /* | 29 | /* |
30 | * Re-written nc(1) for OpenBSD. Only code shared with previous version | 30 | * Re-written nc(1) for OpenBSD. Original implementation by |
31 | * was the code for telnet emulation. Original implementation by | ||
32 | * *Hobbit* <hobbit@avian.org>. | 31 | * *Hobbit* <hobbit@avian.org>. |
33 | */ | 32 | */ |
34 | 33 | ||
@@ -430,46 +429,40 @@ readwrite(nfd) | |||
430 | } | 429 | } |
431 | } | 430 | } |
432 | } | 431 | } |
433 | 432 | /* Deal with RFC854 WILL/WONT DO/DONT negotiation */ | |
434 | /* | ||
435 | * Answer anything that looks like telnet negotiation with don't/won't. | ||
436 | * This doesn't modify any data buffers, update the global output count, | ||
437 | * or show up in a hexdump -- it just shits into the outgoing stream. | ||
438 | * Idea and codebase from Mudge@l0pht.com. | ||
439 | */ | ||
440 | void | 433 | void |
441 | atelnet(nfd, buf, size) | 434 | atelnet(nfd, buf, size) |
442 | int nfd; | 435 | int nfd; |
443 | unsigned char *buf; | 436 | unsigned char *buf; |
444 | unsigned int size; | 437 | unsigned int size; |
445 | { | 438 | { |
446 | static unsigned char obuf[4]; | 439 | int ret, pos = 0; |
447 | int x, ret; | 440 | unsigned char *p, *end; |
448 | unsigned char y; | 441 | unsigned char obuf[4]; |
449 | unsigned char *p; | 442 | |
450 | 443 | end = buf + size; | |
451 | y = 0; | 444 | obuf[0] = '\0'; |
452 | p = buf; | 445 | |
453 | x = size; | 446 | for (p = buf; p < end; p++) { |
454 | while (x > 0) { | ||
455 | if (*p != IAC) | 447 | if (*p != IAC) |
456 | goto notiac; | 448 | break; |
457 | obuf[0] = IAC; | 449 | |
458 | p++; x--; | 450 | obuf[0]=IAC; |
459 | if ((*p == WILL) || (*p == WONT)) | 451 | p++; |
460 | y = DONT; | 452 | if ((*p == WILL) || (*p == WONT)) { |
461 | if ((*p == DO) || (*p == DONT)) | 453 | obuf[1] = DONT; |
462 | y = WONT; | 454 | } |
463 | if (y) { | 455 | if ((*p == DO) || (*p == DONT)) { |
464 | obuf[1] = y; | 456 | obuf[1] = WONT; |
465 | p++; x--; | 457 | } |
458 | if (obuf) { | ||
459 | p++; | ||
466 | obuf[2] = *p; | 460 | obuf[2] = *p; |
461 | obuf[3] = '\0'; | ||
467 | if ((ret = atomicio(write , nfd, obuf, 3)) != 3) | 462 | if ((ret = atomicio(write , nfd, obuf, 3)) != 3) |
468 | warnx("Write Error!"); | 463 | warnx("Write Error!"); |
469 | y = 0; | 464 | obuf[0] = '\0'; |
470 | } | 465 | } |
471 | notiac: | ||
472 | p++; x--; | ||
473 | } | 466 | } |
474 | } | 467 | } |
475 | 468 | ||