Show IP address when address has a label
If an address has been added with a label, ensure the correct address is shown.
This commit is contained in:
parent
5abed82419
commit
6a75ea9aea
@ -29,6 +29,7 @@ const char *get_ip_addr(const char *interface, int family) {
|
|||||||
|
|
||||||
struct ifaddrs *ifaddr, *addrp;
|
struct ifaddrs *ifaddr, *addrp;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
int interface_len = strlen(interface);
|
||||||
|
|
||||||
getifaddrs(&ifaddr);
|
getifaddrs(&ifaddr);
|
||||||
|
|
||||||
@ -39,13 +40,13 @@ const char *get_ip_addr(const char *interface, int family) {
|
|||||||
for (addrp = ifaddr;
|
for (addrp = ifaddr;
|
||||||
|
|
||||||
(addrp != NULL &&
|
(addrp != NULL &&
|
||||||
(strcmp(addrp->ifa_name, interface) != 0 ||
|
(strncmp(addrp->ifa_name, interface, interface_len) != 0 ||
|
||||||
addrp->ifa_addr == NULL ||
|
addrp->ifa_addr == NULL ||
|
||||||
addrp->ifa_addr->sa_family != family));
|
addrp->ifa_addr->sa_family != family));
|
||||||
|
|
||||||
addrp = addrp->ifa_next) {
|
addrp = addrp->ifa_next) {
|
||||||
/* Check if the interface is down */
|
/* Check if the interface is down */
|
||||||
if (strcmp(addrp->ifa_name, interface) != 0)
|
if (strncmp(addrp->ifa_name, interface, interface_len) != 0)
|
||||||
continue;
|
continue;
|
||||||
found = true;
|
found = true;
|
||||||
if ((addrp->ifa_flags & IFF_RUNNING) == 0) {
|
if ((addrp->ifa_flags & IFF_RUNNING) == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user