diff --git a/libraries/AP_Networking/AP_Networking.cpp b/libraries/AP_Networking/AP_Networking.cpp index dd926a31e5..303b50ab98 100644 --- a/libraries/AP_Networking/AP_Networking.cpp +++ b/libraries/AP_Networking/AP_Networking.cpp @@ -442,6 +442,13 @@ int ap_networking_printf(const char *fmt, ...) return 0; } +// address to string using a static return buffer +const char *AP_Networking::address_to_str(uint32_t addr) +{ + static char buf[16]; // 16 for aaa.bbb.ccc.ddd + return SocketAPM::inet_addr_to_str(addr, buf, sizeof(buf)); +} + #ifdef LWIP_PLATFORM_ASSERT void ap_networking_platform_assert(const char *msg, int line, const char *file) { diff --git a/libraries/AP_Networking/AP_Networking.h b/libraries/AP_Networking/AP_Networking.h index c83f0e26da..f5db359962 100644 --- a/libraries/AP_Networking/AP_Networking.h +++ b/libraries/AP_Networking/AP_Networking.h @@ -139,6 +139,9 @@ public: // convert string to ethernet mac address static bool convert_str_to_macaddr(const char *mac_str, uint8_t addr[6]); + // address to string using a static return buffer for scripting + static const char *address_to_str(uint32_t addr); + // helper functions to convert between 32bit Netmask and counting consecutive bits and back static uint32_t convert_netmask_bitcount_to_ip(const uint32_t netmask_bitcount); static uint8_t convert_netmask_ip_to_bitcount(const uint32_t netmask_ip);