https://github.com/ThinkalVB/RTDS-Server
I am making a simple UDP IPv6 server that prints version of the UDP packet sent by the remote endpoint. But this code is acting strangely. When sending IPv6 and IPv4 packets it is printing IPv6
. What is that I am doing wrong? [Testing in Win10 with Packet Sender Portable 6.2.3 (127.0.0.1 and ::1)]
#include <asio.hpp>
#include <iostream>
#include "udp_peer.h"
#include <thread>
asio::io_context ioContext;
asio::io_context::work worker(ioContext);
void runServer()
{
ioContext.run();
}
int main()
{
asio::ip::udp::endpoint mUDPep(asio::ip::udp::v6(), 321);
asio::ip::udp::socket mUDPsock(ioContext);
std::thread thread(runServer);
thread.detach();
asio::error_code ec;
UDPpeer udpPeer(&mUDPsock); // Ignore this, it contains the character array
asio::ip::udp::endpoint ep;
mUDPsock.open(mUDPep.protocol(), ec);
mUDPsock.bind(mUDPep, ec);
while (true)
{
auto dataSize = mUDPsock.receive_from(udpPeer.getReadBuffer(), ep);
if (ep.address().is_v4())
std::cout << "IPv4";
else
std::cout << "IPv6";
}
}