/* Convert first 8 bytes of adapter's GID to a MAC address, * of the form: 00:FF:{gid}, in network byte order, ready * for use in an Ethernet header */ __u64 gid_to_mac(char *data) { int i; unsigned char val; __u64 mac = 0; for (i = 0; i < 8; i += 2) { val = HexStringToDecimalInt(data[i + 1]); val |= (HexStringToDecimalInt(data[i]) << 4); mac |= val << (24 - (4 * i)); } mac &= 0x00FFFFFFFFFF; mac |= 0x00FF00000000; return(hton64(mac) >> 16); }
BOOLEAN ParseMAC (MACADDR dest, const char *src) { int c; int mac_index = 0; BOOLEAN high_digit = FALSE; int delim_action = 1; MYASSERT (src); MYASSERT (dest); CLEAR_MAC (dest); while (c = *src++) { if (IsMacDelimiter (c)) { mac_index += delim_action; high_digit = FALSE; delim_action = 1; } else if (IsHexDigit (c)) { const int digit = HexStringToDecimalInt (c); if (mac_index < sizeof (MACADDR)) { if (!high_digit) { dest[mac_index] = (char)(digit); high_digit = TRUE; delim_action = 1; } else { dest[mac_index] = (char)(dest[mac_index] * 16 + digit); ++mac_index; high_digit = FALSE; delim_action = 0; } } else return FALSE; } else return FALSE; } return (mac_index + delim_action) >= sizeof (MACADDR); }
VOID GenerateRandomMac( __in MACADDR mac, __in const unsigned char *adapter_name ) { unsigned const char *cp = adapter_name; unsigned char c; unsigned int i = 2; unsigned int byte = 0; int brace = 0; int state = 0; CLEAR_MAC (mac); mac[0] = 0x00; mac[1] = 0xFF; while (c = *cp++) { if (i >= sizeof (MACADDR)) break; if (c == '{') brace = 1; if (IsHexDigit (c) && brace) { const unsigned int digit = HexStringToDecimalInt (c); if (state) { byte <<= 4; byte |= digit; mac[i++] = (unsigned char) byte; state = 0; } else { byte = digit; state = 1; } } } }