Skip to content

Commit ba34dea

Browse files
Merge pull request #418
Fix Zephyr discovery IPv4 conversion
2 parents 6141d27 + 7017431 commit ba34dea

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/c/profile/discovery/transport/udp_transport_datagram_posix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void uxr_bytes_to_ip(
8484
char* ip)
8585
{
8686
struct in_addr addr;
87-
addr.s_addr = (in_addr_t)(*bytes + (*(bytes + 1) << 8) + (*(bytes + 2) << 16) + (*(bytes + 3) << 24));
87+
memcpy(&addr.s_addr, bytes, sizeof(addr.s_addr));
8888
char* internal_ip = inet_ntoa(addr);
8989
strcpy(ip, internal_ip);
9090
}

src/c/profile/discovery/transport/udp_transport_datagram_posix_nopoll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void uxr_bytes_to_ip(
8888
char* ip)
8989
{
9090
struct in_addr addr;
91-
addr.s_addr = (in_addr_t)(*bytes + (*(bytes + 1) << 8) + (*(bytes + 2) << 16) + (*(bytes + 3) << 24));
91+
memcpy(&addr.s_addr, bytes, sizeof(addr.s_addr));
9292
char* internal_ip = inet_ntoa(addr);
9393
strcpy(ip, internal_ip);
9494
}

test/unitary/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,6 @@ unitary_test(SessionInfo session/SessionInfo.cpp)
8989
unitary_test(Session session/Session.cpp)
9090
unitary_test(WriteReadAccess session/WriteReadAccess.cpp)
9191
unitary_test(Utils session/Utils.cpp)
92+
unitary_test(DiscoveryTransport profile/DiscoveryTransport.cpp)
93+
target_link_libraries(DiscoveryTransport PRIVATE microxrcedds_client)
9294

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <gtest/gtest.h>
2+
3+
extern "C"
4+
{
5+
#include <c/profile/discovery/transport/udp_transport_datagram_internal.h>
6+
}
7+
8+
TEST(DiscoveryTransportTest, ConvertsIpv4AddressBytes)
9+
{
10+
const uint8_t address[] = {192, 168, 1, 42};
11+
char ip[16] = {};
12+
13+
uxr_bytes_to_ip(address, ip);
14+
15+
EXPECT_STREQ("192.168.1.42", ip);
16+
}

0 commit comments

Comments
 (0)