Skip to content

Commit e4f4e64

Browse files
Jarno LamsaOlli-Pekka Puolitaival
authored andcommitted
Use nanostack-libservice stoip4 to check if address is ipv4
1 parent a508896 commit e4f4e64

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

TEST_APPS/device/socket_app/cmd_ifconfig.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "mbed-client-cli/ns_cmdline.h"
2020
#include "mbed-trace/mbed_trace.h"
2121

22+
#include "ip4string.h"
23+
2224
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
2325
#error [NOT_SUPPORTED] No network configuration found for this target.
2426
#endif
@@ -42,26 +44,16 @@ int cmd_ifconfig(int argc, char *argv[]);
4244
const char* MAN_IFCONFIG = " ifup interface up\r\n"\
4345
" ifdown interface down\r\n";
4446

45-
static bool is_ipv4(const char *str)
46-
{
47-
int dot_count = 0;
48-
for (int i = 0; str[i]; i++) {
49-
if (str[i] == '.' && ++dot_count == 3) {
50-
return true;
51-
}
52-
}
53-
return false;
54-
}
55-
5647
static void ifconfig_print()
5748
{
58-
if(!net)
49+
if(!net) {
5950
cmd_printf("No interface configured\r\n");
6051
return;
52+
}
6153
const char *str = net->get_ip_address();
62-
6354
if (str) {
64-
if (is_ipv4(str)) {
55+
uint8_t buf[4];
56+
if (stoip4(str, strlen(str), buf)) {
6557
cmd_printf("IPv4 if addr: %s\r\n", str);
6658
} else {
6759
cmd_printf("IPv6 if addr:\r\n [0]: %s\r\n", str);

0 commit comments

Comments
 (0)