Wed 26 Aug 2015 09:05:48 AM UTC, original submission:
When both IP versions are supported, ip4_to_ip()/ip6_to_ip() converts the IP version-specific first argument to an IP version-independent type given as the second argument.
To work the same way when only one IP version is supported the first argument needs to be copied to the second.
Consider the following code (choose destination address and pcb based on IP version of incoming packet):
#if LWIP_IPV4
ip4_addr_t v4addr = ..;
#endif
#if LWIP_IPV6
ip6_addr_t v6addr = ..;
#endif
struct {
#if LWIP_IPV4
struct udp_pcb *v4pcb;
#endif
#if LWIP_IPV6
struct udp_pcb *v6pcb;
#endif
} data;
....
{
ip_addr_t tempaddr;
struct udp_pcb *pcb = NULL;
if (IP_IS_V6_VAL(source_addr)) {
#if LWIP_IPV6
ip6_2_ip(&v6addr, &tempaddr);
pcb = data.v6pcb;
#endif
} else {
#if LWIP_IPV4
ip4_2_ip(&v4addr, &tempaddr);
pcb = data.v4pcb;
#endif
}
udp_sendto_if(pcb, pbuf, &tempaddr, port, netif);
}
This code works when both IP versions are enabled but break if only one is, since the ipX_to_ip() functions do different things.
|