Skip to content

Commit 00f5f2a

Browse files
authored
emulation on host: fix incorrect lwIP DNS implementation (#8627)
* emulation on host: fix incorrect lwIP DNS implementation +initialize netif0, make ipv6 example unfail
1 parent a8e3786 commit 00f5f2a

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

tests/host/common/MocklwIP.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "MocklwIP.h"
55

6+
#include <lwip/dns.h>
7+
68
esp8266::AddressListImplementation::AddressList addrList;
79

810
extern "C"
@@ -57,4 +59,18 @@ extern "C"
5759
return &netif0;
5860
}
5961

62+
void dns_setserver(u8_t numdns, const ip_addr_t* dnsserver)
63+
{
64+
(void)numdns;
65+
(void)dnsserver;
66+
}
67+
68+
const ip_addr_t* dns_getserver(u8_t numdns)
69+
{
70+
(void)numdns;
71+
static ip_addr_t addr;
72+
IP4_ADDR(&addr, 127, 0, 0, 1);
73+
return &addr;
74+
}
75+
6076
} // extern "C"

tests/host/common/user_interface.cpp

+7-21
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ extern "C"
136136
for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next)
137137
{
138138
mockverbose("host: interface: %s", ifa->ifa_name);
139-
if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET // ip_info is IPv4 only
140-
)
139+
if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) // ip_info is IPv4 only
141140
{
142141
auto test_ipv4
143142
= lwip_ntohl(*(uint32_t*)&((struct sockaddr_in*)ifa->ifa_addr)->sin_addr);
@@ -179,14 +178,14 @@ extern "C"
179178
info->ip.addr = ipv4;
180179
info->netmask.addr = mask;
181180
info->gw.addr = ipv4;
182-
183-
netif0.ip_addr.addr = ipv4;
184-
netif0.netmask.addr = mask;
185-
netif0.gw.addr = ipv4;
186-
netif0.flags = NETIF_FLAG_IGMP | NETIF_FLAG_UP | NETIF_FLAG_LINK_UP;
187-
netif0.next = nullptr;
188181
}
189182

183+
netif0.ip_addr.addr = ipv4;
184+
netif0.netmask.addr = mask;
185+
netif0.gw.addr = ipv4;
186+
netif0.flags = NETIF_FLAG_IGMP | NETIF_FLAG_UP | NETIF_FLAG_LINK_UP;
187+
netif0.next = nullptr;
188+
190189
return true;
191190
}
192191

@@ -418,19 +417,6 @@ extern "C"
418417
(void)intr;
419418
}
420419

421-
void dns_setserver(u8_t numdns, ip_addr_t* dnsserver)
422-
{
423-
(void)numdns;
424-
(void)dnsserver;
425-
}
426-
427-
ip_addr_t dns_getserver(u8_t numdns)
428-
{
429-
(void)numdns;
430-
ip_addr_t addr = { 0x7f000001 };
431-
return addr;
432-
}
433-
434420
#include <smartconfig.h>
435421
bool smartconfig_start(sc_callback_t cb, ...)
436422
{

0 commit comments

Comments
 (0)