Skip to content

Commit f110b1c

Browse files
authored
Merge branch 'espressif:master' into main
2 parents 749d03e + 8ceb4ba commit f110b1c

File tree

3 files changed

+53
-24
lines changed

3 files changed

+53
-24
lines changed

libraries/Network/src/NetworkManager.cpp

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ NetworkManager::NetworkManager(){
1414

1515
}
1616

17+
NetworkInterface * getNetifByID(Network_Interface_ID id);
18+
1719
bool NetworkManager::begin(){
1820
static bool initialized = false;
1921
if(!initialized){
@@ -44,18 +46,11 @@ bool NetworkManager::begin(){
4446
*/
4547
int NetworkManager::hostByName(const char* aHostname, IPAddress& aResult)
4648
{
47-
err_t err = ERR_OK;
48-
49-
// This should generally check if we have a global address assigned to one of the interfaces.
50-
// If such address is not assigned, there is no point in trying to get V6 from DNS as we will not be able to reach it.
51-
// That is of course, if 'preferV6' is not set to true
5249
static bool hasGlobalV6 = false;
53-
bool hasGlobalV6Now = false;//ToDo: implement this!
54-
if(hasGlobalV6 != hasGlobalV6Now){
55-
hasGlobalV6 = hasGlobalV6Now;
56-
dns_clear_cache();
57-
log_d("Clearing DNS cache");
58-
}
50+
static bool hasGlobalV4 = false;
51+
err_t err = ERR_OK;
52+
const char *servname = "0";
53+
struct addrinfo *res;
5954

6055
aResult = static_cast<uint32_t>(0);
6156

@@ -64,8 +59,33 @@ int NetworkManager::hostByName(const char* aHostname, IPAddress& aResult)
6459
return 1;
6560
}
6661

67-
const char *servname = "0";
68-
struct addrinfo *res;
62+
// This should generally check if we have a global address assigned to one of the interfaces.
63+
// If such address is not assigned, there is no point in trying to get V6 from DNS as we will not be able to reach it.
64+
bool hasGlobalV6Now = false;
65+
bool hasGlobalV4Now = false;
66+
for (int i = 0; i < ESP_NETIF_ID_MAX; ++i){
67+
NetworkInterface * iface = getNetifByID((Network_Interface_ID)i);
68+
if(iface != NULL) {
69+
if(iface->hasGlobalIPv6()) {
70+
hasGlobalV6Now = true;
71+
}
72+
if(iface->hasIP()) {
73+
hasGlobalV4Now = true;
74+
}
75+
}
76+
if (hasGlobalV6Now && hasGlobalV4Now){
77+
break;
78+
}
79+
}
80+
81+
// If the state of IP addresses has changed, clear the DNS cache
82+
if(hasGlobalV6 != hasGlobalV6Now || hasGlobalV4 != hasGlobalV4Now){
83+
hasGlobalV6 = hasGlobalV6Now;
84+
hasGlobalV4 = hasGlobalV4Now;
85+
dns_clear_cache();
86+
log_d("Clearing DNS cache");
87+
}
88+
6989
struct addrinfo hints;
7090
memset(&hints, 0, sizeof(hints));
7191
hints.ai_family = AF_UNSPEC;
@@ -130,8 +150,6 @@ bool NetworkManager::setHostname(const char * name)
130150
return true;
131151
}
132152

133-
NetworkInterface * getNetifByID(Network_Interface_ID id);
134-
135153
bool NetworkManager::setDefaultInterface(NetworkInterface & ifc)
136154
{
137155
return ifc.setDefault();

libraries/NetworkClientSecure/src/ssl_client.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,32 @@ int start_ssl_client(sslclient_context *ssl_client, const IPAddress& ip, uint32_
6262
return -1;
6363
}
6464

65-
log_v("Starting socket");
65+
int domain = ip.type() == IPv6 ? AF_INET6 : AF_INET;
66+
log_v("Starting socket (domain %d)", domain);
6667
ssl_client->socket = -1;
6768

68-
ssl_client->socket = lwip_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
69+
ssl_client->socket = lwip_socket(domain, SOCK_STREAM, IPPROTO_TCP);
6970
if (ssl_client->socket < 0) {
7071
log_e("ERROR opening socket");
7172
return ssl_client->socket;
7273
}
7374

7475
fcntl( ssl_client->socket, F_SETFL, fcntl( ssl_client->socket, F_GETFL, 0 ) | O_NONBLOCK );
75-
struct sockaddr_in serv_addr;
76-
memset(&serv_addr, 0, sizeof(serv_addr));
77-
serv_addr.sin_family = AF_INET;
78-
serv_addr.sin_addr.s_addr = ip;
79-
serv_addr.sin_port = htons(port);
76+
struct sockaddr_storage serv_addr = {};
77+
if (domain == AF_INET6) {
78+
struct sockaddr_in6 *tmpaddr = (struct sockaddr_in6 *)&serv_addr;
79+
tmpaddr->sin6_family = AF_INET6;
80+
for (int index = 0; index < 16; index++) {
81+
tmpaddr->sin6_addr.s6_addr[index] = ip[index];
82+
}
83+
tmpaddr->sin6_port = htons(port);
84+
tmpaddr->sin6_scope_id = ip.zone();
85+
} else {
86+
struct sockaddr_in *tmpaddr = (struct sockaddr_in *)&serv_addr;
87+
tmpaddr->sin_family = AF_INET;
88+
tmpaddr->sin_addr.s_addr = ip;
89+
tmpaddr->sin_port = htons(port);
90+
}
8091

8192
if(timeout <= 0){
8293
timeout = 30000; // Milli seconds.

libraries/USB/src/USBHIDKeyboard.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ size_t USBHIDKeyboard::pressRaw(uint8_t k)
222222
uint8_t i;
223223
if (k >= 0xE0 && k < 0xE8) {
224224
// it's a modifier key
225-
_keyReport.modifiers |= (1<<(k-0x80));
225+
_keyReport.modifiers |= (1<<(k-0xE0));
226226
} else if (k && k < 0xA5) {
227227
// Add k to the key report only if it's not already present
228228
// and if there is an empty slot.
@@ -253,7 +253,7 @@ size_t USBHIDKeyboard::releaseRaw(uint8_t k)
253253
uint8_t i;
254254
if (k >= 0xE0 && k < 0xE8) {
255255
// it's a modifier key
256-
_keyReport.modifiers &= ~(1<<(k-0x80));
256+
_keyReport.modifiers &= ~(1<<(k-0xE0));
257257
} else if (k && k < 0xA5) {
258258
// Test the key report to see if k is present. Clear it if it exists.
259259
// Check all positions in case the key is present more than once (which it shouldn't be)

0 commit comments

Comments
 (0)