VSF Documented
etherdevice.h
Go to the documentation of this file.
1#ifndef __VSF_LINUX_ETHERDEVICE_H__
2#define __VSF_LINUX_ETHERDEVICE_H__
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8static inline void eth_broadcast_addr(u8 *addr)
9{
10 memset(addr, 0xFF, ETH_ALEN);
11}
12
13static inline bool is_local_ether_addr(const u8 *addr)
14{
15 return 0x02 & addr[0];
16}
17
18#if __IS_COMPILER_GCC__
19# pragma GCC diagnostic push
20# pragma GCC diagnostic ignored "-Wcast-align"
21#elif __IS_COMPILER_LLVM__ || __IS_COMPILER_ARM_COMPILER_6__
22# pragma clang diagnostic push
23# pragma clang diagnostic ignored "-Wcast-align"
24#endif
25
26static inline bool is_broadcast_ether_addr(const u8 *addr)
27{
28 return (*(const u16 *)(addr + 0) &
29 *(const u16 *)(addr + 2) &
30 *(const u16 *)(addr + 4)) == 0xffff;
31}
32
33static inline bool is_zero_ether_addr(const u8 *addr)
34{
35 return (*(const u16 *)(addr + 0) |
36 *(const u16 *)(addr + 2) |
37 *(const u16 *)(addr + 4)) == 0;
38}
39
40static inline bool is_multicast_ether_addr(const u8 *addr)
41{
42 u16 a = *(const u16 *)addr;
43#if __BYTE_ORDER == __BIG_ENDIAN
44 return 0x01 & (a >> ((sizeof(a) * 8) - 8));
45#else
46 return 0x01 & a;
47#endif
48}
49
50#if __IS_COMPILER_GCC__
51# pragma GCC diagnostic pop
52#elif __IS_COMPILER_LLVM__ || __IS_COMPILER_ARM_COMPILER_6__
53# pragma clang diagnostic pop
54#endif
55
56static inline bool is_unicast_ether_addr(const u8 *addr)
57{
58 return !is_multicast_ether_addr(addr);
59}
60
61static inline bool is_valid_ether_addr(const u8 *addr)
62{
63 return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
64}
65
66#ifdef __cplusplus
67}
68#endif
69
70#endif
#define ETH_ALEN
Definition if_ether.h:12
__u8 u8
Definition types.h:69
__u16 u16
Definition types.h:71
void * memset(void *s, int ch, size_t n)