Skip to content

Commit 8fb7f8a

Browse files
awojasinskijhedberg
authored andcommitted
net: lib: ptp: Fix PTP_UDP_IPv6_PROTOCOL compilation error
When the `PTP_UDP_IPv6_PROTOCOL` configuration is enabled the `mcast_addr` variable is defined as an IPv6 structure, which doesn't have `s_addr` member. To not introduce preprocessor guarded code blocks in functions added union to represent both configurations: IPv4 and IPv6. Fixes: #92975 Signed-off-by: Adam Wojasinski <[email protected]>
1 parent be2ab1f commit 8fb7f8a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

subsys/net/lib/ptp/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ choice
9191

9292
config PTP_UDP_IPv4_PROTOCOL
9393
bool "UDP with IPv4"
94+
depends on NET_IPV4
9495
select NET_IPV4_IGMP
9596

9697
config PTP_UDP_IPv6_PROTOCOL
9798
bool "UDP with IPv6"
99+
depends on NET_IPV6
98100
select NET_IPV6_MLD
99101
endchoice
100102

subsys/net/lib/ptp/transport.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ LOG_MODULE_REGISTER(ptp_transport, CONFIG_PTP_LOG_LEVEL);
1515

1616
#define INTERFACE_NAME_LEN (32)
1717

18+
union mcast_addr {
19+
struct in_addr ipv4;
20+
#if defined(CONFIG_PTP_UDP_IPv6_PROTOCOL)
21+
struct in6_addr ipv6;
22+
#endif
23+
};
24+
1825
#if CONFIG_PTP_UDP_IPv4_PROTOCOL
19-
static struct in_addr mcast_addr = {{{224, 0, 1, 129}}};
26+
static union mcast_addr mcast_addr = {.ipv4 = {{{224, 0, 1, 129}}}};
2027
#elif CONFIG_PTP_UDP_IPv6_PROTOCOL
21-
static struct in6_addr mcast_addr = {{{0xff, 0xe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
22-
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x81}}};
28+
static union mcast_addr mcast_addr = {.ipv6 = {{{0xff, 0xe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
29+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x81}}}};
2330
#else
2431
#error "Chosen PTP transport protocol not implemented"
2532
#endif
@@ -198,7 +205,7 @@ static int transport_send(int socket, int port, void *buf, int length, struct so
198205
if (IS_ENABLED(CONFIG_PTP_UDP_IPv4_PROTOCOL)) {
199206
m_addr.sa_family = AF_INET;
200207
net_sin(&m_addr)->sin_port = htons(port);
201-
net_sin(&m_addr)->sin_addr.s_addr = mcast_addr.s_addr;
208+
net_sin(&m_addr)->sin_addr.s_addr = mcast_addr.ipv4.s_addr;
202209

203210
} else if (IS_ENABLED(CONFIG_PTP_UDP_IPv6_PROTOCOL)) {
204211
m_addr.sa_family = AF_INET6;

0 commit comments

Comments
 (0)