Beispiel #1
0
static void sll_print_full(struct pkt_buff *pkt)
{
	struct sockaddr_ll *sll = pkt->sll;
	char addr_str[40] = {};

	tprintf(" [ Linux \"cooked\"");
	tprintf(" Pkt Type %d (%s)", sll->sll_pkttype,
		pkt_type2str(sll->sll_pkttype));
	tprintf(", If Type %d (%s)", sll->sll_hatype,
		device_type2str(sll->sll_hatype));
	tprintf(", Addr Len %d", sll->sll_halen);
	tprintf(", Src (%s)", device_addr2str(sll->sll_addr, sll->sll_halen,
		sll->sll_hatype, addr_str, sizeof(addr_str)));
	tprintf(", Proto 0x%x", ntohs(sll->sll_protocol));
	tprintf(" ]\n");

	switch (pcap_devtype_to_linktype(sll->sll_hatype)) {
	case LINKTYPE_EN10MB:
	case ___constant_swab32(LINKTYPE_EN10MB):
		pkt_set_dissector(pkt, &eth_lay2, ntohs(sll->sll_protocol));
		break;
	case LINKTYPE_NETLINK:
	case ___constant_swab32(LINKTYPE_NETLINK):
		pkt->dissector = &nlmsg_ops;
		break;
	default:
		tprintf(" [ Unknown protocol ]\n");
	}
}
Beispiel #2
0
static void sll_print_less(struct pkt_buff *pkt)
{
	struct sockaddr_ll *sll = pkt->sll;
	char addr_str[40] = {};

	tprintf(" Pkt Type %d (%s)", sll->sll_pkttype,
		pkt_type2str(sll->sll_pkttype));
	tprintf(", If Type %d (%s)", sll->sll_hatype,
		device_type2str(sll->sll_hatype));
	tprintf(", Addr Len %d", sll->sll_halen);
	tprintf(", Src (%s)", device_addr2str(sll->sll_addr, sll->sll_halen,
		sll->sll_hatype, addr_str, sizeof(addr_str)));
	tprintf(", Proto 0x%x", ntohs(sll->sll_protocol));
}
Beispiel #3
0
static void rtnl_print_ifinfo(struct nlmsghdr *hdr)
{
	struct ifinfomsg *ifi = NLMSG_DATA(hdr);
	struct rtattr *attr = IFLA_RTA(ifi);
	uint32_t attrs_len = IFLA_PAYLOAD(hdr);
	char flags[256];
	char if_addr[64] = {};
	char *af_link = "unknown";

	if (hdr->nlmsg_len < NLMSG_LENGTH(sizeof(*ifi)))
		return;

	if (ifi->ifi_family == AF_UNSPEC)
		af_link = "unspec";
	else if (ifi->ifi_family == AF_BRIDGE)
		af_link = "bridge";

	tprintf(" [ Link Family %d (%s%s%s)", ifi->ifi_family,
			colorize_start(bold), af_link, colorize_end());
	tprintf(", Type %d (%s%s%s)", ifi->ifi_type,
			colorize_start(bold),
			device_type2str(ifi->ifi_type),
			colorize_end());
	tprintf(", Index %d", ifi->ifi_index);
	tprintf(", Flags 0x%x (%s%s%s)", ifi->ifi_flags,
			colorize_start(bold),
			rtnl_link_flags2str(ifi->ifi_flags, flags,
				sizeof(flags)),
			colorize_end());
	tprintf(", Change 0x%x (%s%s%s) ]\n", ifi->ifi_change,
			colorize_start(bold),
			rtnl_link_flags2str(ifi->ifi_change, flags,
				sizeof(flags)),
			colorize_end());

	for (; RTA_OK(attr, attrs_len); attr = RTA_NEXT(attr, attrs_len)) {
		switch (attr->rta_type) {
		case IFLA_ADDRESS:
			rta_fmt(attr, "Address %s",
					device_addr2str(RTA_DATA(attr),
						RTA_LEN(attr), ifi->ifi_type,
						if_addr, sizeof(if_addr)));
			break;
		case IFLA_BROADCAST:
			rta_fmt(attr, "Broadcast %s",
					device_addr2str(RTA_DATA(attr),
						RTA_LEN(attr), ifi->ifi_type,
						if_addr, sizeof(if_addr)));
			break;
		case IFLA_IFNAME:
			rta_fmt(attr, "Name %s%s%s",
					colorize_start(bold), RTA_STR(attr),
					colorize_end());
			break;
		case IFLA_MTU:
			rta_fmt(attr, "MTU %d", RTA_INT(attr));
			break;
		case IFLA_LINK:
			rta_fmt(attr, "Link %d", RTA_INT(attr));
			break;
		case IFLA_QDISC:
			rta_fmt(attr, "QDisc %s", RTA_STR(attr));
			break;
		case IFLA_OPERSTATE:
			{
				uint8_t st = RTA_UINT8(attr);
				char states[256];

				rta_fmt(attr, "Operation state 0x%x (%s%s%s)",
						st,
						colorize_start(bold),
						rtnl_link_operstate2str(st,
							states, sizeof(states)),
						colorize_end());
			}
			break;
		case IFLA_LINKMODE:
			{
				uint8_t mode = RTA_UINT8(attr);
				char str[32];

				rta_fmt(attr, "Mode 0x%x (%s%s%s)", mode,
						colorize_start(bold),
						rtnl_link_mode2str(mode, str,
							sizeof(str)),
						colorize_end());
			}
			break;
		case IFLA_GROUP:
			rta_fmt(attr, "Group %d", RTA_INT(attr));
			break;
		case IFLA_TXQLEN:
			rta_fmt(attr, "Tx queue len %d", RTA_INT(attr));
			break;
		case IFLA_NET_NS_PID:
			rta_fmt(attr, "Network namespace pid %d",
					RTA_INT(attr));
			break;
		case IFLA_NET_NS_FD:
			rta_fmt(attr, "Network namespace fd %d", RTA_INT(attr));
			break;
		default:
			rta_fmt(attr, "0x%x", attr->rta_type);
			break;
		}
	}
}