diff --git a/src/net/linux/addrs.c b/src/net/linux/addrs.c index c8a904eda..2d825f3df 100644 --- a/src/net/linux/addrs.c +++ b/src/net/linux/addrs.c @@ -81,6 +81,7 @@ static bool parse_msg_addr(struct nlmsghdr *msg, ssize_t len, for (nlh = msg; NLMSG_OK(nlh, len); nlh = NLMSG_NEXT(nlh, len)) { struct sa sa; uint32_t flags; + void *addr; char if_name[IF_NAMESIZE]; if (nlh->nlmsg_type == NLMSG_DONE) { @@ -109,13 +110,19 @@ static bool parse_msg_addr(struct nlmsghdr *msg, ssize_t len, continue; } + if (rta_tb[IFA_LOCAL]) + /* looks like point-to-point network, use local + * address, instead of peer */ + addr = RTA_DATA(rta_tb[IFA_LOCAL]); + else + addr = RTA_DATA(rta_tb[IFA_ADDRESS]); + if (ifa->ifa_family == AF_INET) { sa_init(&sa, AF_INET); - sa.u.in.sin_addr.s_addr = - *(uint32_t *)RTA_DATA(rta_tb[IFA_ADDRESS]); + sa.u.in.sin_addr.s_addr = *(uint32_t *)addr; } else if (ifa->ifa_family == AF_INET6) { - sa_set_in6(&sa, RTA_DATA(rta_tb[IFA_ADDRESS]), 0); + sa_set_in6(&sa, addr, 0); sa_set_scopeid(&sa, ifa->ifa_index); } else