Page MenuHomeFreeBSD

net: add ETHER_IS_ZERO macro similar to ETHER_IS_BROADCAST
Needs ReviewPublic

Authored by jacob.e.keller_intel.com on Mon, Aug 12, 10:53 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Some places in network code may need to verify that an ethernet address
is not the 'zero' address. Provide a standard macro ETHER_IS_ZERO for
this purpose, similar to the ETHER_IS_BROADCAST macro already available.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>

Diff Detail

Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 25855
Build 24426: arc lint + arc unit

Event Timeline

aleksandr.fedorov_itglobal.com added inline comments.
sys/net/ethernet.h
79

Is this correct? If one byte of mac address is equal zero than the whole expression equal 0x00.

sys/net/ethernet.h
79

Yea, this is incorrect, woops. Should be bitwise or.

Use bitwise OR instead of bitwise AND to correct implementation

It’s seems I found another incorrect solution:

#include <stdio.h>

int main()
{

unsigned char a = (1 << 0) ||(1<<1)||(1 <<2)||(1<<3)||(1<<4)||(1<<5);
printf("momentum more : %d\n", a);

return 0;

}

It’s seems I found another incorrect solution:
#include <stdio.h>
int main()
{

unsigned char a = (1 << 0) ||(1<<1)||(1 <<2)||(1<<3)||(1<<4)||(1<<5);
printf("momentum more : %d\n", a);
return 0;

}

It’s seems I found another incorrect solution:
#include <stdio.h>
int main()
{

unsigned char a = (1 << 0) ||(1<<1)||(1 <<2)||(1<<3)||(1<<4)||(1<<5);
printf("momentum more : %d\n", a);
return 0;

}

This uses boolean ||, not bitwise |

bitwise OR should correctly combine all of the chunks of the MAC address, and if any are non-zero, the whole thing will be non-zero.

Ops, you’re right. Sorry for the noise.