Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-esp32
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-esp32
Commits
d805b88c
Unverified
Commit
d805b88c
authored
Apr 05, 2024
by
Me No Dev
Committed by
GitHub
Apr 05, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(net): Add support for selecting the default network interface (#9457)
parent
9b32541c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
2 deletions
+63
-2
libraries/Network/src/NetworkInterface.cpp
libraries/Network/src/NetworkInterface.cpp
+38
-0
libraries/Network/src/NetworkInterface.h
libraries/Network/src/NetworkInterface.h
+4
-1
libraries/Network/src/NetworkManager.cpp
libraries/Network/src/NetworkManager.cpp
+17
-1
libraries/Network/src/NetworkManager.h
libraries/Network/src/NetworkManager.h
+4
-0
No files found.
libraries/Network/src/NetworkInterface.cpp
View file @
d805b88c
...
...
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "NetworkInterface.h"
#include "NetworkManager.h"
#include "esp_netif.h"
#include "esp_netif_defaults.h"
#include "esp_system.h"
...
...
@@ -538,6 +539,43 @@ String NetworkInterface::impl_name(void) const
return
String
(
netif_name
);
}
int
NetworkInterface
::
impl_index
()
const
{
if
(
_esp_netif
==
NULL
){
return
-
1
;
}
return
esp_netif_get_netif_impl_index
(
_esp_netif
);
}
int
NetworkInterface
::
route_prio
()
const
{
if
(
_esp_netif
==
NULL
){
return
-
1
;
}
return
esp_netif_get_route_prio
(
_esp_netif
);
}
bool
NetworkInterface
::
setDefault
()
{
if
(
_esp_netif
==
NULL
){
return
false
;
}
esp_err_t
err
=
esp_netif_set_default_netif
(
_esp_netif
);
if
(
err
!=
ESP_OK
){
log_e
(
"Failed to set default netif: %d"
,
err
);
return
false
;
}
return
true
;
}
bool
NetworkInterface
::
isDefault
()
const
{
if
(
_esp_netif
==
NULL
){
return
false
;
}
return
esp_netif_get_default_netif
()
==
_esp_netif
;
}
uint8_t
*
NetworkInterface
::
macAddress
(
uint8_t
*
mac
)
const
{
if
(
!
mac
||
_esp_netif
==
NULL
){
...
...
libraries/Network/src/NetworkInterface.h
View file @
d805b88c
...
...
@@ -8,7 +8,6 @@
#include "esp_netif_types.h"
#include "esp_event.h"
#include "Arduino.h"
#include "NetworkManager.h"
#include "Printable.h"
typedef
enum
{
...
...
@@ -54,6 +53,10 @@ class NetworkInterface: public Printable {
const
char
*
ifkey
()
const
;
const
char
*
desc
()
const
;
String
impl_name
()
const
;
int
impl_index
()
const
;
int
route_prio
()
const
;
bool
setDefault
();
bool
isDefault
()
const
;
uint8_t
*
macAddress
(
uint8_t
*
mac
)
const
;
String
macAddress
()
const
;
...
...
libraries/Network/src/NetworkManager.cpp
View file @
d805b88c
...
...
@@ -4,7 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "NetworkManager.h"
#include "NetworkInterface.h"
#include "IPAddress.h"
#include "esp_netif.h"
#include "lwip/dns.h"
...
...
@@ -133,6 +132,23 @@ bool NetworkManager::setHostname(const char * name)
NetworkInterface
*
getNetifByID
(
Network_Interface_ID
id
);
bool
NetworkManager
::
setDefaultInterface
(
NetworkInterface
&
ifc
)
{
return
ifc
.
setDefault
();
}
NetworkInterface
*
NetworkManager
::
getDefaultInterface
()
{
esp_netif_t
*
netif
=
esp_netif_get_default_netif
();
for
(
int
i
=
0
;
i
<
ESP_NETIF_ID_MAX
;
++
i
){
NetworkInterface
*
iface
=
getNetifByID
((
Network_Interface_ID
)
i
);
if
(
iface
!=
NULL
&&
iface
->
netif
()
==
netif
){
return
iface
;
}
}
return
NULL
;
}
size_t
NetworkManager
::
printTo
(
Print
&
out
)
const
{
size_t
bytes
=
0
;
...
...
libraries/Network/src/NetworkManager.h
View file @
d805b88c
...
...
@@ -6,6 +6,7 @@
#pragma once
#include "NetworkEvents.h"
#include "NetworkInterface.h"
#include "IPAddress.h"
#include "WString.h"
...
...
@@ -18,6 +19,9 @@ public:
uint8_t
*
macAddress
(
uint8_t
*
mac
);
String
macAddress
();
bool
setDefaultInterface
(
NetworkInterface
&
ifc
);
NetworkInterface
*
getDefaultInterface
();
size_t
printTo
(
Print
&
out
)
const
;
static
const
char
*
getHostname
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment