3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 06:29:23 +01:00

client: Don't try to print addresses if not connected

This commit is contained in:
Denis Kenzior 2021-10-26 14:29:26 -05:00
parent 062fc7852a
commit 4b1ce76549

View File

@ -145,6 +145,66 @@ static void check_errors_method_callback(struct l_dbus_message *message,
dbus_message_has_error(message);
}
static void display_addresses(const char *device_name)
{
struct ifaddrs *ifa;
struct ifaddrs *cur;
bool have_address = false;
char addrstr[INET6_ADDRSTRLEN];
int r;
if (getifaddrs(&ifa) == -1)
return;
for (cur = ifa; cur; cur = cur->ifa_next) {
if (cur->ifa_addr == NULL)
continue;
if (strcmp(cur->ifa_name, device_name))
continue;
if (cur->ifa_addr->sa_family == AF_INET6) {
struct sockaddr_in6 *si6 =
(struct sockaddr_in6 *) cur->ifa_addr;
if (IN6_IS_ADDR_LINKLOCAL(&si6->sin6_addr))
continue;
if (!inet_ntop(AF_INET6, &si6->sin6_addr,
addrstr, sizeof(addrstr)))
continue;
have_address = true;
display("%s%*s %-*s%-*s\n", MARGIN, 8, "", 20,
"IPv6 address", 47, addrstr);
} else if (cur->ifa_addr->sa_family == AF_INET) {
struct sockaddr_in *si =
(struct sockaddr_in *) cur->ifa_addr;
if (!inet_ntop(AF_INET, &si->sin_addr,
addrstr, sizeof(addrstr)))
continue;
have_address = true;
display("%s%*s %-*s%-*s\n", MARGIN, 8, "", 20,
"IPv4 address", 47, addrstr);
}
}
freeifaddrs(ifa);
if (have_address)
return;
r = daemon_netconfig_enabled();
if (r < 0 || r == 1)
return;
display("%s%*s %-*s%-*s\n", MARGIN, 8, "", 20,
"No IP addresses", 47, "Is DHCP client configured?");
}
static void display_station(const char *device_name,
const struct proxy_interface *proxy)
{
@ -158,6 +218,8 @@ static void display_station(const char *device_name,
display("%s%*s %-*s%-*s\n", MARGIN, 8, "", 20,
"Connected network", 47,
network_get_name(station->connected_network));
display_addresses(device_name);
/*
* If connected the diagnostic interface is presumably up so
* don't add the table footer just yet.
@ -601,65 +663,6 @@ static enum cmd_status cmd_scan(const char *device_name,
return CMD_STATUS_TRIGGERED;
}
static void display_addresses(const char *device_name)
{
struct ifaddrs *ifa;
struct ifaddrs *cur;
bool have_address = false;
char addrstr[INET6_ADDRSTRLEN];
int r;
if (getifaddrs(&ifa) == -1)
return;
for (cur = ifa; cur; cur = cur->ifa_next) {
if (cur->ifa_addr == NULL)
continue;
if (strcmp(cur->ifa_name, device_name))
continue;
if (cur->ifa_addr->sa_family == AF_INET6) {
struct sockaddr_in6 *si6 =
(struct sockaddr_in6 *) cur->ifa_addr;
if (IN6_IS_ADDR_LINKLOCAL(&si6->sin6_addr))
continue;
if (!inet_ntop(AF_INET6, &si6->sin6_addr,
addrstr, sizeof(addrstr)))
continue;
have_address = true;
display("%s%*s %-*s%-*s\n", MARGIN, 8, "", 20,
"IPv6 address", 47, addrstr);
} else if (cur->ifa_addr->sa_family == AF_INET) {
struct sockaddr_in *si =
(struct sockaddr_in *) cur->ifa_addr;
if (!inet_ntop(AF_INET, &si->sin_addr,
addrstr, sizeof(addrstr)))
continue;
have_address = true;
display("%s%*s %-*s%-*s\n", MARGIN, 8, "", 20,
"IPv4 address", 47, addrstr);
}
}
freeifaddrs(ifa);
if (have_address)
return;
r = daemon_netconfig_enabled();
if (r < 0 || r == 1)
return;
display("%s%*s %-*s%-*s\n", MARGIN, 8, "", 20,
"No IP addresses", 47, "Is DHCP client configured?");
}
static void get_diagnostics_callback(struct l_dbus_message *message,
void *user_data)
{
@ -695,7 +698,6 @@ static enum cmd_status cmd_show(const char *device_name,
}
display_station(device_name, station);
display_addresses(device_name);
/*
* No need to query additional diagnostic information if IWD has