| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: util.c,v 1.19 2019/10/01 10:52:53 kardel Exp $ */ | | 1 | /* $NetBSD: util.c,v 1.20 2020/10/11 21:32:37 roy Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2008 David Young. All rights reserved. | | 4 | * Copyright (c) 2008 David Young. All rights reserved. |
5 | * | | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | | 7 | * modification, are permitted provided that the following conditions |
8 | * are met: | | 8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright | | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright | | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the | | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. | | 13 | * documentation and/or other materials provided with the distribution. |
14 | * | | 14 | * |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | | 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 | * SUCH DAMAGE. | | 25 | * SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | #include <sys/cdefs.h> | | 28 | #include <sys/cdefs.h> |
29 | #ifndef lint | | 29 | #ifndef lint |
30 | __RCSID("$NetBSD: util.c,v 1.19 2019/10/01 10:52:53 kardel Exp $"); | | 30 | __RCSID("$NetBSD: util.c,v 1.20 2020/10/11 21:32:37 roy Exp $"); |
31 | #endif /* not lint */ | | 31 | #endif /* not lint */ |
32 | | | 32 | |
33 | #include <ctype.h> | | 33 | #include <ctype.h> |
34 | #include <err.h> | | 34 | #include <err.h> |
35 | #include <errno.h> | | 35 | #include <errno.h> |
36 | #include <netdb.h> | | 36 | #include <netdb.h> |
37 | #include <stddef.h> | | 37 | #include <stddef.h> |
38 | #include <stdio.h> | | 38 | #include <stdio.h> |
39 | #include <stdlib.h> | | 39 | #include <stdlib.h> |
40 | #include <string.h> | | 40 | #include <string.h> |
41 | #include <unistd.h> | | 41 | #include <unistd.h> |
42 | #include <util.h> | | 42 | #include <util.h> |
43 | | | 43 | |
| @@ -265,28 +265,30 @@ print_link_addresses(prop_dictionary_t e | | | @@ -265,28 +265,30 @@ print_link_addresses(prop_dictionary_t e |
265 | for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { | | 265 | for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { |
266 | if (strcmp(ifname, ifa->ifa_name) != 0) | | 266 | if (strcmp(ifname, ifa->ifa_name) != 0) |
267 | continue; | | 267 | continue; |
268 | if (ifa->ifa_addr->sa_family != AF_LINK) | | 268 | if (ifa->ifa_addr->sa_family != AF_LINK) |
269 | continue; | | 269 | continue; |
270 | | | 270 | |
271 | sdl = satocsdl(ifa->ifa_addr); | | 271 | sdl = satocsdl(ifa->ifa_addr); |
272 | | | 272 | |
273 | memcpy(&iflr.addr, ifa->ifa_addr, MIN(ifa->ifa_addr->sa_len, | | 273 | memcpy(&iflr.addr, ifa->ifa_addr, MIN(ifa->ifa_addr->sa_len, |
274 | sizeof(iflr.addr))); | | 274 | sizeof(iflr.addr))); |
275 | iflr.flags = IFLR_PREFIX; | | 275 | iflr.flags = IFLR_PREFIX; |
276 | iflr.prefixlen = sdl->sdl_alen * NBBY; | | 276 | iflr.prefixlen = sdl->sdl_alen * NBBY; |
277 | | | 277 | |
278 | if (prog_ioctl(s, SIOCGLIFADDR, &iflr) == -1) | | 278 | if (prog_ioctl(s, SIOCGLIFADDR, &iflr) == -1) { |
279 | warn("%s: ioctl SIOCGLIFADDR", __func__); | | 279 | warn("%s: ioctl SIOCGLIFADDR", __func__); |
| | | 280 | continue; |
| | | 281 | } |
280 | | | 282 | |
281 | if (((iflr.flags & IFLR_ACTIVE) != 0) != print_active_only) | | 283 | if (((iflr.flags & IFLR_ACTIVE) != 0) != print_active_only) |
282 | continue; | | 284 | continue; |
283 | | | 285 | |
284 | if (getnameinfo(ifa->ifa_addr, ifa->ifa_addr->sa_len, | | 286 | if (getnameinfo(ifa->ifa_addr, ifa->ifa_addr->sa_len, |
285 | hbuf, sizeof(hbuf), NULL, 0, | | 287 | hbuf, sizeof(hbuf), NULL, 0, |
286 | Nflag ? 0 : NI_NUMERICHOST) == 0 && | | 288 | Nflag ? 0 : NI_NUMERICHOST) == 0 && |
287 | hbuf[0] != '\0') { | | 289 | hbuf[0] != '\0') { |
288 | printf("\t%s %s\n", | | 290 | printf("\t%s %s\n", |
289 | print_active_only ? "address:" : "link", hbuf); | | 291 | print_active_only ? "address:" : "link", hbuf); |
290 | } | | 292 | } |
291 | } | | 293 | } |
292 | freeifaddrs(ifap); | | 294 | freeifaddrs(ifap); |