Example #1
0
static void
_print_eth(struct eth_hdr* e, int length)
{
		char d[20], s[20];
		eth_ntop(&e->eth_dst, &d[0], sizeof(d));
		eth_ntop(&e->eth_src, &s[0], sizeof(s));

		printf("%s > %s type 0x%04hx length %d", d, s, htons(e->eth_type), length);
}
Example #2
0
static void
setethfield(lua_State* L, int tindex, const char* field, const uint8_t addr[ETHER_ADDR_LEN])
{
    char addrstr[] = "11:22:33:44:55:66";
    eth_addr_t ethaddr;

    memcpy(ethaddr.data, addr, ETHER_ADDR_LEN);

    setstringfield(L, tindex, field, eth_ntop(&ethaddr, addrstr, sizeof(addrstr)));
}
Example #3
0
char *
addr_ntop(const struct addr *src, char *dst, size_t size)
{
	if (src->addr_type == ADDR_TYPE_IP && size >= 20) {
		if (ip_ntop(&src->addr_ip, dst, size) != NULL) {
			if (src->addr_bits != IP_ADDR_BITS)
				sprintf(dst + strlen(dst), "/%d",
				    src->addr_bits);
			return (dst);
		}
	} else if (src->addr_type == ADDR_TYPE_IP6 && size >= 42) {
		if (ip6_ntop(&src->addr_ip6, dst, size) != NULL) {
			if (src->addr_bits != IP6_ADDR_BITS)
				sprintf(dst + strlen(dst), "/%d",
				    src->addr_bits);
			return (dst);
		}
	} else if (src->addr_type == ADDR_TYPE_ETH && size >= 18) {
		if (src->addr_bits == ETH_ADDR_BITS)
			return (eth_ntop(&src->addr_eth, dst, size));
	}
	errno = EINVAL;
	return (NULL);
}