MAC address data type
A variable of type mac_addr_t is used to hold the value of MAC address.
The MAC address data type is an abstract data type and you cannot use it directly with standard C
unary or binary operators.
Only local or global variables of type mac_addr_t are supported.
A variable of this type can also be stored in an associate array either as a key or as a value.
Vue supports the following characteristics and operations for the MAC address type variables:
Declaration of MAC address variable
mac_addr_t m1; // global variable of type
__auto mac_addr_t m2; // auto variable of type
m2 = __etherhdr->src_addr; // store source MAC address in a local variable
mac_aso[“src_mac_addr”] = __etherhdr->src_addr ; // store in an associative array.
The signed, unsigned, register, static, thread, and kernel qualifiers are not supported for the
mac_addr_t type variables.
Assignment operation
The assignment (=) operator allows a mac_addr_t type variable to be assigned to
another mac_addr_t type variable. The original values of the variable is
overwritten. No typecasting is allowed from or to the mac_addr_t variable types.
In the following example, the content of the mac_addr_t m1 is assigned to m2.
mac_addr_t m1, m2; // Declares two MAC address variables.
m1 = __etherhdr->src_addr; // Get the source MAC address of the packet in m1.
m2 = m1 ; // Get the content of m1 into m2.
Comparison operation
Only equality (==) and inequality (!=) operators are allowed for the mac_addr_t
variables. The result of the equality operator is True (1) if both contains the same MAC address
values or False (0) otherwise.
mac_addr_t type variables.
if ( m1 == m2) // comparing two mac_addr_t type variables.
printf(“Mac addresses are equal”); else printf(“Mac addresses are not equal”);Printing MAC address type variables
mac_addr_t type variable can be printed with “%M” format specifier
in the printf() function of Vue. An associative array that has mac_addr_t type
variables as key or value (or both) can be printed by using the print() function.
printf(“ Source MAC address=[%M]\n”, __etherhdr->src_addr);
mac_aso[“src_mac_address”] = __etherhdr->src_addr ; // Store source MAC address as value in an associative array mac_aso.
print(mac_aso);
- The array of the mac_addr_t variable cannot be declared.
- The mac_addr_t variables cannot be used as a member of a struct or a union.
- Pointer to mac_addr_t variable is not allowed.
- Typecasting of mac_addr_t variable to any other type or typecasting any other type to mac_addr_t type is not allowed.
- No arithmetic operator (+, -, *, /, ++, -- etc) can be used with mac_addr_t type variable.