a8516df79bdf071c29bf5bde220d08b9afecca7f
[openvswitch] / include / mac.h
1 #ifndef MAC_H
2 #define MAC_H 1
3
4 #include <string.h>
5 #include <inttypes.h>
6 #include <stdbool.h>
7 #include "packets.h"
8
9 static inline bool mac_is_multicast(const uint8_t mac[ETH_ADDR_LEN])
10 {
11     return mac[0] & 0x80;
12 }
13
14 static inline bool mac_is_private(const uint8_t mac[ETH_ADDR_LEN])
15 {
16     return mac[0] & 0x40;
17 }
18
19 static inline bool mac_is_broadcast(const uint8_t mac[ETH_ADDR_LEN])
20 {
21     return (mac[0] & mac[1] & mac[2] & mac[3] & mac[4] & mac[5]) == 0xff;
22 }
23
24 static inline bool mac_is_zero(const uint8_t mac[ETH_ADDR_LEN])
25 {
26     return (mac[0] | mac[1] | mac[2] | mac[3] | mac[4] | mac[5]) == 0;
27 }
28
29 static inline bool mac_equals(const uint8_t a[ETH_ADDR_LEN],
30                               const uint8_t b[ETH_ADDR_LEN]) 
31 {
32     return !memcmp(a, b, ETH_ADDR_LEN);
33 }
34
35 #define MAC_FMT                                                         \
36     "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8
37 #define MAC_ARGS(mac)                                           \
38     (mac)[0], (mac)[1], (mac)[2], (mac)[3], (mac)[4], (mac)[5]
39
40
41 #endif /* mac.h */