Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable IPv6 support #192

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions src/ESPAsyncTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port){
#endif
if (_pcb) //already connected
return false;
ip_addr_t addr;
addr.addr = ip;

ip_addr_t addr = ip;

#if LWIP_VERSION_MAJOR == 1
netif* interface = ip_route(&addr);
if (!interface){ //no route to host
Expand Down Expand Up @@ -279,7 +280,7 @@ bool AsyncClient::connect(const char* host, uint16_t port){
#if ASYNC_TCP_SSL_ENABLED
return connect(IPAddress(addr.addr), port, secure);
#else
return connect(IPAddress(addr.addr), port);
return connect(IPAddress(addr), port);
#endif
} else if(err == ERR_INPROGRESS) {
#if ASYNC_TCP_SSL_ENABLED
Expand Down Expand Up @@ -328,7 +329,25 @@ AsyncClient& AsyncClient::operator=(const AsyncClient& other){
}

bool AsyncClient::operator==(const AsyncClient &other) {
return (_pcb != NULL && other._pcb != NULL && (_pcb->remote_ip.addr == other._pcb->remote_ip.addr) && (_pcb->remote_port == other._pcb->remote_port));
if (_pcb == NULL || other._pcb == NULL) {
return false;
}

if (_pcb->remote_ip.type != other._pcb->remote_ip.type) {
return false;
}

if (_pcb->remote_ip.type == IPADDR_TYPE_V4) {
if (_pcb->remote_ip.u_addr.ip4.addr != other._pcb->remote_ip.u_addr.ip4.addr) {
return false;
}
} else {
if (_pcb->remote_ip.u_addr.ip6.addr != other._pcb->remote_ip.u_addr.ip6.addr) {
return false;
}
}

return true;
}

void AsyncClient::abort(){
Expand Down Expand Up @@ -704,7 +723,7 @@ void AsyncClient::_dns_found(const ip_addr *ipaddr){
#if ASYNC_TCP_SSL_ENABLED
connect(IPAddress(ipaddr->addr), _connect_port, _pcb_secure);
#else
connect(IPAddress(ipaddr->addr), _connect_port);
connect(IPAddress(ipaddr), _connect_port);
#endif
} else {
if(_error_cb)
Expand Down Expand Up @@ -831,40 +850,28 @@ uint16_t AsyncClient::getMss(){
return 0;
}

uint32_t AsyncClient::getRemoteAddress() {
if(!_pcb)
return 0;
return _pcb->remote_ip.addr;
}

uint16_t AsyncClient::getRemotePort() {
if(!_pcb)
return 0;
return _pcb->remote_port;
}

uint32_t AsyncClient::getLocalAddress() {
if(!_pcb)
return 0;
return _pcb->local_ip.addr;
}

uint16_t AsyncClient::getLocalPort() {
if(!_pcb)
return 0;
return _pcb->local_port;
}

IPAddress AsyncClient::remoteIP() {
return IPAddress(getRemoteAddress());
return IPAddress(_pcb->remote_ip);
}

uint16_t AsyncClient::remotePort() {
return getRemotePort();
}

IPAddress AsyncClient::localIP() {
return IPAddress(getLocalAddress());
return IPAddress(_pcb->local_ip);
}

uint16_t AsyncClient::localPort() {
Expand Down Expand Up @@ -1073,7 +1080,7 @@ AsyncServer::AsyncServer(IPAddress addr, uint16_t port)

AsyncServer::AsyncServer(uint16_t port)
: _port(port)
, _addr((uint32_t) IPADDR_ANY)
, _addr(IP_ANY_TYPE)
, _noDelay(false)
, _pcb(0)
, _connect_cb(0)
Expand Down Expand Up @@ -1118,8 +1125,7 @@ void AsyncServer::begin(){
}

tcp_setprio(pcb, TCP_PRIO_MIN);
ip_addr_t local_addr;
local_addr.addr = (uint32_t) _addr;
ip_addr_t local_addr = _addr;
err = tcp_bind(pcb, &local_addr, _port);
// Failures are ERR_ISCONN or ERR_USE
if (err != ERR_OK) {
Expand Down
2 changes: 0 additions & 2 deletions src/ESPAsyncTCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ class AsyncClient {
void setAckTimeout(uint32_t timeout);//no ACK timeout for the last sent packet in milliseconds
void setNoDelay(bool nodelay);
bool getNoDelay();
uint32_t getRemoteAddress();
uint16_t getRemotePort();
uint32_t getLocalAddress();
uint16_t getLocalPort();

IPAddress remoteIP();
Expand Down