5

If I run these NetCat below commands (no error messages at all) during a WireShark capture running (capture filter= udp dst port 4000) :

luis@Zarzamoro:~$ echo "Hello" | nc -w1 -4u 255.255.255.255 4000
luis@Zarzamoro:~$ echo "Hello" | nc -w1 -4u 255.255.255.1 4000
luis@Zarzamoro:~$ echo "Hello" | nc -w1 -4u 192.168.11.255 4000
luis@Zarzamoro:~$ echo "Hello" | nc -w1 -4u 192.168.11.100 4000

This is the captured data (note the two missing netcat orders) :

Missing supposedly sent data.

As I conclude, any data sent to a broadcast (x.x.x.255) network address is ignored (without errors :-P ) by NetCat.

Why is this happening?

Additional data:

This is my full ifconfig :

luis@Zarzamoro:~$ sudo ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:ef:bb:aa
          inet addr:192.168.11.140  Bcast:192.168.11.255  Mask:255.255.255.0
          inet6 addr: fe80::ba27:ebff:feef:bbaa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9672 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8567 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:503027 (503.0 KB)  TX bytes:5993557 (5.9 MB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:153 errors:0 dropped:0 overruns:0 frame:0
          TX packets:153 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:10926 (10.9 KB)  TX bytes:10926 (10.9 KB)

Running Ubuntu 14.04.

As a workaround for now, I am using socat:

echo "Hello" | socat - UDP-DATAGRAM:255.255.255.255:4000,broadcast

but I would anyway like to understand why NetCat is not capable of doing the same.

  • try -b flag. what does nc say? -b Allow broadcast. What does update-alternatives --display nc display? Try apt-get install netcat-traditional, sudo update-alternatives --set nc /bin/nc.traditional, echo "Hello" | nc -b -w1 -u 192.168.11.255 4000 – Evgeny Vereshchagin Jul 22 '15 at 18:03
  • @EvgenyVereshchagin, most of your suggestions were the way to success. I think they have been practically explained on Yaegashi answer. Thanks you. – Sopalajo de Arrierez Jul 22 '15 at 22:56
6

I assume you are using netcat-openbsd because you specify -4. It has -b to enable broadcast address, but it's known that UDP broadcast is not supported by this version of netcat even with -b. Debian Bug#702204 suggests a patch to fix that.

You can install an alternative package netcat-traditional which seems to correctly support -b with UDP. Note that which netcat to be invoked by running /bin/nc is configurable using update-alternatives when both packages are installed in your system.

$ sudo update-alternatives --config nc
There are 2 choices for the alternative nc (providing /bin/nc).

  Selection    Path                 Priority   Status
------------------------------------------------------------
* 0            /bin/nc.openbsd       50        auto mode
  1            /bin/nc.openbsd       50        manual mode
  2            /bin/nc.traditional   10        manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /bin/nc.traditional to provide /bin/nc (nc) in manual mode

Finally you might want to add -v to get more verbose diagnostics from nc.

  • 1
    That was exactly my problem. I have solved it by issuing apt-get update && apt-get install netcat-traditional, and apt-get remove netcat-openbsd. The last order was needed for me too on Ubuntu, as long as the old OpenBSD version kept prioritized in the operating system. Lets hope it will be soon fixed. Thanks you. – Sopalajo de Arrierez Jul 22 '15 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.