Package: netcat / 1.10-41

545579-send-crlf.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
From: R�bert Koszor�s <koszorus@reidea.hu>
Subject: netcat-traditional: netcat CRLF support
Date: Tue, 08 Sep 2009 10:12:00 +0200

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=545579

Most of the services from Internet (HTTP, POP3, SMTP, etc..) are using text
based protocol with CRLF line-ending, but the original nc doesn't support it.

I saw my patch is applied for Ubuntu's netcat-openbsd package, but not for the
netcat-traditional. I worked out the patch for the tradtional one.

Index: netcat-1.10/netcat.c
===================================================================
--- netcat-1.10.orig/netcat.c
+++ netcat-1.10/netcat.c
@@ -179,6 +179,7 @@ USHORT o_wfile = 0;
 USHORT o_random = 0;
 USHORT o_udpmode = 0;
 USHORT o_verbose = 0;
+USHORT o_crlf = 0;
 unsigned int o_wait = 0;
 USHORT o_zero = 0;
 int o_quit = -1; /* 0 == quit-now; >0 == quit after o_quit seconds */
@@ -1360,7 +1361,14 @@ Debug (("wrote %d to stdout, errno %d",
 	  rr = findline (zp, rzleft);
 	else
 	  rr = rzleft;
-	rr = write (fd, zp, rr);	/* one line, or the whole buffer */
+  if ( (o_crlf) && (zp[rr-1] == '\n') ) { /* one line */
+      rr = write (fd, zp, rr-1); /* without \n */
+      write (fd, "\r\n", 2); /* \r\n */
+      rr++; /* count only original \n */
+  }
+  else {
+    rr = write (fd, zp, rr); /* one line, or the whole buffer */
+  }
 	if (rr > 0) {
 	  if (o_wfile)
 	    oprint (0, zp, rr);		/* log what got sent */
@@ -1512,7 +1520,7 @@ 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 */
-  while ((x = getopt (argc, argv, "abc:e:g:G:hi:klno:p:q:rs:T:tuvw:z")) != EOF) {
+  while ((x = getopt (argc, argv, "abc:e:g:G:hi:klno:p:q:rs:T:tuvw:zC")) != EOF) {
 /* Debug (("in go: x now %c, optarg %x optind %d", x, optarg, optind)) */
     switch (x) {
       case 'a':
@@ -1617,6 +1625,9 @@ main (argc, argv)
       case 'z':				/* little or no data xfer */
 	o_zero++;
 	break;
+      case 'C':       /* CRLF mode */
+  o_crlf++;
+  break;
       default:
 	errno = 0;
 	bail ("nc -h for help");
@@ -1833,6 +1844,7 @@ options:");
 	-u			UDP mode\n\
 	-v			verbose [use twice to be more verbose]\n\
 	-w secs			timeout for connects and final net reads\n\
+	-C			Send CRLF as line-ending\n\
 	-z			zero-I/O mode [used for scanning]");
   holler ("port numbers can be individual or ranges: lo-hi [inclusive];\n\
 hyphens in port names must be backslash escaped (e.g. 'ftp\\-data').");