mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 15:48:06 +02:00
shared: improve NM_ETHER_ADDR_INIT() helper macro
The macro should require exactly 6 parameters (for the 6 bytes of the address). On the other hand, we also should be able to use a macro like NM_ETHER_ADDR_INIT(NM_BRIDGE_GROUP_ADDRESS_DEF_BIN) To get that work properly, we need to expand the variadic macro once. Also, cast the result to the struct type. With this, it can not only be used for initialization, but also for assignment and temporary variables.
This commit is contained in:
parent
0db10dd5a7
commit
f125d821be
2 changed files with 13 additions and 4 deletions
|
|
@ -93,11 +93,20 @@ typedef struct {
|
|||
(x)->ether_addr_octet[0], (x)->ether_addr_octet[1], (x)->ether_addr_octet[2], \
|
||||
(x)->ether_addr_octet[3], (x)->ether_addr_octet[4], (x)->ether_addr_octet[5]
|
||||
|
||||
#define NM_ETHER_ADDR_INIT(...) \
|
||||
{ \
|
||||
.ether_addr_octet = {__VA_ARGS__}, \
|
||||
#define _NM_ETHER_ADDR_INIT(a0, a1, a2, a3, a4, a5) \
|
||||
{ \
|
||||
.ether_addr_octet = { \
|
||||
(a0), \
|
||||
(a1), \
|
||||
(a2), \
|
||||
(a3), \
|
||||
(a4), \
|
||||
(a5), \
|
||||
}, \
|
||||
}
|
||||
|
||||
#define NM_ETHER_ADDR_INIT(...) ((NMEtherAddr) _NM_ETHER_ADDR_INIT(__VA_ARGS__))
|
||||
|
||||
static inline int
|
||||
nm_ether_addr_cmp(const NMEtherAddr *a, const NMEtherAddr *b)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ static void
|
|||
to_sysfs_group_address_sys(const char *group_address, NMEtherAddr *out_addr)
|
||||
{
|
||||
if (group_address == NULL) {
|
||||
*out_addr = (NMEtherAddr) NM_ETHER_ADDR_INIT(NM_BRIDGE_GROUP_ADDRESS_DEF_BIN);
|
||||
*out_addr = NM_ETHER_ADDR_INIT(NM_BRIDGE_GROUP_ADDRESS_DEF_BIN);
|
||||
return;
|
||||
}
|
||||
if (!nm_utils_hwaddr_aton(group_address, out_addr, ETH_ALEN))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue