Multicast mac-address or not

If one of the processes doesn't want to hold any multicast mac-address in its table, restricting the mac-address for further processing is the best option.


Multicast MAC Address in hexadecimal representation

I have written a sample program to verify the given mac-address is multicast or not. Similarly, broadcast mac-address program also can be written.

#include<stdio.h>

int is_mcast_eth_addr(unsigned int  *mac)
{
#if 0
    return *(mac+0) & 0x01; //I believe this is good way
#endif 
    if (((mac[0] == 0x01) && (mac[1] == 0x00) && (mac[2] == 0x5E)) ||
         ((mac[0] == 0x33) && (mac[1] == 0x33))) {
        printf("Given Mac-address is Multicast \t\n");
        return 1;
    }
    return 0;
}

int main()
{
    char *get_mac = "01005E010106";
    unsigned int mac_addr[6] = {0};
    char final[13] ="0";
    int mcast = 0;
    sscanf(get_mac, "%02X%02X%02X%02X%02X%02X \t", &mac_addr[0],&mac_addr[1],&mac_addr[2],&mac_addr[3],&mac_addr[4],&mac_addr[5]);
    mcast = is_mcast_eth_addr(mac_addr);
    snprintf(final, sizeof(final),"%02X%02X%02X%02X%02X%02X \t", mac_addr[0],mac_addr[1],mac_addr[2],mac_addr[3],mac_addr[4],mac_addr[5]);
    if (mcast == 1) {
        printf("Mac-address %s is Multicast \t\n",final);
    } else {
        printf("Mac-address %s is not Multicast \t\n",final);
    }
    return 1;
}


Output:
1
2
Given Mac-address is Multicast  
Mac-address 01005E01010

Comments