Why is listening on port with Netcat not working
Asked Answered
D

2

10

I am running the following command on Ubuntu:

nc -l -p 5004 -v  >> /home/anders/Dropbox/netcatFiles/test

which includes a command to make it listen at 5004.

I am sending a RTP-stream to port 5004 using VLC. When I am observing the loopback-interface in Wireshark I notice ICMP-packets with the message 'Destination unreachable'.

Opening another VLC and telling it to play the incoming data at port 5004, it all works, and the stream is played.

What should I do in order to get Netcat to listen at port 5004?

Depression answered 1/7, 2012 at 22:40 Comment(0)
H
13

I think you need to add the " -u " parameter to make it listen on UDP.

By default, netcat works in TCP mode, but RTP protocol is UDP based.

"The Transmission Control Protocol (TCP), although standardized for RTP use,[5] is not normally used in RTP application because TCP favors reliability over timeliness. Instead the majority of the RTP implementations are built on the User Datagram Protocol (UDP)"

http://en.wikipedia.org/wiki/Real-time_Transport_Protocol

Hellbox answered 1/7, 2012 at 22:47 Comment(2)
Thanks! The following works: nc -u -l -p 5004 -v >> /home/anders/Dropbox/netcatFiles/testDepression
I did a quick check, and Harald Brinkhof is correct. "-l -p 5004" shouldn't be working. I suspect you have an old version of netcat. The one I have, that supports your -p 5004 syntax, reports version 1.10, while on another box I have a version which looks newer (more options, etc.) which has the same manual page Harald quotes.Hellbox
I
8

don't use -p (man nc (1))

-p source_port Specifies the source port nc should use, subject to privilege restrictions and availability. It is an error to use this option in con‐ junction with the -l option.

so just specify

nc -l 5004 -v  >> /home/anders/Dropbox/netcatFiles/test
Intermix answered 1/7, 2012 at 22:47 Comment(5)
However, when I did the above command it didn't work. Status: Warning: Inverse name lookup failed for `0.0.19.140' and when I do: nc -u -l -p 5004 -v >> /home/anders/Dropbox/netcatFiles/test it works. I get the status: Received packet from 127.0.0.1:32843 -> 127.0.0.1:5004 (local)Depression
i tested with nc -l 5004 >> output.txt for the listener and echo "tester" | nc 127.0.0.1 5004 for the sender. Worked fine though it does need the host for the sender.Intermix
Thanks for your reply and your comment!! Based on Isernis latest comment and some research I did after receiving it: The manual you linked to, and my version of nc, seems to be for an old version of nc. The manual reads: nc -l -p port [-options] [hostname] [port]Depression
ubuntu actually has (or at least used to have) 2 netcat packages: one openbsd nc based and the other the 'traditional' one probably called netcat-traditional. It might be that there's some discrepancy between those 2 versions.Intermix
I'm not sure what the opposite of thank you is, but I needed to add -p for my version to work: netcat (The GNU Netcat) 0.7.1. Seems like I'd installed it via Macports on Mac OS X (hint being that it was located here /opt/local/libexec/gnubin/nc).Convalescent

© 2022 - 2024 — McMap. All rights reserved.