Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listening to an udp broadcast with the boost library

Seems to be a problem that many people have, but all the answers I have found so far didn't help.

Problem: I'm trying to listen to a Velodyne HDL32 that sends its packets via UDP to my pc. The OS is 32-bit Ubuntu and Boost library v1.46.

The data i get via Wireshark looks like this:

Time     | Source         | Destination   | Protocol | Length | Source Port | Destination Port
0.000000 | 192.168.17.212 | 192.168.3.255 | UDP      | 1248   | https       | opentable

But with this code, no data is shown to me (Port is correct):

receiver(boost::asio::io_service& io_service,
  const boost::asio::ip::address& listen_address)
: m_socket(io_service)
{

boost::asio::ip::address ipAddr = boost::asio::ip::address_v4::any();
boost::asio::ip::udp::endpoint listen_endpoint(
         ipAddr, 2368);

m_socket.open(listen_endpoint.protocol());
m_socket.bind(listen_endpoint);

m_socket.async_receive_from(
    boost::asio::buffer(m_data, max_length), m_sender_endpoint,
    boost::bind(&receiver::handle_receive_from, this,
      boost::asio::placeholders::error,
      boost::asio::placeholders::bytes_transferred));
}

void handle_receive_from(const boost::system::error_code& error,
  size_t bytes_recvd)
{
std::cout << "receive" << bytes_recvd << std::endl;


  m_socket.async_receive_from(
      boost::asio::buffer(m_data, max_length), m_sender_endpoint,
      boost::bind(&receiver::handle_receive_from, this,
        boost::asio::placeholders::error,
        boost::asio::placeholders::bytes_transferred));
}

Can anyone identify a problem so far or do you need more information? I appreciate any help I can get.

NOTE: I'm NOT running the program with root privileges!

Some thoughts: Could it be possible that boost::asio::ip::address_v4::any() won't listen to the IP ..*.255 when having subnetmask 255.255.255.0?

When using netcat, no data is shown as well. When I use Windows netcat it works quite fine. Same with Wireshark on Linux and Windows - works fine. Tried it with the as well, but with the same effect - no data.

like image 650
Hugo Ritzkowski Avatar asked May 26 '12 13:05

Hugo Ritzkowski


1 Answers

Thank you all for your trying to help me. The code was all right, but the problem was on side of the velodyne and the networksetting with it.

Explanation for all others who try to work with a Velodyne:

The velodyne has it's own subnetwork (192.168.17.x). All recorded data is now send to the subnetwork 192.168.3.x by broadcast. Under normal circumstances the data should be received on all IPs in this subnet, but this seems not to be possible. The only IP you can receive data is the IP 255 and that just if you use one of these two solutions. (Or use windows or dump a file with wireshark)

1. The stupid but working solution

Set an gateway to 192.168.3.1. Yes there is none, but it doesn't matter. From now one you will receive data on the IP 255.

2. The clean solution

Set a new route that leads all traffic from the subnet of the velodyne to the subnet 192.168.3.x.

I really don't know why it's so complicaded, but it took us quite some time to discover this "secret". Hopefully some of you will profit from our finicky job.

like image 194
Hugo Ritzkowski Avatar answered Oct 14 '22 19:10

Hugo Ritzkowski