Listening to udp cast using boost library

This seems to be a problem that many people experience, but all the answers that I have found so far have not helped.

Problem: I am trying to listen to Velodyne HDL32, which sends its packets via UDP to my computer. The OS is a 32-bit Ubuntu library and Boost v1.46.

The data that I get through Wireshark is as follows:

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 someone identify the problem so far or do you need more information? I appreciate any help I can get.

Note: I DO NOT run a program with root privileges!

Some thoughts: Is it possible that boost :: asio :: ip :: address_v4 :: any () will not listen on IP .. *. 255 if there is a subnet of 255.255.255.0?

When using netcat, data is not displayed. When I use Windows netcat, it works fine. Same thing with Wireshark on Linux and Windows - works great. I tried with this, but with the same effect - no data.

+6
source share
2 answers

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

Explanation for everyone else trying to work with Velodyne:

Velodyne has its own subnet (192.168.17.x). All recorded data is now sent to the 192.168.3.x subnet via broadcast. Under normal circumstances, data should be obtained at all IP addresses on this subnet, but this seems impossible. The only IP address you can get is IP 255, and only if you use one of these two solutions. (Or use windows or file dump with wirehark)

1. A stupid but working solution

Set the gateway to 192.168.3.1. No, but it doesn’t matter. Now you will receive data on IP 255.

2. Clean solution

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

I really don't know why this got so complicated, but it took us quite a while to discover this "secret." I hope some of you will profit from our excellent work.

+2
source

Have you tried setting the broadcast option?

 // do this before binding boost::asio::socket_base::broadcast option(true); m_socket.set_option(option); 
0
source

Source: https://habr.com/ru/post/916745/


All Articles