22#include <idfxx/chrono>
220struct is_error_code_enum<
idfxx::netif::errc> : std::true_type {};
237extern const event_base<ip_event_id>
ip_events;
240inline event_base<ip_event_id> idfxx_get_event_base(ip_event_id*) {
304 ip_event_id::ap_sta_ip4_assigned
387 : _handle(std::exchange(other._handle,
nullptr))
388 , _owning(other._owning) {}
475#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
508#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
544#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
564#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
617#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
654#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
692#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
723#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
750#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
776#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
780inline void deinit() {
835 bool smooth_sync =
false;
836 bool server_from_dhcp =
false;
837 bool wait_for_sync =
true;
839 bool renew_servers_after_new_ip =
false;
840 ip_event_id renew_event_id = ip_event_id::sta_got_ip4;
841 std::vector<std::string> servers;
844#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
847void init(
const config&
cfg);
869#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
870inline void init(
const config&
cfg) {
897template<
typename Rep,
typename Period>
898[[
nodiscard]]
bool sync_wait(
const std::chrono::duration<Rep, Period>&
timeout) {
899 return detail::sync_wait_ms(std::chrono::duration_cast<std::chrono::milliseconds>(
timeout));
// end of idfxx_netif_sntp
924#include "sdkconfig.h"
925#ifdef CONFIG_IDFXX_STD_FORMAT
932struct formatter<
idfxx::netif::dns_type> {
933 constexpr auto parse(format_parse_context& ctx) {
return ctx.begin(); }
935 template<
typename FormatContext>
938 return std::copy(str.begin(), str.end(), ctx.out());
A MAC-48 (6-byte) hardware address.
Error category for network interface errors.
std::string message(int ec) const override final
Returns a human-readable message for the given error code.
const char * name() const noexcept override final
Returns the name of the error category.
Network interface handle.
std::vector< net::ip6_addr > get_all_ip6() const
Returns all IPv6 addresses of this interface.
void set_mac(const mac_address &mac)
Sets the MAC address.
interface & operator=(const interface &)=delete
result< net::ip6_addr > try_get_ip6_global() const
Returns the IPv6 global address of this interface.
net::ip6_addr get_ip6_global() const
Returns the IPv6 global address.
void create_ip6_linklocal()
Creates an IPv6 link-local address for this interface.
result< void > try_create_ip6_linklocal()
Creates an IPv6 link-local address for this interface.
bool is_up() const
Checks if the network interface is up.
void dhcp_client_stop()
Stops the DHCP client on this interface.
void set_ip4_info(const net::ip4_info &info)
Sets the IPv4 information.
bool is_dhcp_server_running() const
Checks if the DHCP server is running on this interface.
std::vector< net::ip6_addr > get_all_preferred_ip6() const
Returns all preferred IPv6 addresses of this interface.
result< void > try_dhcp_client_stop()
Stops the DHCP client on this interface.
result< void > try_set_ip4_info(const net::ip4_info &info)
Sets the IPv4 information of this interface.
void napt_enable(bool enable=true)
Enables or disables NAPT on this interface.
void dhcp_server_start()
Starts the DHCP server on this interface.
result< std::string > try_get_hostname() const
Returns the hostname of this interface.
void set_hostname(std::string_view hostname)
Sets the hostname.
flags< flag > get_flags() const
Returns the flags set on this interface.
interface(interface &&other) noexcept
Move constructs an interface, transferring ownership state.
void dhcp_client_start()
Starts the DHCP client on this interface.
interface(const interface &)=delete
result< void > try_set_mac(const mac_address &mac)
Sets the MAC address of this interface.
idfxx::event< ip_event_id, ip4_event_data > got_ip4_event() const
Returns the typed "got IP" event for this interface.
result< net::ip6_addr > try_get_ip6_linklocal() const
Returns the IPv6 link-local address of this interface.
result< void > try_dhcp_server_start()
Starts the DHCP server on this interface.
const char * key() const
Returns the interface key string.
bool is_dhcp_client_running() const
Checks if the DHCP client is running on this interface.
idfxx::event< ip_event_id > lost_ip4_event() const
Returns the typed "lost IP" event for this interface.
mac_address get_mac() const
Returns the MAC address.
const char * description() const
Returns the interface description string.
void set_dns(dns_type type, const dns_info &info)
Sets the DNS server information.
net::ip6_addr get_ip6_linklocal() const
Returns the IPv6 link-local address.
void dhcp_server_stop()
Stops the DHCP server on this interface.
result< void > try_set_dns(dns_type type, const dns_info &info)
Sets the DNS server information for this interface.
net::ip4_info get_ip4_info() const
Returns the current IPv4 information of this interface.
esp_netif_t * idf_handle() const noexcept
Returns the underlying ESP-NETIF handle.
result< void > try_set_hostname(std::string_view hostname)
Sets the hostname of this interface.
result< void > try_dhcp_server_stop()
Stops the DHCP server on this interface.
interface & operator=(interface &&other) noexcept
Move assigns an interface, transferring ownership state.
result< void > try_dhcp_client_start()
Starts the DHCP client on this interface.
dns_info get_dns(dns_type type) const
Returns the DNS server information.
result< mac_address > try_get_mac() const
Returns the MAC address of this interface.
result< dns_info > try_get_dns(dns_type type) const
Returns the DNS server information for this interface.
void set_route_priority(int priority)
Sets the route priority of this interface.
int get_route_priority() const
Returns the route priority of this interface.
std::string get_hostname() const
Returns the hostname.
result< void > try_napt_enable(bool enable=true)
Enables or disables NAPT (Network Address Port Translation) on this interface.
Concept for types that can be both received and posted as event data.
std::string to_string(core_id c)
Returns a string representation of a CPU core identifier.
struct esp_netif_obj esp_netif_t
constexpr idfxx::event< ip_event_id, ip4_event_data > eth_got_ip4
Ethernet received IPv4 address event with IP details.
const event_base< ip_event_id > ip_events
IP event base.
std::error_code make_error_code(errc e) noexcept
Creates an error code from an idfxx::netif::errc value.
constexpr idfxx::event< ip_event_id, ip6_event_data > got_ip6
Received IPv6 address event.
errc
Network interface error codes.
std::optional< interface > get_default()
Returns a non-owning handle to the default network interface.
constexpr idfxx::event< ip_event_id, ap_sta_ip4_assigned_event_data > ap_sta_ip4_assigned
Soft-AP assigned IP to a connected station event.
flag
Network interface flags.
@ ipv6_autoconfig_enabled
size_t get_nr_of_ifs()
Returns the number of registered network interfaces.
constexpr idfxx::event< ip_event_id > sta_lost_ip4
Station lost IPv4 address event.
constexpr idfxx::event< ip_event_id > eth_lost_ip4
Ethernet lost IPv4 address event.
dhcp_option_id
DHCP option identifiers.
@ vendor_class_identifier
@ router_solicitation_address
constexpr idfxx::event< ip_event_id, ip4_event_data > ppp_got_ip4
PPP interface received IPv4 address event with IP details.
void set_default(interface &iface)
Sets the given interface as the default network interface.
std::optional< interface > find_by_key(const char *key)
Finds a network interface by its key string.
constexpr idfxx::event< ip_event_id > ppp_lost_ip4
PPP interface lost IPv4 address event.
constexpr idfxx::event< ip_event_id, ip4_event_data > sta_got_ip4
Station received IPv4 address event with IP details.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
@ timeout
Operation timed out.
std::expected< T, std::error_code > result
result type wrapping a value or error code.
result< void > wrap(esp_err_t e)
Wraps an esp_err_t into a result<void>.
const netif::error_category & netif_category() noexcept
Returns a reference to the netif error category singleton.
std::unexpected< std::error_code > netif_error(esp_err_t e)
Creates an unexpected error from an ESP-IDF error code, mapping to netif error codes where possible.
IPv4 network interface information.
Information about an IP assigned to a station connected to an AP.
Information about an acquired IPv4 address.
Information about an acquired IPv6 address.