From dd22395b265b5c0f755bbf14fd4f8e484a48752b Mon Sep 17 00:00:00 2001 From: HendrikVE Date: Tue, 1 Feb 2022 13:52:47 +0100 Subject: [PATCH] Process IPv6 scope id Send data to the same interface we originally received from. This allows the use of TAP devices for communication. --- MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp | 6 ++++++ MQTTSNGateway/src/linux/udp6/SensorNetwork.h | 1 + 2 files changed, 7 insertions(+) diff --git a/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp b/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp index 353d793..8cf077b 100644 --- a/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp +++ b/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp @@ -59,6 +59,11 @@ uint16_t SensorNetAddress::getPortNo(void) return _IpAddr.sin6_port; } +uint32_t SensorNetAddress::getScopeId(void) +{ + return _IpAddr.sin6_scope_id; +} + void SensorNetAddress::setAddress(struct sockaddr_in6 *IpAddr) { memcpy((void*) &_IpAddr, IpAddr, sizeof(_IpAddr)); @@ -397,6 +402,7 @@ int UDPPort6::unicast(const uint8_t* buf, uint32_t length, SensorNetAddress* add memset(&dest, 0, sizeof(dest)); dest.sin6_family = AF_INET6; dest.sin6_port = addr->getPortNo(); + dest.sin6_scope_id = addr->getScopeId(); memcpy(dest.sin6_addr.s6_addr, (const void*) &addr->getIpAddress()->sin6_addr, sizeof(in6_addr)); #ifdef DEBUG_NW diff --git a/MQTTSNGateway/src/linux/udp6/SensorNetwork.h b/MQTTSNGateway/src/linux/udp6/SensorNetwork.h index 68830b6..a9a0eaf 100644 --- a/MQTTSNGateway/src/linux/udp6/SensorNetwork.h +++ b/MQTTSNGateway/src/linux/udp6/SensorNetwork.h @@ -42,6 +42,7 @@ class SensorNetAddress int setAddress(const char* data); uint16_t getPortNo(void); sockaddr_in6* getIpAddress(void); + uint32_t getScopeId(void); char* getAddress(void); bool isMatch(SensorNetAddress* addr); SensorNetAddress& operator =(SensorNetAddress& addr);