--- netcat-1.10-2.orig/netcat.c 2003-05-10 16:20:58.000000000 +0100 +++ netcat-1.10-2.new/netcat.c 2004-01-24 00:38:04.000000000 +0000 @@ -165,6 +165,9 @@ USHORT o_random = 0; USHORT o_udpmode = 0; USHORT o_verbose = 0; unsigned int o_wait = 0; +#ifdef FORCE_EOLS +USHORT o_eols = 0; +#endif // FORCE_EOLS USHORT o_zero = 0; /* o_tn in optional section */ @@ -1216,7 +1219,47 @@ Debug (("got %d from the net, errno %d", /* okay, suck more stdin */ if (FD_ISSET (0, ding2)) { /* stdin: ding! */ +#ifdef FORCE_EOLS + if (o_eols <= 1) /* no translation or only shrink crlf->lf */ + rr = read (0, bigbuf_in, BIGSIZ); + else /* leave worst-case room to expand lf->crlf */ + rr = read (0, bigbuf_in, BIGSIZ / 2); + if (o_eols == 1) { + /* crlf->lf */ + char *s, *d; + int m; + s = d = bigbuf_in; + m = rr; + while (m--) { + if (*s != 0x0d) + *d++ = *s; + else + rr--; + s++; + } + } else if (o_eols == 2) { + /* lf->crlf. */ + char *s, *d; + int n, m; + n = 0; + s = bigbuf_in; + m = rr; + while (m--) + n += (*s++ == 0x0a) ? 1 : 0; + rr += n; + --s; + d = s + n; + m = rr; + if (n) while (m--) { + *d-- = *s; + if (*s == 0x0a) + *d-- = 0x0d; + s--; + } + } +#else // !FORCE_EOLS rr = read (0, bigbuf_in, BIGSIZ); +#endif // FORCE_EOLS /* Considered making reads here smaller for UDP mode, but 8192-byte mobygrams are kinda fun and exercise the reassembler. */ if (rr <= 0) { /* at end, or fukt, or ... */ @@ -1395,7 +1438,11 @@ main (argc, argv) /* If your shitbox doesn't have getopt, step into the nineties already. */ /* optarg, optind = next-argv-component [i.e. flag arg]; optopt = last-char */ +#ifdef FORCE_EOLS + while ((x = getopt (argc, argv, "aDe:g:G:hi:lno:p:rs:tuvw:Xz")) != EOF) { +#else // !FORCE_EOLS while ((x = getopt (argc, argv, "ae:g:G:hi:lno:p:rs:tuvw:z")) != EOF) { +#endif // FORCE_EOLS /* Debug (("in go: x now %c, optarg %x optind %d", x, optarg, optind)) */ switch (x) { case 'a': @@ -1475,6 +1522,14 @@ main (argc, argv) case 'z': /* little or no data xfer */ o_zero++; break; +#ifdef FORCE_EOLS + case 'D': + o_eols = 2; + break; + case 'X': + o_eols = 1; + break; +#endif // FORCE_EOLS default: errno = 0; bail ("nc -h for help"); @@ -1667,6 +1722,11 @@ options:"); -v verbose [use twice to be more verbose]\n\ -w secs timeout for connects and final net reads\n\ -z zero-I/O mode [used for scanning]"); +#ifdef FORCE_EOLS + holler ("\ + -D force DOS-style CR/LF line ends from stdin\n\ + -X force *nix-style LF line ends from stdin"); +#endif // FORCE_EOLS bail ("port numbers can be individual or ranges: lo-hi [inclusive]"); } /* helpme */ #endif /* HAVE_HELP */