Skip to content

Commit 50b244d

Browse files
committed
Support non-IPv6 lwIP
1 parent 2cd2e47 commit 50b244d

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

src/AsyncTCP.cpp

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,11 @@ bool AsyncClient::connect(ip_addr_t addr, uint16_t port) {
843843
tcp_pcb *pcb;
844844
{
845845
tcp_core_guard tcg;
846+
#if LWIP_IPV4 && LWIP_IPV6
846847
pcb = tcp_new_ip_type(addr.type);
848+
#else
849+
pcb = tcp_new_ip_type(IPADDR_TYPE_V4);
850+
#endif
847851
if (!pcb) {
848852
log_e("pcb == NULL");
849853
return false;
@@ -863,8 +867,12 @@ bool AsyncClient::connect(ip_addr_t addr, uint16_t port) {
863867
bool AsyncClient::connect(const IPAddress &ip, uint16_t port) {
864868
ip_addr_t addr;
865869
#if ESP_IDF_VERSION_MAJOR < 5
870+
#if LWIP_IPV4 && LWIP_IPV6
866871
addr.u_addr.ip4.addr = ip;
867872
addr.type = IPADDR_TYPE_V4;
873+
#else
874+
addr.addr = ip;
875+
#endif
868876
#else
869877
ip.to_ip_addr_t(&addr);
870878
#endif
@@ -1349,19 +1357,33 @@ uint16_t AsyncClient::getLocalPort() const {
13491357
}
13501358

13511359
ip4_addr_t AsyncClient::getRemoteAddress4() const {
1360+
#if LWIP_IPV4 && LWIP_IPV6
13521361
if (_pcb && _pcb->remote_ip.type == IPADDR_TYPE_V4) {
13531362
return _pcb->remote_ip.u_addr.ip4;
1354-
} else {
1363+
}
1364+
#else
1365+
if (_pcb) {
1366+
return _pcb->remote_ip;
1367+
}
1368+
#endif
1369+
else {
13551370
ip4_addr_t nulladdr;
13561371
ip4_addr_set_zero(&nulladdr);
13571372
return nulladdr;
13581373
}
13591374
}
13601375

13611376
ip4_addr_t AsyncClient::getLocalAddress4() const {
1377+
#if LWIP_IPV4 && LWIP_IPV6
13621378
if (_pcb && _pcb->local_ip.type == IPADDR_TYPE_V4) {
13631379
return _pcb->local_ip.u_addr.ip4;
1364-
} else {
1380+
}
1381+
#else
1382+
if (_pcb) {
1383+
return _pcb->local_ip;
1384+
}
1385+
#endif
1386+
else {
13651387
ip4_addr_t nulladdr;
13661388
ip4_addr_set_zero(&nulladdr);
13671389
return nulladdr;
@@ -1492,24 +1514,34 @@ AsyncServer::AsyncServer(ip_addr_t addr, uint16_t port)
14921514
#ifdef ARDUINO
14931515
AsyncServer::AsyncServer(IPAddress addr, uint16_t port) : _port(port), _noDelay(false), _pcb(0), _connect_cb(0), _connect_cb_arg(0) {
14941516
#if ESP_IDF_VERSION_MAJOR < 5
1517+
#if LWIP_IPV4 && LWIP_IPV6
14951518
_addr.type = IPADDR_TYPE_V4;
14961519
_addr.u_addr.ip4.addr = addr;
1520+
#else
1521+
_addr.addr = addr;
1522+
#endif
14971523
#else
14981524
addr.to_ip_addr_t(&_addr);
14991525
#endif
15001526
}
1501-
#if ESP_IDF_VERSION_MAJOR < 5
1527+
#if ESP_IDF_VERSION_MAJOR < 5 && __has_include(<IPv6Address.h>) && LWIP_IPV6
15021528
AsyncServer::AsyncServer(IPv6Address addr, uint16_t port) : _port(port), _noDelay(false), _pcb(0), _connect_cb(0), _connect_cb_arg(0) {
1529+
#if LWIP_IPV4 && LWIP_IPV6
15031530
_addr.type = IPADDR_TYPE_V6;
1531+
#endif
15041532
auto ipaddr = static_cast<const uint32_t *>(addr);
15051533
_addr = IPADDR6_INIT(ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
15061534
}
15071535
#endif
15081536
#endif
15091537

15101538
AsyncServer::AsyncServer(uint16_t port) : _port(port), _noDelay(false), _pcb(0), _connect_cb(0), _connect_cb_arg(0) {
1539+
#if LWIP_IPV4 && LWIP_IPV6
15111540
_addr.type = IPADDR_TYPE_ANY;
15121541
_addr.u_addr.ip4.addr = INADDR_ANY;
1542+
#else
1543+
_addr.addr = IPADDR_TYPE_ANY;
1544+
#endif
15131545
}
15141546

15151547
AsyncServer::~AsyncServer() {
@@ -1533,7 +1565,11 @@ void AsyncServer::begin() {
15331565
int8_t err;
15341566
{
15351567
tcp_core_guard tcg;
1568+
#if LWIP_IPV4 && LWIP_IPV6
15361569
_pcb = tcp_new_ip_type(_addr.type);
1570+
#else
1571+
_pcb = tcp_new_ip_type(IPADDR_TYPE_V4);
1572+
#endif
15371573
}
15381574
if (!_pcb) {
15391575
log_e("_pcb == NULL");

0 commit comments

Comments
 (0)