Skip to content

Commit

Permalink
net: shell: Print user friendly network interface name
Browse files Browse the repository at this point in the history
If network interface name support is enabled, print the name
when showing network interface data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
  • Loading branch information
jukkar committed Aug 25, 2023
1 parent e2a6dff commit d17402a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions subsys/net/ip/net_shell.c
Expand Up @@ -6,6 +6,7 @@

/*
* Copyright (c) 2016 Intel Corporation
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -378,8 +379,21 @@ static void iface_cb(struct net_if *iface, void *user_data)
return;
}

#if defined(CONFIG_NET_INTERFACE_NAME)
char ifname[CONFIG_NET_INTERFACE_NAME_LEN + 1] = { 0 };
int ret_name;

ret_name = net_if_get_name(iface, ifname, sizeof(name) - 1);
if (ret_name < 1 || ifname[0] == '\0') {
snprintk(ifname, sizeof(ifname), "?");
}

PR("\nInterface %s (%p) (%s) [%d]\n", ifname, iface, iface2str(iface, &extra),
net_if_get_by_iface(iface));
#else
PR("\nInterface %p (%s) [%d]\n", iface, iface2str(iface, &extra),
net_if_get_by_iface(iface));
#endif
PR("===========================%s\n", extra);

if (!net_if_is_up(iface)) {
Expand Down

0 comments on commit d17402a

Please sign in to comment.