From 349e80764978dcf2b0a9d095cd6f13d078133238 Mon Sep 17 00:00:00 2001 From: study-faraphel Date: Mon, 11 Nov 2024 10:02:50 +0100 Subject: [PATCH] fixed IPv6 mode not receiving loopback messages --- README.md | 24 ++++++++++++++++++++---- source/EventManager.cpp | 25 ++++++++++++++++--------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 5fbc7ad..820598d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,22 @@ -## Dependencies +## Installation -apt -``` -sudo apt install cmake pkg-config build-essential libmpg123-dev libssl-dev portaudio19-dev +Debian +```bash +# Download +sudo apt install -y git +git clone https://git.faraphel.fr/study-faraphel/M2-PT-DRP +cd M2-PT-DRP + +# Dependencies +sudo apt install -y libmpg123-dev libssl-dev portaudio19-dev + +# Compile +sudo apt install -y build-essential cmake ninja-build pkg-config +cmake -S . -B build -G Ninja +cmake --build build +cd build + +# Run +./M2-PT-DRP --host ff02::1 --ipv6 ``` + diff --git a/source/EventManager.cpp b/source/EventManager.cpp index 9d57779..7eb2c45 100644 --- a/source/EventManager.cpp +++ b/source/EventManager.cpp @@ -42,16 +42,16 @@ EventManager::EventManager(const std::string& address, const std::string& port, }; // hints for the communication - addrinfo addressHints {}; - addressHints.ai_family = useIpv6 ? AF_INET6 : AF_INET; - addressHints.ai_socktype = SOCK_DGRAM; - addressHints.ai_protocol = IPPROTO_UDP; + addrinfo broadcastAddressHints {}; + broadcastAddressHints.ai_family = useIpv6 ? AF_INET6 : AF_INET; + broadcastAddressHints.ai_socktype = SOCK_DGRAM; + broadcastAddressHints.ai_protocol = IPPROTO_UDP; // create the client socket this->context.socket = socket( - addressHints.ai_family, - addressHints.ai_socktype, - addressHints.ai_protocol + broadcastAddressHints.ai_family, + broadcastAddressHints.ai_socktype, + broadcastAddressHints.ai_protocol ); if (this->context.socket < 0) @@ -73,17 +73,24 @@ EventManager::EventManager(const std::string& address, const std::string& port, if(const int error = getaddrinfo( address.c_str(), port.c_str(), - &addressHints, + &broadcastAddressHints, &context.broadcastAddressInfo ) != 0) throw std::runtime_error("Could not get the broadcast address: " + std::string(gai_strerror(error))); + // hints for the bind address + addrinfo anyAddressHints {}; + anyAddressHints.ai_family = useIpv6 ? AF_INET6 : AF_INET; + anyAddressHints.ai_flags = AI_PASSIVE; + anyAddressHints.ai_socktype = SOCK_DGRAM; + anyAddressHints.ai_protocol = IPPROTO_UDP; + // get the information for the broadcast local-link address addrinfo *anyAddressInfo; if(const int error = getaddrinfo( nullptr, port.c_str(), - &addressHints, + &anyAddressHints, &anyAddressInfo ) != 0) throw std::runtime_error("Could not get the any address: " + std::string(gai_strerror(error)));