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:
Thomas Haller 2020-11-19 11:26:32 +01:00
parent 0db10dd5a7
commit f125d821be
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 13 additions and 4 deletions

View file

@ -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)
{

View file

@ -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))