Mail Archives: cygwin/2004/01/23/23:29:01
------=_NextPart_000_219_6266_7f34
Content-Type: text/plain; format=flowed
Hi CV, I see you're listed as netcat maintainer.
I've got a small patch for netcat that gives it two new options (-D/-X) to
force dos or unix line ends when it's sending to the network. This comes in
quite useful for things like HTTP and SMTP servers, since strict ones only
accept CRLF. Default is to just behave as it does presently, and the entire
patch is wrapped in ifdef for good measure. Dunno if you'll think it's a
good idea or not, but here it is for your entertainment. Heh, I didn't know
whether to do a gnu-style changelog or one in the style of the existing
changelogs, so I did both.
cheers,
DaveK
--
040124
Added -D and -X options to force DOS or *nix EOLs when reading stdin.
--
* netcat.c [FORCE_EOLS] (o_eols): added new global option variable.
* netcat.c (readwrite) [FORCE_EOLS]: respect o_eols by using binary mode
fgets.
to read native EOLs or appending a chosen EOL type to gets.
* netcat.c (main) [FORCE_EOLS]: parse new options -D and -X and set o_eols.
* netcat.c (helpme) [FORCE_EOLS]: document new -D and -X options.
_________________________________________________________________
Stay in touch with absent friends - get MSN Messenger
http://www.msn.co.uk/messenger
------=_NextPart_000_219_6266_7f34
Content-Type: text/plain; name="cygwin-netcat-1.10-2.patch"; format=flowed
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="cygwin-netcat-1.10-2.patch"
--- 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 */
------=_NextPart_000_219_6266_7f34
Content-Type: text/plain; charset=us-ascii
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
------=_NextPart_000_219_6266_7f34--
- Raw text -