cilium 1.15.1
把单个mac拆分成2个整数,做减法比较。
#include <stdio.h>
union macaddr {
struct {
__uint32_t p1;
__uint16_t p2;
};
__uint8_t addr[6];
};
static __always_inline int eth_addrcmp(const union macaddr *a,
const union macaddr *b)
{
int tmp;
tmp = a->p1 - b->p1;
if (!tmp)
tmp = a->p2 - b->p2;
return tmp;
}
int main() {
unsigned char mac1[6] = {1,1,1,1,1,1};
unsigned char mac2[6] = {1,1,1,1,1,2};
union macaddr *macaddr1 = (union macaddr*)mac1;
union macaddr *macaddr2 = (union macaddr*)mac2;
printf("%d\n", eth_addrcmp(macaddr1, macaddr2));
unsigned char mac3[6] = {1,1,1,1,1,1};
unsigned char mac4[6] = {1,1,1,1,1,1};
union macaddr *macaddr3 = (union macaddr*)mac3;
union macaddr *macaddr4 = (union macaddr*)mac4;
printf("%d\n", eth_addrcmp(macaddr3, macaddr4));
return 0;
}
标签:tmp,__,macaddr,union,unsigned,C语言,char,mac,比较
From: https://www.cnblogs.com/WJQ2017/p/18238457