@@ -705,7 +705,7 @@ bool AsyncClient::_connect(ip_addr_t addr, uint16_t port){
705
705
return false ;
706
706
}
707
707
708
- tcp_pcb* pcb = tcp_new_ip_type (addr. type );
708
+ tcp_pcb* pcb = tcp_new_ip_type (IPADDR_TYPE_ANY );
709
709
if (!pcb){
710
710
log_e (" pcb == NULL" );
711
711
return false ;
@@ -722,19 +722,20 @@ 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
- addr.type = IPADDR_TYPE_V4;
726
- addr.u_addr .ip4 .addr = ip;
725
+ ip_addr_set_ip4_u32 (&addr, ip);
727
726
728
727
return _connect (addr, port);
729
728
}
730
729
730
+ #if LWIP_IPV6
731
731
bool AsyncClient::connect (IPv6Address ip, uint16_t port){
732
732
ip_addr_t addr;
733
733
addr.type = IPADDR_TYPE_V6;
734
734
memcpy (addr.u_addr .ip6 .addr , static_cast <const uint32_t *>(ip), sizeof (uint32_t ) * 4 );
735
735
736
736
return _connect (addr, port);
737
737
}
738
+ #endif
738
739
739
740
bool AsyncClient::connect (const char * host, uint16_t port){
740
741
ip_addr_t addr;
@@ -746,10 +747,10 @@ bool AsyncClient::connect(const char* host, uint16_t port){
746
747
747
748
err_t err = dns_gethostbyname (host, &addr, (dns_found_callback)&_tcp_dns_found, this );
748
749
if (err == ERR_OK) {
750
+ #if LWIP_IPV6
749
751
if (addr.type == IPADDR_TYPE_V6) {
750
752
return connect (IPv6Address (addr.u_addr .ip6 .addr ), port);
751
753
}
752
- #if LWIP_IPV6
753
754
return connect (IPAddress (addr.u_addr .ip4 .addr ), port);
754
755
#else
755
756
return connect (IPAddress (addr.addr ), port);
@@ -1018,10 +1019,12 @@ int8_t AsyncClient::_poll(tcp_pcb* pcb){
1018
1019
}
1019
1020
1020
1021
void AsyncClient::_dns_found (struct ip_addr *ipaddr){
1021
- if (ipaddr && ipaddr->u_addr .ip4 .addr ){
1022
- connect (IPAddress (ipaddr->u_addr .ip4 .addr ), _connect_port);
1022
+ if (ipaddr && IP_IS_V4 (ipaddr)){
1023
+ connect (IPAddress (ip_addr_get_ip4_u32 (ipaddr)), _connect_port);
1024
+ #if LWIP_IPV6
1023
1025
} else if (ipaddr && ipaddr->u_addr .ip6 .addr ){
1024
1026
connect (IPv6Address (ipaddr->u_addr .ip6 .addr ), _connect_port);
1027
+ #endif
1025
1028
} else {
1026
1029
if (_error_cb) {
1027
1030
_error_cb (_error_cb_arg, this , -55 );
@@ -1117,6 +1120,7 @@ uint32_t AsyncClient::getRemoteAddress() {
1117
1120
#endif
1118
1121
}
1119
1122
1123
+ #if LWIP_IPV6
1120
1124
ip6_addr_t AsyncClient::getRemoteAddress6 () {
1121
1125
if (!_pcb) {
1122
1126
ip6_addr_t nulladdr;
@@ -1126,6 +1130,24 @@ ip6_addr_t AsyncClient::getRemoteAddress6() {
1126
1130
return _pcb->remote_ip .u_addr .ip6 ;
1127
1131
}
1128
1132
1133
+ ip6_addr_t AsyncClient::getLocalAddress6 () {
1134
+ if (!_pcb) {
1135
+ ip6_addr_t nulladdr;
1136
+ ip6_addr_set_zero (&nulladdr);
1137
+ return nulladdr;
1138
+ }
1139
+ return _pcb->local_ip .u_addr .ip6 ;
1140
+ }
1141
+
1142
+ IPv6Address AsyncClient::remoteIP6 () {
1143
+ return IPv6Address (getRemoteAddress6 ().addr );
1144
+ }
1145
+
1146
+ IPv6Address AsyncClient::localIP6 () {
1147
+ return IPv6Address (getLocalAddress6 ().addr );
1148
+ }
1149
+ #endif
1150
+
1129
1151
uint16_t AsyncClient::getRemotePort () {
1130
1152
if (!_pcb) {
1131
1153
return 0 ;
@@ -1144,15 +1166,6 @@ uint32_t AsyncClient::getLocalAddress() {
1144
1166
#endif
1145
1167
}
1146
1168
1147
- ip6_addr_t AsyncClient::getLocalAddress6 () {
1148
- if (!_pcb) {
1149
- ip6_addr_t nulladdr;
1150
- ip6_addr_set_zero (&nulladdr);
1151
- return nulladdr;
1152
- }
1153
- return _pcb->local_ip .u_addr .ip6 ;
1154
- }
1155
-
1156
1169
uint16_t AsyncClient::getLocalPort () {
1157
1170
if (!_pcb) {
1158
1171
return 0 ;
@@ -1164,10 +1177,6 @@ IPAddress AsyncClient::remoteIP() {
1164
1177
return IPAddress (getRemoteAddress ());
1165
1178
}
1166
1179
1167
- IPv6Address AsyncClient::remoteIP6 () {
1168
- return IPv6Address (getRemoteAddress6 ().addr );
1169
- }
1170
-
1171
1180
uint16_t AsyncClient::remotePort () {
1172
1181
return getRemotePort ();
1173
1182
}
@@ -1176,9 +1185,6 @@ IPAddress AsyncClient::localIP() {
1176
1185
return IPAddress (getLocalAddress ());
1177
1186
}
1178
1187
1179
- IPv6Address AsyncClient::localIP6 () {
1180
- return IPv6Address (getLocalAddress6 ().addr );
1181
- }
1182
1188
1183
1189
uint16_t AsyncClient::localPort () {
1184
1190
return getLocalPort ();
@@ -1377,9 +1383,10 @@ void AsyncServer::begin(){
1377
1383
}
1378
1384
1379
1385
ip_addr_t local_addr;
1380
- local_addr.type = bind_type;
1386
+ ip_addr_set_ip4_u32 (&local_addr, _addr);
1387
+ /* local_addr.type = bind_type;
1381
1388
local_addr.u_addr.ip4.addr = (uint32_t) _addr;
1382
- memcpy (local_addr.u_addr .ip6 .addr , static_cast <const uint32_t *>(_addr6), sizeof (uint32_t ) * 4 );
1389
+ memcpy(local_addr.u_addr.ip6.addr, static_cast<const uint32_t*>(_addr6), sizeof(uint32_t) * 4); */
1383
1390
err = _tcp_bind (_pcb, &local_addr, _port);
1384
1391
1385
1392
if (err != ERR_OK) {
0 commit comments