From 7bd9febf65e98eb1f4b4d51afa2479c442066235 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Sat, 3 Nov 2018 23:43:49 +0100 Subject: libxtables: add and use mac print helpers This changes ebtables-nft to consistently print mac address with two characters, i.e. 00:01:02:03:04:0a, not 0:1:2:3:4:a. Will require another bump of vcurrent/vage. Suggested-by: Pablo Neira Ayuso Signed-off-by: Florian Westphal --- libxtables/xtables.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'libxtables') diff --git a/libxtables/xtables.c b/libxtables/xtables.c index 34a084f4..11231fc4 100644 --- a/libxtables/xtables.c +++ b/libxtables/xtables.c @@ -2077,6 +2077,28 @@ void xtables_print_num(uint64_t number, unsigned int format) printf(FMT("%4lluT ","%lluT "), (unsigned long long)number); } +void xtables_print_mac(const unsigned char *macaddress) +{ + unsigned int i; + + printf("%02x", macaddress[0]); + for (i = 1; i < 6; ++i) + printf(":%02x", macaddress[i]); +} + +void xtables_print_mac_and_mask(const unsigned char *mac, const unsigned char *mask) +{ + static const char hlpmsk[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + + xtables_print_mac(mac); + + if (memcmp(mask, hlpmsk, 6) == 0) + return; + + printf("/"); + xtables_print_mac(mask); +} + void xtables_parse_val_mask(struct xt_option_call *cb, unsigned int *val, unsigned int *mask, const struct xtables_lmap *lmap) -- cgit v1.2.3