@@ -722,12 +722,16 @@ bool AsyncClient::_connect(ip_addr_t addr, uint16_t port){
722
722
723
723
bool AsyncClient::connect (IPAddress ip, uint16_t port){
724
724
ip_addr_t addr;
725
+ #if ESP_IDF_VERSION_MAJOR < 5
725
726
ip_addr_set_ip4_u32 (&addr, ip);
727
+ #else
728
+ ip.to_ip_addr_t (&addr);
729
+ #endif
726
730
727
731
return _connect (addr, port);
728
732
}
729
733
730
- #if LWIP_IPV6
734
+ #if LWIP_IPV6 && ESP_IDF_VERSION_MAJOR < 5
731
735
bool AsyncClient::connect (IPv6Address ip, uint16_t port){
732
736
ip_addr_t addr;
733
737
addr.type = IPADDR_TYPE_V6;
@@ -747,13 +751,17 @@ bool AsyncClient::connect(const char* host, uint16_t port){
747
751
748
752
err_t err = dns_gethostbyname (host, &addr, (dns_found_callback)&_tcp_dns_found, this );
749
753
if (err == ERR_OK) {
754
+ #if ESP_IDF_VERSION_MAJOR < 5
750
755
#if LWIP_IPV6
751
756
if (addr.type == IPADDR_TYPE_V6) {
752
757
return connect (IPv6Address (addr.u_addr .ip6 .addr ), port);
753
758
}
754
759
return connect (IPAddress (addr.u_addr .ip4 .addr ), port);
755
760
#else
756
761
return connect (IPAddress (addr.addr ), port);
762
+ #endif
763
+ #else
764
+ return _connect (addr, port);
757
765
#endif
758
766
} else if (err == ERR_INPROGRESS) {
759
767
_connect_port = port;
@@ -1019,11 +1027,16 @@ int8_t AsyncClient::_poll(tcp_pcb* pcb){
1019
1027
}
1020
1028
1021
1029
void AsyncClient::_dns_found (struct ip_addr *ipaddr){
1030
+ #if ESP_IDF_VERSION_MAJOR < 5
1022
1031
if (ipaddr && IP_IS_V4 (ipaddr)){
1023
1032
connect (IPAddress (ip_addr_get_ip4_u32 (ipaddr)), _connect_port);
1024
1033
#if LWIP_IPV6
1025
1034
} else if (ipaddr && ipaddr->u_addr .ip6 .addr ){
1026
1035
connect (IPv6Address (ipaddr->u_addr .ip6 .addr ), _connect_port);
1036
+ #endif
1037
+ #else
1038
+ if (ipaddr) {
1039
+ connect (IPAddress (ipaddr), _connect_port);
1027
1040
#endif
1028
1041
} else {
1029
1042
if (_error_cb) {
@@ -1138,14 +1151,23 @@ ip6_addr_t AsyncClient::getLocalAddress6() {
1138
1151
}
1139
1152
return _pcb->local_ip .u_addr .ip6 ;
1140
1153
}
1141
-
1154
+ # if ESP_IDF_VERSION_MAJOR < 5
1142
1155
IPv6Address AsyncClient::remoteIP6 () {
1143
1156
return IPv6Address (getRemoteAddress6 ().addr );
1144
1157
}
1145
1158
1146
1159
IPv6Address AsyncClient::localIP6 () {
1147
1160
return IPv6Address (getLocalAddress6 ().addr );
1148
1161
}
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
1149
1171
#endif
1150
1172
1151
1173
uint16_t AsyncClient::getRemotePort () {
@@ -1174,15 +1196,23 @@ uint16_t AsyncClient::getLocalPort() {
1174
1196
}
1175
1197
1176
1198
IPAddress AsyncClient::remoteIP () {
1199
+ #if ESP_IDF_VERSION_MAJOR < 5
1177
1200
return IPAddress (getRemoteAddress ());
1201
+ #else
1202
+ return _pcb ? IPAddress (dynamic_cast <const ip_addr_t *>(&_pcb->remote_ip )) : IPAddress ();
1203
+ #endif
1178
1204
}
1179
1205
1180
1206
uint16_t AsyncClient::remotePort () {
1181
1207
return getRemotePort ();
1182
1208
}
1183
1209
1184
1210
IPAddress AsyncClient::localIP () {
1211
+ #if ESP_IDF_VERSION_MAJOR < 5
1185
1212
return IPAddress (getLocalAddress ());
1213
+ #else
1214
+ return _pcb ? IPAddress (dynamic_cast <const ip_addr_t *>(&_pcb->local_ip )) : IPAddress ();
1215
+ #endif
1186
1216
}
1187
1217
1188
1218
@@ -1318,14 +1348,20 @@ int8_t AsyncClient::_s_connected(void * arg, void * pcb, int8_t err){
1318
1348
1319
1349
AsyncServer::AsyncServer (IPAddress addr, uint16_t port)
1320
1350
: _port (port)
1351
+ #if ESP_IDF_VERSION_MAJOR < 5
1321
1352
, _bind4 (true )
1353
+ #else
1354
+ , _bind4 (addr.type () != IPType::IPv6)
1355
+ , _bind6 (addr.type () == IPType::IPv6)
1356
+ #endif
1322
1357
, _addr (addr)
1323
1358
, _noDelay (false )
1324
1359
, _pcb (0 )
1325
1360
, _connect_cb (0 )
1326
1361
, _connect_cb_arg (0 )
1327
1362
{}
1328
1363
1364
+ #if ESP_IDF_VERSION_MAJOR < 5
1329
1365
AsyncServer::AsyncServer (IPv6Address addr, uint16_t port)
1330
1366
: _port (port)
1331
1367
, _bind6 (true )
@@ -1335,13 +1371,16 @@ AsyncServer::AsyncServer(IPv6Address addr, uint16_t port)
1335
1371
, _connect_cb (0 )
1336
1372
, _connect_cb_arg (0 )
1337
1373
{}
1374
+ #endif
1338
1375
1339
1376
AsyncServer::AsyncServer (uint16_t port)
1340
1377
: _port (port)
1341
1378
, _bind4 (true )
1342
1379
, _bind6 (true )
1343
1380
, _addr ((uint32_t ) IPADDR_ANY)
1381
+ #if ESP_IDF_VERSION_MAJOR < 5
1344
1382
, _addr6 ()
1383
+ #endif
1345
1384
, _noDelay (false )
1346
1385
, _pcb (0 )
1347
1386
, _connect_cb (0 )
0 commit comments