From: Yu Watanabe Date: Sat, 6 Nov 2021 03:15:12 +0000 (+0900) Subject: ether-addr-util: introduce several helper functions X-Git-Tag: v250-rc1~327^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1f86a3fe52c71af7f46381bf45c2efe580a19dcc;p=thirdparty%2Fsystemd.git ether-addr-util: introduce several helper functions --- diff --git a/src/basic/ether-addr-util.h b/src/basic/ether-addr-util.h index 794fc55bb83..a7f42ccd1af 100644 --- a/src/basic/ether-addr-util.h +++ b/src/basic/ether-addr-util.h @@ -6,6 +6,8 @@ #include #include "hash-funcs.h" +#include "macro.h" +#include "memory-util.h" /* This is MAX_ADDR_LEN as defined in linux/netdevice.h, but net/if_arp.h * defines a macro of the same name with a much lower size. */ @@ -60,6 +62,26 @@ static inline bool ether_addr_is_null(const struct ether_addr *addr) { return ether_addr_equal(addr, ÐER_ADDR_NULL); } +static inline bool ether_addr_is_broadcast(const struct ether_addr *addr) { + assert(addr); + return memeqbyte(0xff, addr->ether_addr_octet, ETH_ALEN); +} + +static inline bool ether_addr_is_multicast(const struct ether_addr *addr) { + assert(addr); + return FLAGS_SET(addr->ether_addr_octet[0], 0x01); +} + +static inline bool ether_addr_is_unicast(const struct ether_addr *addr) { + return !ether_addr_is_multicast(addr); +} + +static inline bool ether_addr_is_local(const struct ether_addr *addr) { + /* Determine if the Ethernet address is locally-assigned one (IEEE 802) */ + assert(addr); + return !FLAGS_SET(addr->ether_addr_octet[0], 0x02); +} + int ether_addr_from_string(const char *s, struct ether_addr *ret); extern const struct hash_ops ether_addr_hash_ops;