arp.c revision 1.55.8.3 1 /* $NetBSD: arp.c,v 1.55.8.3 2018/07/27 09:55:50 martin Exp $ */
2
3 /*
4 * Copyright (c) 1984, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Sun Microsystems, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 #include <sys/cdefs.h>
36 #ifndef lint
37 __COPYRIGHT("@(#) Copyright (c) 1984, 1993\
38 The Regents of the University of California. All rights reserved.");
39 #endif /* not lint */
40
41 #ifndef lint
42 #if 0
43 static char sccsid[] = "@(#)arp.c 8.3 (Berkeley) 4/28/95";
44 #else
45 __RCSID("$NetBSD: arp.c,v 1.55.8.3 2018/07/27 09:55:50 martin Exp $");
46 #endif
47 #endif /* not lint */
48
49 /*
50 * arp - display, set, and delete arp table entries
51 */
52
53 #include <sys/param.h>
54 #include <sys/file.h>
55 #include <sys/socket.h>
56 #include <sys/sysctl.h>
57 #include <sys/ioctl.h>
58
59 #include <net/if.h>
60 #include <net/if_dl.h>
61 #include <net/if_ether.h>
62 #include <net/if_types.h>
63 #include <net/route.h>
64 #include <netinet/in.h>
65 #include <netinet/if_inarp.h>
66 #include <arpa/inet.h>
67
68 #include <err.h>
69 #include <errno.h>
70 #include <netdb.h>
71 #include <nlist.h>
72 #include <paths.h>
73 #include <stdio.h>
74 #include <stdlib.h>
75 #include <string.h>
76 #include <unistd.h>
77 #include <ifaddrs.h>
78
79 #include "prog_ops.h"
80
81 static int is_llinfo(const struct sockaddr_dl *, int);
82 static int delete_one(struct rt_msghdr *);
83 static void dump(uint32_t);
84 static void delete(const char *, const char *);
85 static void sdl_print(const struct sockaddr_dl *);
86 static int getifname(u_int16_t, char *, size_t);
87 static int atosdl(const char *s, struct sockaddr_dl *sdl);
88 static int file(const char *);
89 static void get(const char *);
90 static int getinetaddr(const char *, struct in_addr *);
91 static int getsocket(void);
92 static struct rt_msghdr *
93 rtmsg(const int, const int, struct rt_msghdr *,
94 const struct sockaddr_inarp *, const struct sockaddr_dl *);
95 static int set(int, char **);
96 static void usage(void) __dead;
97
98 static int aflag, nflag, vflag;
99 static struct sockaddr_in so_mask = {
100 .sin_len = 8,
101 .sin_addr = {
102 .s_addr = 0xffffffff
103 }
104 };
105 static struct sockaddr_inarp blank_sin = {
106 .sin_len = sizeof(blank_sin),
107 .sin_family = AF_INET
108 };
109 static struct sockaddr_dl blank_sdl = {
110 .sdl_len = sizeof(blank_sdl),
111 .sdl_family = AF_LINK
112 };
113
114 static int expire_time, flags, export_only, doing_proxy, found_entry;
115
116 int
117 main(int argc, char **argv)
118 {
119 int ch;
120 int op = 0;
121
122 setprogname(argv[0]);
123
124 while ((ch = getopt(argc, argv, "andsfv")) != -1)
125 switch((char)ch) {
126 case 'a':
127 aflag = 1;
128 break;
129 case 'd':
130 case 's':
131 case 'f':
132 if (op)
133 usage();
134 op = ch;
135 break;
136 case 'n':
137 nflag = 1;
138 break;
139 case 'v':
140 vflag = 1;
141 break;
142 default:
143 usage();
144 }
145 argc -= optind;
146 argv += optind;
147
148 if (!op && aflag)
149 op = 'a';
150
151 if (prog_init && prog_init() == -1)
152 err(1, "init failed");
153
154 switch((char)op) {
155 case 'a':
156 dump(0);
157 break;
158 case 'd':
159 if (aflag && argc == 0)
160 delete(NULL, NULL);
161 else {
162 if (aflag || argc < 1 || argc > 2)
163 usage();
164 delete(argv[0], argv[1]);
165 }
166 break;
167 case 's':
168 if (argc < 2 || argc > 7)
169 usage();
170 return (set(argc, argv) ? 1 : 0);
171 case 'f':
172 if (argc != 1)
173 usage();
174 return (file(argv[0]));
175 default:
176 if (argc != 1)
177 usage();
178 get(argv[0]);
179 break;
180 }
181 return (0);
182 }
183
184 /*
185 * Process a file to set standard arp entries
186 */
187 static int
188 file(const char *name)
189 {
190 char *line, *argv[5];
191 int i, retval;
192 FILE *fp;
193
194 if (!strcmp(name, "-")) {
195 fp = stdin;
196 } else {
197 fp = fopen(name, "r");
198 if (fp == NULL) {
199 err(1, "Cannot open %s", name);
200 }
201 }
202 retval = 0;
203 for (; (line = fparseln(fp, NULL, NULL, NULL, 0)) != NULL; free(line)) {
204 char **ap, *inputstring;
205
206 inputstring = line;
207 for (ap = argv; ap < &argv[sizeof(argv) / sizeof(argv[0])] &&
208 (*ap = stresep(&inputstring, " \t", '\\')) != NULL;) {
209 if (**ap != '\0')
210 ap++;
211 }
212 i = ap - argv;
213 if (i < 2) {
214 warnx("bad line: %s", line);
215 retval = 1;
216 continue;
217 }
218 if (set(i, argv))
219 retval = 1;
220 }
221 if (fp != stdin)
222 (void)fclose(fp);
223 return retval;
224 }
225
226 static int
227 getsocket(void)
228 {
229 int s;
230 s = prog_socket(PF_ROUTE, SOCK_RAW, 0);
231 if (s < 0)
232 err(1, "socket");
233 return s;
234 }
235
236 static int
237 getlink(const char *name, struct sockaddr_dl *sdl)
238 {
239 struct ifaddrs *ifap, *ifa;
240
241 if (getifaddrs(&ifap) != 0) {
242 warn("getifaddrs");
243 return 0;
244 }
245
246 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
247 if (ifa->ifa_addr->sa_family != AF_LINK)
248 continue;
249 if (strcmp(ifa->ifa_name, name) != 0)
250 continue;
251 memcpy(sdl, ifa->ifa_addr, sizeof(*sdl));
252 freeifaddrs(ifap);
253 return 1;
254 }
255 freeifaddrs(ifap);
256 return 0;
257 }
258
259 /*
260 * Set an individual arp entry
261 */
262 static int
263 set(int argc, char **argv)
264 {
265 struct sockaddr_inarp *sina;
266 struct sockaddr_dl *sdl = NULL;
267 struct rt_msghdr *rtm;
268 char *host = argv[0], *eaddr;
269 struct sockaddr_inarp sin_m = blank_sin; /* struct copy */
270 struct sockaddr_dl sdl_m = blank_sdl; /* struct copy */
271 int s;
272
273 eaddr = argv[1];
274
275 s = getsocket();
276 argc -= 2;
277 argv += 2;
278
279 if (getinetaddr(host, &sin_m.sin_addr) == -1)
280 return (1);
281 if (atosdl(eaddr, &sdl_m))
282 warnx("invalid link-level address '%s'", eaddr);
283 doing_proxy = flags = export_only = expire_time = 0;
284 for (; argc-- > 0; argv++) {
285 if (strncmp(argv[0], "temp", 4) == 0) {
286 struct timeval timev;
287 (void)gettimeofday(&timev, 0);
288 expire_time = timev.tv_sec + 20 * 60;
289 }
290 else if (strncmp(argv[0], "pub", 3) == 0) {
291 flags |= RTF_ANNOUNCE;
292 doing_proxy = 1;
293 if (argc && strncmp(argv[1], "pro", 3) == 0) {
294 export_only = 1;
295 argc--; argv++;
296 }
297 } else if (strncmp(argv[0], "trail", 5) == 0) {
298 warnx("%s: Sending trailers is no longer supported",
299 host);
300 } else if (strcmp(argv[0], "ifscope") == 0) {
301 if (argc == 0) {
302 warnx("missing interface for ifscope");
303 continue;
304 }
305 argc--;
306 argv++;
307 if (!getlink(argv[0], &sdl_m))
308 warnx("cannot get link address for %s", argv[0]);
309 }
310
311 }
312 tryagain:
313 rtm = rtmsg(s, RTM_GET, NULL, &sin_m, &sdl_m);
314 if (rtm == NULL) {
315 warn("%s", host);
316 return (1);
317 }
318 sina = (struct sockaddr_inarp *)(void *)(rtm + 1);
319 sdl = (struct sockaddr_dl *)(void *)(RT_ROUNDUP(sina->sin_len) +
320 (char *)(void *)sina);
321 if (sina->sin_addr.s_addr == sin_m.sin_addr.s_addr) {
322 if (is_llinfo(sdl, rtm->rtm_flags))
323 goto overwrite;
324 if (doing_proxy == 0) {
325 warnx("set: can only proxy for %s", host);
326 return (1);
327 }
328 if (sin_m.sin_other & SIN_PROXY) {
329 warnx("set: proxy entry exists for non 802 device");
330 return (1);
331 }
332 sin_m.sin_other = SIN_PROXY;
333 export_only = 1;
334 goto tryagain;
335 }
336 overwrite:
337 if (sdl->sdl_family != AF_LINK) {
338 warnx("cannot intuit interface index and type for %s",
339 host);
340 return (1);
341 }
342 sdl_m.sdl_type = sdl->sdl_type;
343 sdl_m.sdl_index = sdl->sdl_index;
344 sin_m.sin_other = 0;
345 if (doing_proxy && export_only)
346 sin_m.sin_other = SIN_PROXY;
347 rtm = rtmsg(s, RTM_ADD, NULL, &sin_m, &sdl_m);
348 if (vflag)
349 (void)printf("%s (%s) added\n", host, eaddr);
350 return (rtm == NULL) ? 1 : 0;
351 }
352
353 /*
354 * Display an individual arp entry
355 */
356 static void
357 get(const char *host)
358 {
359 struct sockaddr_inarp sin = blank_sin; /* struct copy */
360
361 if (getinetaddr(host, &sin.sin_addr) == -1)
362 exit(1);
363 dump(sin.sin_addr.s_addr);
364 if (found_entry == 0)
365 errx(1, "%s (%s) -- no entry", host, inet_ntoa(sin.sin_addr));
366 }
367
368
369 static int
370 is_llinfo(const struct sockaddr_dl *sdl, int rtflags)
371 {
372 if (sdl->sdl_family != AF_LINK ||
373 (rtflags & (RTF_LLDATA|RTF_GATEWAY)) != RTF_LLDATA)
374 return 0;
375
376 switch (sdl->sdl_type) {
377 case IFT_ETHER:
378 case IFT_FDDI:
379 case IFT_ISO88023:
380 case IFT_ISO88024:
381 case IFT_ISO88025:
382 case IFT_ARCNET:
383 return 1;
384 default:
385 return 0;
386 }
387 }
388
389 /*
390 * Delete an arp entry
391 */
392 int
393 delete_one(struct rt_msghdr *rtm)
394 {
395 struct sockaddr_inarp *sina;
396 struct sockaddr_dl *sdl;
397 int s;
398
399 s = getsocket();
400 sina = (struct sockaddr_inarp *)(void *)(rtm + 1);
401 sdl = (struct sockaddr_dl *)(void *)(RT_ROUNDUP(sina->sin_len) +
402 (char *)(void *)sina);
403 if (sdl->sdl_family != AF_LINK)
404 return (1);
405 rtm = rtmsg(s, RTM_DELETE, rtm, sina, sdl);
406 if (rtm == NULL)
407 return (1);
408 return (0);
409 }
410
411 /*
412 * Dump the entire arp table
413 */
414 void
415 dump(uint32_t addr)
416 {
417 int mib[6];
418 size_t needed;
419 char ifname[IFNAMSIZ];
420 char *lim, *buf, *next;
421 const char *host;
422 struct rt_msghdr *rtm;
423 struct sockaddr_inarp *sina;
424 struct sockaddr_dl *sdl;
425 struct hostent *hp;
426
427 mib[0] = CTL_NET;
428 mib[1] = PF_ROUTE;
429 mib[2] = 0;
430 mib[3] = AF_INET;
431 mib[4] = NET_RT_FLAGS;
432 mib[5] = 0;
433 if (prog_sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
434 err(1, "route-sysctl-estimate");
435 if (needed == 0)
436 return;
437 if ((buf = malloc(needed)) == NULL)
438 err(1, "malloc");
439 if (prog_sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
440 err(1, "actual retrieval of routing table");
441 lim = buf + needed;
442 for (next = buf; next < lim; next += rtm->rtm_msglen) {
443 rtm = (struct rt_msghdr *)(void *)next;
444 sina = (struct sockaddr_inarp *)(void *)(rtm + 1);
445 sdl = (struct sockaddr_dl *)(void *)
446 (RT_ROUNDUP(sina->sin_len) + (char *)(void *)sina);
447 if (addr) {
448 if (addr != sina->sin_addr.s_addr)
449 continue;
450 found_entry = 1;
451 }
452 if (nflag == 0)
453 hp = gethostbyaddr((const char *)(void *)
454 &(sina->sin_addr),
455 sizeof sina->sin_addr, AF_INET);
456 else
457 hp = NULL;
458
459 host = hp ? hp->h_name : "?";
460
461 (void)printf("%s (%s) at ", host, inet_ntoa(sina->sin_addr));
462 if (sdl->sdl_alen)
463 sdl_print(sdl);
464 else
465 (void)printf("(incomplete)");
466
467 if (sdl->sdl_index) {
468 if (getifname(sdl->sdl_index, ifname, sizeof(ifname)) == 0)
469 (void)printf(" on %s", ifname);
470 }
471
472 if (rtm->rtm_rmx.rmx_expire == 0)
473 (void)printf(" permanent");
474 if (sina->sin_other & SIN_PROXY)
475 (void)printf(" published (proxy only)");
476 if (rtm->rtm_addrs & RTA_NETMASK) {
477 sina = (struct sockaddr_inarp *)(void *)
478 (RT_ROUNDUP(sdl->sdl_len) + (char *)(void *)sdl);
479 if (sina->sin_addr.s_addr == 0xffffffff)
480 (void)printf(" published");
481 if (sina->sin_len != 8)
482 (void)printf("(weird)");
483 }
484 (void)printf("\n");
485 }
486 free(buf);
487 }
488
489 /*
490 * Delete the entire arp table
491 */
492 void
493 delete(const char *host, const char *info)
494 {
495 int mib[6];
496 size_t needed;
497 char *lim, *buf, *next;
498 struct rt_msghdr *rtm;
499 struct sockaddr_inarp *sina;
500 struct sockaddr_inarp sin_m = blank_sin; /* struct copy */
501 bool found = false;
502
503 if (host != NULL) {
504 int ret = getinetaddr(host, &sin_m.sin_addr);
505 if (ret == -1)
506 return;
507 }
508 if (info && strncmp(info, "pro", 3) == 0)
509 sin_m.sin_other = SIN_PROXY;
510
511 retry:
512 mib[0] = CTL_NET;
513 mib[1] = PF_ROUTE;
514 mib[2] = 0;
515 mib[3] = AF_INET;
516 mib[4] = NET_RT_FLAGS;
517 mib[5] = RTF_LLDATA;
518 if (prog_sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
519 err(1, "route-sysctl-estimate");
520 if (needed == 0)
521 return;
522 if ((buf = malloc(needed)) == NULL)
523 err(1, "malloc");
524 if (prog_sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
525 free(buf);
526 if (errno == ENOBUFS)
527 goto retry;
528 err(1, "actual retrieval of routing table");
529 }
530 lim = buf + needed;
531
532 for (next = buf; next < lim; next += rtm->rtm_msglen) {
533 int ret;
534 rtm = (struct rt_msghdr *)(void *)next;
535 sina = (struct sockaddr_inarp *)(void *)(rtm + 1);
536 if (host != NULL &&
537 sina->sin_addr.s_addr != sin_m.sin_addr.s_addr)
538 continue;
539 found = true;
540 ret = delete_one(rtm);
541 if (vflag && ret == 0) {
542 (void)printf("%s (%s) deleted\n", host,
543 inet_ntoa(sina->sin_addr));
544 }
545 }
546 if (host != NULL && !found)
547 warnx("delete: can't locate %s", host);
548 free(buf);
549 }
550
551 void
552 sdl_print(const struct sockaddr_dl *sdl)
553 {
554 char hbuf[NI_MAXHOST];
555
556 if (getnameinfo((const struct sockaddr *)(const void *)sdl,
557 (socklen_t)sdl->sdl_len,
558 hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0)
559 (void)printf("<invalid>");
560 else
561 (void)printf("%s", hbuf);
562 }
563
564 static int
565 atosdl(const char *ss, struct sockaddr_dl *sdl)
566 {
567 int i;
568 unsigned long b;
569 char *endp;
570 char *p;
571 char *t, *r;
572
573 p = LLADDR(sdl);
574 endp = ((char *)(void *)sdl) + sdl->sdl_len;
575 i = 0;
576
577 b = strtoul(ss, &t, 16);
578 if (b > 255 || t == ss)
579 return 1;
580
581 *p++ = (char)b;
582 ++i;
583 while ((p < endp) && (*t++ == ':')) {
584 b = strtoul(t, &r, 16);
585 if (b > 255 || r == t)
586 break;
587 *p++ = (char)b;
588 ++i;
589 t = r;
590 }
591 sdl->sdl_alen = i;
592
593 return 0;
594 }
595
596 static void
597 usage(void)
598 {
599 const char *progname;
600
601 progname = getprogname();
602 (void)fprintf(stderr, "Usage: %s [-n] hostname\n", progname);
603 (void)fprintf(stderr, " %s [-nv] -a\n", progname);
604 (void)fprintf(stderr, " %s [-v] -d [-a|hostname [proxy]]\n",
605 progname);
606 (void)fprintf(stderr, " %s -s hostname ether_addr [temp] [pub [proxy]]\n",
607 progname);
608 (void)fprintf(stderr, " %s -f filename\n", progname);
609 exit(1);
610 }
611
612 static struct rt_msghdr *
613 rtmsg(const int s, const int cmd, struct rt_msghdr *_rtm,
614 const struct sockaddr_inarp *sin, const struct sockaddr_dl *sdl)
615 {
616 static int seq;
617 struct rt_msghdr *rtm = _rtm;
618 char *cp;
619 int l;
620 static struct {
621 struct rt_msghdr m_rtm;
622 char m_space[512];
623 } m_rtmsg;
624 pid_t pid;
625
626 errno = 0;
627 if (rtm != NULL) {
628 memcpy(&m_rtmsg, rtm, rtm->rtm_msglen);
629 rtm = &m_rtmsg.m_rtm;
630 goto doit;
631 }
632 (void)memset(&m_rtmsg, 0, sizeof(m_rtmsg));
633 rtm = &m_rtmsg.m_rtm;
634 cp = m_rtmsg.m_space;
635
636 rtm->rtm_flags = flags;
637 rtm->rtm_version = RTM_VERSION;
638
639 switch (cmd) {
640 default:
641 errx(1, "internal wrong cmd");
642 /*NOTREACHED*/
643 case RTM_ADD:
644 rtm->rtm_addrs |= RTA_GATEWAY;
645 rtm->rtm_rmx.rmx_expire = expire_time;
646 rtm->rtm_inits = RTV_EXPIRE;
647 rtm->rtm_flags |= (RTF_HOST | RTF_STATIC | RTF_LLDATA);
648 if (doing_proxy) {
649 if (!export_only) {
650 rtm->rtm_addrs |= RTA_NETMASK;
651 rtm->rtm_flags &= ~RTF_HOST;
652 }
653 }
654 rtm->rtm_addrs |= RTA_DST;
655 break;
656 case RTM_GET:
657 rtm->rtm_flags |= RTF_LLDATA;
658 rtm->rtm_addrs |= RTA_DST | RTA_GATEWAY;
659 }
660
661 #define NEXTADDR(w, s) \
662 if (rtm->rtm_addrs & (w)) { \
663 (void)memcpy(cp, &s, \
664 (size_t)((const struct sockaddr *)&s)->sa_len); \
665 RT_ADVANCE(cp, ((const struct sockaddr *)&s)); \
666 }
667
668 NEXTADDR(RTA_DST, *sin);
669 NEXTADDR(RTA_GATEWAY, *sdl);
670 NEXTADDR(RTA_NETMASK, so_mask);
671
672 rtm->rtm_msglen = cp - (char *)(void *)&m_rtmsg;
673 doit:
674 l = rtm->rtm_msglen;
675 rtm->rtm_seq = ++seq;
676 rtm->rtm_type = cmd;
677 if (prog_write(s, &m_rtmsg, (size_t)l) < 0) {
678 if (errno != ESRCH || cmd != RTM_DELETE) {
679 warn("writing to routing socket");
680 return NULL;
681 }
682 }
683
684 pid = prog_getpid();
685 do {
686 l = prog_read(s, &m_rtmsg, sizeof(m_rtmsg));
687 } while (l > 0 && (rtm->rtm_seq != seq || rtm->rtm_pid != pid));
688 if (l < 0)
689 warn("read from routing socket");
690 return rtm;
691 }
692
693 static int
694 getinetaddr(const char *host, struct in_addr *inap)
695 {
696 struct hostent *hp;
697
698 if (inet_aton(host, inap) == 1)
699 return (0);
700 if ((hp = gethostbyname(host)) == NULL) {
701 warnx("%s: %s", host, hstrerror(h_errno));
702 return (-1);
703 }
704 (void)memcpy(inap, hp->h_addr, sizeof(*inap));
705 return (0);
706 }
707
708 static int
709 getifname(u_int16_t ifindex, char *ifname, size_t l)
710 {
711 int i;
712 struct ifaddrs *addr;
713 const struct sockaddr_dl *sdl = NULL;
714 static struct ifaddrs* ifaddrs = NULL;
715
716 if (ifaddrs == NULL) {
717 i = getifaddrs(&ifaddrs);
718 if (i != 0)
719 err(1, "getifaddrs");
720 }
721
722 for (addr = ifaddrs; addr; addr = addr->ifa_next) {
723 if (addr->ifa_addr == NULL ||
724 addr->ifa_addr->sa_family != AF_LINK)
725 continue;
726
727 sdl = (const struct sockaddr_dl *)(void *)addr->ifa_addr;
728 if (sdl && sdl->sdl_index == ifindex) {
729 (void) strlcpy(ifname, addr->ifa_name, l);
730 return 0;
731 }
732 }
733
734 return -1;
735 }
736