source: npl/overig/netcat_openbsd/patches/0005-send-crlf.patch @ d0ec78d

gcc484perl-5.22
Last change on this file since d0ec78d was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[c5c522c]1From: Aron Xu <aron@debian.org>
2Date: Mon, 13 Feb 2012 14:57:45 +0800
3Subject: send crlf
4
5---
6 nc.1     |    6 ++++--
7 netcat.c |   21 +++++++++++++++++----
8 2 files changed, 21 insertions(+), 6 deletions(-)
9
10diff --git a/nc.1 b/nc.1
11index b7014a2..af44976 100644
12--- a/nc.1
13+++ b/nc.1
14@@ -34,7 +34,7 @@
15 .Sh SYNOPSIS
16 .Nm nc
17 .Bk -words
18-.Op Fl 46DdhklnrStUuvz
19+.Op Fl 46CDdhklnrStUuvz
20 .Op Fl I Ar length
21 .Op Fl i Ar interval
22 .Op Fl O Ar length
23@@ -98,6 +98,8 @@ to use IPv4 addresses only.
24 Forces
25 .Nm
26 to use IPv6 addresses only.
27+.It Fl C
28+Send CRLF as line-ending.
29 .It Fl D
30 Enable debugging on the socket.
31 .It Fl d
32@@ -355,7 +357,7 @@ More complicated examples can be built up when the user knows the format
33 of requests required by the server.
34 As another example, an email may be submitted to an SMTP server using:
35 .Bd -literal -offset indent
36-$ nc localhost 25 \*(Lt\*(Lt EOF
37+$ nc [\-C] localhost 25 \*(Lt\*(Lt EOF
38 HELO host.example.com
39 MAIL FROM:\*(Ltuser@host.example.com\*(Gt
40 RCPT TO:\*(Ltuser2@host.example.com\*(Gt
41diff --git a/netcat.c b/netcat.c
42index fdaca44..4f4d2bf 100644
43--- a/netcat.c
44+++ b/netcat.c
45@@ -111,6 +111,7 @@
46 #define CONNECTION_TIMEOUT 2
47 
48 /* Command Line Options */
49+int     Cflag = 0;                              /* CRLF line-ending */
50 int    dflag;                                  /* detached, no stdin */
51 unsigned int iflag;                            /* Interval Flag */
52 int    jflag;                                  /* use jumbo frames if we can */
53@@ -180,7 +181,7 @@ main(int argc, char *argv[])
54        sv = NULL;
55 
56        while ((ch = getopt(argc, argv,
57-           "46DdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) {
58+           "46CDdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) {
59                switch (ch) {
60                case '4':
61                        family = AF_INET;
62@@ -309,6 +310,9 @@ main(int argc, char *argv[])
63                        if (Tflag < 0 || Tflag > 255 || errstr || errno)
64                                errx(1, "illegal tos value %s", optarg);
65                        break;
66+                case 'C':
67+                        Cflag = 1;
68+                        break;
69                default:
70                        usage(1);
71                }
72@@ -906,8 +910,16 @@ readwrite(int nfd)
73                        else if (n == 0) {
74                                goto shutdown_wr;
75                        } else {
76-                               if (atomicio(vwrite, nfd, buf, n) != n)
77-                                       return;
78+                               if ((Cflag) && (buf[n-1]=='\n')) {
79+                                       if (atomicio(vwrite, nfd, buf, n-1) != (n-1))
80+                                               return;
81+                                       if (atomicio(vwrite, nfd, "\r\n", 2) != 2)
82+                                               return;
83+                               }
84+                               else {
85+                                       if (atomicio(vwrite, nfd, buf, n) != n)
86+                                               return;
87+                               }
88                        }
89                        }
90                        else if (pfd[1].revents & POLLHUP) {
91@@ -1139,6 +1151,7 @@ help(void)
92        fprintf(stderr, "\tCommand Summary:\n\
93        \t-4            Use IPv4\n\
94        \t-6            Use IPv6\n\
95+       \t-C            Send CRLF as line-ending\n\
96        \t-D            Enable the debug socket option\n\
97        \t-d            Detach from stdin\n\
98        \t-h            This help text\n\
99@@ -1172,7 +1185,7 @@ void
100 usage(int ret)
101 {
102        fprintf(stderr,
103-           "usage: nc [-46DdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n"
104+           "usage: nc [-46CDdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n"
105            "\t  [-P proxy_username] [-p source_port] [-s source] [-T toskeyword]\n"
106            "\t  [-V rtable] [-w timeout] [-X proxy_protocol]\n"
107            "\t  [-x proxy_address[:port]] [destination] [port]\n");
108--
Note: See TracBrowser for help on using the repository browser.