send-crlf.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. Index: netcat-openbsd-1.89/netcat.c
  2. ===================================================================
  3. --- netcat-openbsd-1.89.orig/netcat.c 2008-06-19 16:49:57.000000000 -0400
  4. +++ netcat-openbsd-1.89/netcat.c 2008-06-19 17:04:22.000000000 -0400
  5. @@ -73,6 +73,7 @@
  6. #define UDP_SCAN_TIMEOUT 3 /* Seconds */
  7. /* Command Line Options */
  8. +int Cflag = 0; /* CRLF line-ending */
  9. int dflag; /* detached, no stdin */
  10. int iflag; /* Interval Flag */
  11. int jflag; /* use jumbo frames if we can */
  12. @@ -136,7 +137,7 @@
  13. sv = NULL;
  14. while ((ch = getopt(argc, argv,
  15. - "46Ddhi:jklnP:p:rSs:tT:Uuvw:X:x:z")) != -1) {
  16. + "46Ddhi:jklnP:p:rSs:tT:Uuvw:X:x:zC")) != -1) {
  17. switch (ch) {
  18. case '4':
  19. family = AF_INET;
  20. @@ -226,6 +227,9 @@
  21. case 'T':
  22. Tflag = parse_iptos(optarg);
  23. break;
  24. + case 'C':
  25. + Cflag = 1;
  26. + break;
  27. default:
  28. usage(1);
  29. }
  30. @@ -738,8 +742,16 @@
  31. else if (n == 0) {
  32. goto shutdown_wr;
  33. } else {
  34. - if (atomicio(vwrite, nfd, buf, n) != n)
  35. - return;
  36. + if ((Cflag) && (buf[n-1]=='\n')) {
  37. + if (atomicio(vwrite, nfd, buf, n-1) != (n-1))
  38. + return;
  39. + if (atomicio(vwrite, nfd, "\r\n", 2) != 2)
  40. + return;
  41. + }
  42. + else {
  43. + if (atomicio(vwrite, nfd, buf, n) != n)
  44. + return;
  45. + }
  46. }
  47. }
  48. else if (pfd[1].revents & POLLHUP) {
  49. @@ -944,6 +956,7 @@
  50. #endif
  51. " \t-s addr\t Local source address\n\
  52. \t-T ToS\t Set IP Type of Service\n\
  53. + \t-C Send CRLF as line-ending\n\
  54. \t-t Answer TELNET negotiation\n\
  55. \t-U Use UNIX domain socket\n\
  56. \t-u UDP mode\n\
  57. @@ -959,7 +972,7 @@
  58. void
  59. usage(int ret)
  60. {
  61. - fprintf(stderr, "usage: nc [-46DdhklnrStUuvz] [-i interval] [-P proxy_username] [-p source_port]\n");
  62. + fprintf(stderr, "usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]\n");
  63. fprintf(stderr, "\t [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]\n");
  64. fprintf(stderr, "\t [-x proxy_address[:port]] [hostname] [port[s]]\n");
  65. if (ret)
  66. Index: netcat-openbsd-1.89/nc.1
  67. ===================================================================
  68. --- netcat-openbsd-1.89.orig/nc.1 2008-06-19 16:49:39.000000000 -0400
  69. +++ netcat-openbsd-1.89/nc.1 2008-06-19 16:54:36.000000000 -0400
  70. @@ -34,7 +34,7 @@
  71. .Sh SYNOPSIS
  72. .Nm nc
  73. .Bk -words
  74. -.Op Fl 46DdhklnrStUuvz
  75. +.Op Fl 46DdhklnrStUuvzC
  76. .Op Fl i Ar interval
  77. .Op Fl P Ar proxy_username
  78. .Op Fl p Ar source_port
  79. @@ -140,6 +140,10 @@
  80. It is an error to use this option in conjunction with the
  81. .Fl l
  82. option.
  83. +.It Fl q
  84. +after EOF on stdin, wait the specified number of seconds and then quit. If
  85. +.Ar seconds
  86. +is negative, wait forever.
  87. .It Fl r
  88. Specifies that source and/or destination ports should be chosen randomly
  89. instead of sequentially within a range or in the order that the system
  90. @@ -159,6 +163,8 @@
  91. .Dq reliability ,
  92. or an 8-bit hexadecimal value preceded by
  93. .Dq 0x .
  94. +.It Fl C
  95. +Send CRLF as line-ending
  96. .It Fl t
  97. Causes
  98. .Nm
  99. @@ -317,7 +323,7 @@
  100. of requests required by the server.
  101. As another example, an email may be submitted to an SMTP server using:
  102. .Bd -literal -offset indent
  103. -$ nc localhost 25 \*(Lt\*(Lt EOF
  104. +$ nc [-C] localhost 25 \*(Lt\*(Lt EOF
  105. HELO host.example.com
  106. MAIL FROM:\*(Ltuser@host.example.com\*(Gt
  107. RCPT TO:\*(Ltuser2@host.example.com\*(Gt