Bug 142243

Summary: Netcat (nc(1)) manual mistake
Product: Documentation Reporter: Yasir M. Arsanukaev <yasir27>
Component: Books & ArticlesAssignee: Benedict Reuschling <bcr>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
nc.1.diff none

Description Yasir M. Arsanukaev 2010-01-02 15:10:04 UTC
man 1 nc states in TALKING TO SERVERS section:
[..]
For example, to retrieve the home page of a web site:

           $ echo -n "GET / HTTP/1.0\r\n\r\n" | nc host.example.com 80
[..]

But this kind of request often returns either nothing or something irrelevant, maybe due to a strong server implementation (e.g. meets RFCs).

Fix: 

There should have been used printf(1) instead.
Man should be corrected, namely, sed 's/echo -n/printf/'
How-To-Repeat: According to man one could do the following:

           $ echo "GET / HTTP/1.0\r\n\r\n" | nc example.com 80

But nothing is returned upon request.

Another attempt which also fails:
           $ echo "HEAD / HTTP/1.0\r\n\r\n" | nc ya.ru 80
           <html>
           <head><title>400 Bad Request</title></head>
           <body bgcolor="white">
           <center><h1>400 Bad Request</h1></center>
           <hr><center>nginx</center>
           </body>
           </html>
Comment 1 yarsanukaev 2010-01-02 16:26:45 UTC
While echo in bash(1), sh(1) and csh(1) don't handle '\n' and '\r' properly,
I've discovered echo works correctly in zsh(1).

Patch is attached and can be applied this way:
$ patch /usr/src/contrib/netcat/nc.1 < nc.1.diff

The other way is to mention that example works only in zsh.
Comment 2 Doug Barton freebsd_committer freebsd_triage 2010-01-02 18:57:44 UTC
Yasir wrote:
>> Fix:
> There should have been used printf(1) instead.
> Man should be corrected, namely, sed 's/echo -n/printf/'


printf should always work, yes. In our sh and in bash, 'echo -e' will
also work.


hth,

Doug

-- 

	Improve the effectiveness of your Internet presence with
	a domain name makeover!    http://SupersetSolutions.com/

	Computers are useless. They can only give you answers.
			-- Pablo Picasso
Comment 3 Benedict Reuschling freebsd_committer freebsd_triage 2010-07-25 14:42:57 UTC
Responsible Changed
From-To: freebsd-doc->bcr

I'm working on that.
Comment 4 dfilter service freebsd_committer freebsd_triage 2010-07-26 19:33:47 UTC
Author: bcr (doc committer)
Date: Mon Jul 26 18:33:33 2010
New Revision: 210511
URL: http://svn.freebsd.org/changeset/base/210511

Log:
  Use "printf" instead of "echo -n" in an example because it
  should be more compatible for most shells that are out there.
  
  I contacted Philip Guenther at OpenBSD about this PR and he
  corrected the issue in their tree pretty fast.
  
  PR:			docs/142243
  Submitted by:		Yasir (yasir27 at mail dot ru)
  Obtained from:		OpenBSD
  Discussed with:		delphij
  MFC after:		7 days

Modified:
  head/contrib/netcat/nc.1

Modified: head/contrib/netcat/nc.1
==============================================================================
--- head/contrib/netcat/nc.1	Mon Jul 26 18:23:05 2010	(r210510)
+++ head/contrib/netcat/nc.1	Mon Jul 26 18:33:33 2010	(r210511)
@@ -27,7 +27,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd April 15, 2010
+.Dd July 3, 2010
 .Dt NC 1
 .Os
 .Sh NAME
@@ -340,7 +340,7 @@ when it might be necessary to verify wha
 in response to commands issued by the client.
 For example, to retrieve the home page of a web site:
 .Bd -literal -offset indent
-$ echo -n "GET / HTTP/1.0\er\en\er\en" | nc host.example.com 80
+$ printf "GET / HTTP/1.0\er\en\er\en" | nc host.example.com 80
 .Ed
 .Pp
 Note that this also displays the headers sent by the web server.
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 5 Benedict Reuschling freebsd_committer freebsd_triage 2010-07-26 19:42:37 UTC
State Changed
From-To: open->patched

The fix based on this PR was incorporated into the OpenBSD tree. 
A commit to our HEAD has been made as a result. Until the MFC is 
through, I'll keep it in this state.
Comment 6 dfilter service freebsd_committer freebsd_triage 2010-08-02 16:55:18 UTC
Author: bcr (doc committer)
Date: Mon Aug  2 15:54:59 2010
New Revision: 210771
URL: http://svn.freebsd.org/changeset/base/210771

Log:
  MFC r210511:
  
  Use "printf" instead of "echo -n" in an example because it
  should be more compatible for most shells that are out there.
  
  I contacted Philip Guenther at OpenBSD about this PR and he
  corrected the issue in their tree pretty fast.
  
  PR:                 docs/142243
  Submitted by:       Yasir (yasir27 at mail dot ru)
  Obtained from:      OpenBSD
  Discussed with:     delphij

Modified:
  stable/8/contrib/netcat/nc.1
Directory Properties:
  stable/8/contrib/netcat/   (props changed)

Modified: stable/8/contrib/netcat/nc.1
==============================================================================
--- stable/8/contrib/netcat/nc.1	Mon Aug  2 15:33:16 2010	(r210770)
+++ stable/8/contrib/netcat/nc.1	Mon Aug  2 15:54:59 2010	(r210771)
@@ -27,7 +27,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd April 15, 2010
+.Dd July 3, 2010
 .Dt NC 1
 .Os
 .Sh NAME
@@ -340,7 +340,7 @@ when it might be necessary to verify wha
 in response to commands issued by the client.
 For example, to retrieve the home page of a web site:
 .Bd -literal -offset indent
-$ echo -n "GET / HTTP/1.0\er\en\er\en" | nc host.example.com 80
+$ printf "GET / HTTP/1.0\er\en\er\en" | nc host.example.com 80
 .Ed
 .Pp
 Note that this also displays the headers sent by the web server.
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 7 Benedict Reuschling freebsd_committer freebsd_triage 2010-08-02 17:01:08 UTC
State Changed
From-To: patched->closed

MFC is finished, PR closed. Thanks for sending us this issue.