Bug 719386

Summary: nc -C -u results in two separate datagrams for any message sent
Product: [Fedora] Fedora Reporter: Jaroslav Franek <jarin.franek>
Component: ncAssignee: Petr Šabata <psabata>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: unspecified    
Version: 15CC: psabata, rvokal
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: nc-1.100-3.fc15 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-07-18 22:43:02 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Attachments:
Description Flags
Source code patch
jarin.franek: review?
Wireshark capture of original TCP behavior
none
Wireshark capture of original UDP behavior
none
Wireshark capture of fixed TCP behavior
none
Wireshark capture of fixed UDP behavior none

Description Jaroslav Franek 2011-07-06 16:35:36 UTC
Created attachment 511528 [details]
Source code patch

Description of problem:
When using -C option with nc, the program makes two writes into socket:
1) the message itself
2) the CRLF bytes "\r\n"
For TCP it results in aditional message of 2 bytes + ack, but since TCP is a stream, the client or server may not notice.
For UDP it results in two separate datagrams and this is bad as UDP does not guarantee delivery nor order of the datagrams. Even the client/server is got by surprise as it expected a single datagram containing a valid protocol message.

Version-Release number of selected component (if applicable):
nc-1.100-2.fc15.i686

How reproducible:
(TCP) nc -C 127.0.0.1 <port>
(UDP) nc -C -u 127.0.0.1 <port>

Steps to Reproduce:
see above
  
Actual results:
see Wireshark dumps attached (nc_tcp_orig.cap, nc_udp_orig.cap)

Expected results:
using the supplied patch, CRLF is sent in the same message (one write to the socket), see Wireshark dumps attached (nc_tcp_fixed.cap, nc_udp_fixed.cap)

Additional info:
Patch against nc-1.100-2.fc15 provided for review.

Comment 1 Jaroslav Franek 2011-07-06 16:37:43 UTC
Created attachment 511531 [details]
Wireshark capture of original TCP behavior

Comment 2 Jaroslav Franek 2011-07-06 16:38:42 UTC
Created attachment 511532 [details]
Wireshark capture of original UDP behavior

Comment 3 Jaroslav Franek 2011-07-06 16:39:24 UTC
Created attachment 511533 [details]
Wireshark capture of fixed TCP behavior

Comment 4 Jaroslav Franek 2011-07-06 16:40:10 UTC
Created attachment 511534 [details]
Wireshark capture of fixed UDP behavior

Comment 5 Petr Šabata 2011-07-07 15:20:44 UTC
Thanks, Jaroslav.  The patch looks good to me.

Comment 6 Fedora Update System 2011-07-07 15:32:01 UTC
nc-1.100-3.fc15 has been submitted as an update for Fedora 15.
https://admin.fedoraproject.org/updates/nc-1.100-3.fc15

Comment 7 Fedora Update System 2011-07-08 17:58:07 UTC
Package nc-1.100-3.fc15:
* should fix your issue,
* was pushed to the Fedora 15 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing nc-1.100-3.fc15'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/nc-1.100-3.fc15
then log in and leave karma (feedback).

Comment 8 Fedora Update System 2011-07-18 22:42:56 UTC
nc-1.100-3.fc15 has been pushed to the Fedora 15 stable repository.  If problems still persist, please make note of it in this bug report.