@@ -722,12 +722,16 @@ bool AsyncClient::_connect(ip_addr_t addr, uint16_t port){
722722
723723bool AsyncClient::connect (IPAddress ip, uint16_t port){
724724 ip_addr_t addr;
725+ #if ESP_IDF_VERSION_MAJOR < 5
725726 ip_addr_set_ip4_u32 (&addr, ip);
727+ #else
728+ ip.to_ip_addr_t (&addr);
729+ #endif
726730
727731 return _connect (addr, port);
728732}
729733
730- #if LWIP_IPV6
734+ #if LWIP_IPV6 && ESP_IDF_VERSION_MAJOR < 5
731735bool AsyncClient::connect (IPv6Address ip, uint16_t port){
732736 ip_addr_t addr;
733737 addr.type = IPADDR_TYPE_V6;
@@ -747,13 +751,17 @@ bool AsyncClient::connect(const char* host, uint16_t port){
747751
748752 err_t err = dns_gethostbyname (host, &addr, (dns_found_callback)&_tcp_dns_found, this );
749753 if (err == ERR_OK) {
754+ #if ESP_IDF_VERSION_MAJOR < 5
750755#if LWIP_IPV6
751756 if (addr.type == IPADDR_TYPE_V6) {
752757 return connect (IPv6Address (addr.u_addr .ip6 .addr ), port);
753758 }
754759 return connect (IPAddress (addr.u_addr .ip4 .addr ), port);
755760#else
756761 return connect (IPAddress (addr.addr ), port);
762+ #endif
763+ #else
764+ return _connect (addr, port);
757765#endif
758766 } else if (err == ERR_INPROGRESS) {
759767 _connect_port = port;
@@ -1019,11 +1027,16 @@ int8_t AsyncClient::_poll(tcp_pcb* pcb){
10191027}
10201028
10211029void AsyncClient::_dns_found (struct ip_addr *ipaddr){
1030+ #if ESP_IDF_VERSION_MAJOR < 5
10221031 if (ipaddr && IP_IS_V4 (ipaddr)){
10231032 connect (IPAddress (ip_addr_get_ip4_u32 (ipaddr)), _connect_port);
10241033#if LWIP_IPV6
10251034 } else if (ipaddr && ipaddr->u_addr .ip6 .addr ){
10261035 connect (IPv6Address (ipaddr->u_addr .ip6 .addr ), _connect_port);
1036+ #endif
1037+ #else
1038+ if (ipaddr) {
1039+ connect (IPAddress (ipaddr), _connect_port);
10271040#endif
10281041 } else {
10291042 if (_error_cb) {
@@ -1138,14 +1151,23 @@ ip6_addr_t AsyncClient::getLocalAddress6() {
11381151 }
11391152 return _pcb->local_ip .u_addr .ip6 ;
11401153}
1141-
1154+ # if ESP_IDF_VERSION_MAJOR < 5
11421155IPv6Address AsyncClient::remoteIP6 () {
11431156 return IPv6Address (getRemoteAddress6 ().addr );
11441157}
11451158
11461159IPv6Address AsyncClient::localIP6 () {
11471160 return IPv6Address (getLocalAddress6 ().addr );
11481161}
1162+ #else
1163+ IPAddress AsyncClient::remoteIP6 () {
1164+ return _pcb ? IPAddress (dynamic_cast <const ip_addr_t *>(&_pcb->remote_ip )) : IPAddress (IPType::IPv6);
1165+ }
1166+
1167+ IPAddress AsyncClient::localIP6 () {
1168+ return _pcb ? IPAddress (dynamic_cast <const ip_addr_t *>(&_pcb->local_ip )) : IPAddress (IPType::IPv6);
1169+ }
1170+ #endif
11491171#endif
11501172
11511173uint16_t AsyncClient::getRemotePort () {
@@ -1174,15 +1196,23 @@ uint16_t AsyncClient::getLocalPort() {
11741196}
11751197
11761198IPAddress AsyncClient::remoteIP () {
1199+ #if ESP_IDF_VERSION_MAJOR < 5
11771200 return IPAddress (getRemoteAddress ());
1201+ #else
1202+ return _pcb ? IPAddress (dynamic_cast <const ip_addr_t *>(&_pcb->remote_ip )) : IPAddress ();
1203+ #endif
11781204}
11791205
11801206uint16_t AsyncClient::remotePort () {
11811207 return getRemotePort ();
11821208}
11831209
11841210IPAddress AsyncClient::localIP () {
1211+ #if ESP_IDF_VERSION_MAJOR < 5
11851212 return IPAddress (getLocalAddress ());
1213+ #else
1214+ return _pcb ? IPAddress (dynamic_cast <const ip_addr_t *>(&_pcb->local_ip )) : IPAddress ();
1215+ #endif
11861216}
11871217
11881218
@@ -1318,14 +1348,20 @@ int8_t AsyncClient::_s_connected(void * arg, void * pcb, int8_t err){
13181348
13191349AsyncServer::AsyncServer (IPAddress addr, uint16_t port)
13201350: _port (port)
1351+ #if ESP_IDF_VERSION_MAJOR < 5
13211352, _bind4 (true )
1353+ #else
1354+ , _bind4 (addr.type () != IPType::IPv6)
1355+ , _bind6 (addr.type () == IPType::IPv6)
1356+ #endif
13221357, _addr (addr)
13231358, _noDelay (false )
13241359, _pcb (0 )
13251360, _connect_cb (0 )
13261361, _connect_cb_arg (0 )
13271362{}
13281363
1364+ #if ESP_IDF_VERSION_MAJOR < 5
13291365AsyncServer::AsyncServer (IPv6Address addr, uint16_t port)
13301366: _port (port)
13311367, _bind6 (true )
@@ -1335,13 +1371,16 @@ AsyncServer::AsyncServer(IPv6Address addr, uint16_t port)
13351371, _connect_cb (0 )
13361372, _connect_cb_arg (0 )
13371373{}
1374+ #endif
13381375
13391376AsyncServer::AsyncServer (uint16_t port)
13401377: _port (port)
13411378, _bind4 (true )
13421379, _bind6 (true )
13431380, _addr ((uint32_t ) IPADDR_ANY)
1381+ #if ESP_IDF_VERSION_MAJOR < 5
13441382, _addr6 ()
1383+ #endif
13451384, _noDelay (false )
13461385, _pcb (0 )
13471386, _connect_cb (0 )
0 commit comments