fixed IPv6 mode not receiving loopback messages
This commit is contained in:
parent
05142cbb1f
commit
349e807649
2 changed files with 36 additions and 13 deletions
24
README.md
24
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
|
||||
```
|
||||
|
||||
|
|
|
@ -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)));
|
||||
|
|
Loading…
Reference in a new issue