Check if a MAC address of type uint8_t* starts with xx:xx:xx

I found this piece of code:

bool check_whitelist(uint8_t *macAdress){
  unsigned int i=0;
  for (i=0; i<WHITELIST_LENGTH; i++) {
    if (! memcmp(macAdress, whitelist[i], ETH_MAC_LEN)) return true;
  }
  return false;
}

in this file.

And I’d like to change it so that instead of returning true if macAdress is in whitelist[], it returns true if macAdress starts with certain digits.

So I’d like to change it to something like this:

bool check_blacklist(uint8_t *macAdress){
  if (macAdress.startsWith("BE:EF:99")) {
    return true;
  } else {
    return false;
  }
}

How could I achieve that?

Typically, macAddress would be an array of 6 bytes. It appears you only want to check the first 3 so change the comparison to test the first 3 bytes

bool check_blacklist(uint8_t *macAdress){
  if (macAdress[0] ==0xBE && macAddress[1] == 0xEF && macAddress[2] == 0x99)) {
    return true;
  } else {
    return false;
  }
}

It's not an array though or is it? The type is uint8_t * from what I can tell. Wouldn't it be something like uint8_t[] * if it was an array?

Nope, macAdress is being treated as an array. Arrays and pointers are very closely related in C / C++. For example: https://codeforwin.org/2017/10/c-pointers-array-relationship-use.html

Thank you, that article was very helpful! And also thanks to blh64! :slight_smile: