]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ether-addr-util: introduce several helper functions
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 6 Nov 2021 03:15:12 +0000 (12:15 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 8 Nov 2021 23:20:51 +0000 (08:20 +0900)
src/basic/ether-addr-util.h

index 794fc55bb837b5812b750ae5e10a154389503944..a7f42ccd1af1e908d924091133ce6daa328289e1 100644 (file)
@@ -6,6 +6,8 @@
 #include <stdbool.h>
 
 #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, &ETHER_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;