MCPcopy Create free account
hub / github.com/F-Stack/f-stack / print_entry

Function print_entry

tools/arp/arp.c:622–717  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

620 */
621
622static void
623print_entry(struct sockaddr_dl *sdl,
624 struct sockaddr_in *addr, struct rt_msghdr *rtm)
625{
626 const char *host;
627 struct hostent *hp;
628 struct if_nameindex *p;
629
630 if (ifnameindex == NULL)
631 if ((ifnameindex = if_nameindex()) == NULL)
632 xo_err(1, "cannot retrieve interface names");
633
634 xo_open_instance("arp-cache");
635
636 if (nflag == 0)
637 hp = gethostbyaddr((caddr_t)&(addr->sin_addr),
638 sizeof addr->sin_addr, AF_INET);
639 else
640 hp = 0;
641 if (hp)
642 host = hp->h_name;
643 else {
644 host = "?";
645 if (h_errno == TRY_AGAIN)
646 nflag = 1;
647 }
648 xo_emit("{:hostname/%s} ({:ip-address/%s}) at ", host,
649 inet_ntoa(addr->sin_addr));
650 if (sdl->sdl_alen) {
651 if ((sdl->sdl_type == IFT_ETHER ||
652 sdl->sdl_type == IFT_L2VLAN ||
653 sdl->sdl_type == IFT_BRIDGE) &&
654 sdl->sdl_alen == ETHER_ADDR_LEN)
655 xo_emit("{:mac-address/%s}",
656 ether_ntoa((struct ether_addr *)LLADDR(sdl)));
657 else {
658 int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0;
659
660 xo_emit("{:mac-address/%s}", link_ntoa(sdl) + n);
661 }
662 } else
663 xo_emit("{d:/(incomplete)}{en:incomplete/true}");
664
665 for (p = ifnameindex; p && p->if_index && p->if_name; p++) {
666 if (p->if_index == sdl->sdl_index) {
667 xo_emit(" on {:interface/%s}", p->if_name);
668 break;
669 }
670 }
671
672 if (rtm->rtm_rmx.rmx_expire == 0)
673 xo_emit("{d:/ permanent}{en:permanent/true}");
674 else {
675 static struct timespec tp;
676 if (tp.tv_sec == 0)
677 clock_gettime(CLOCK_MONOTONIC, &tp);
678 if ((expire_time = rtm->rtm_rmx.rmx_expire - tp.tv_sec) > 0)
679 xo_emit(" expires in {:expires/%d} seconds",

Callers

nothing calls this directly

Calls 6

xo_errFunction · 0.85
xo_open_instanceFunction · 0.85
xo_emitFunction · 0.85
link_ntoaFunction · 0.85
xo_close_instanceFunction · 0.85
if_nameindexClass · 0.70

Tested by

no test coverage detected