hwaddr_matches


Description:


public bool hwaddr_matches (void* hwaddr1, ssize_t hwaddr1_len, void* hwaddr2, ssize_t hwaddr2_len)

Generalized hardware address comparison function.

Tests if hwaddr1 and hwaddr2 "equal" (or more precisely, "equivalent"), with several advantages over a simple cmp:

  1. If hwaddr1_len or hwaddr2_len is -1, then the corresponding address is assumed to be ASCII rather than binary, and will be converted to binary before being compared.
  2. If hwaddr1 or hwaddr2 is null, it is treated instead as though it was a zero-filled buffer hwaddr1_len or hwaddr2_len bytes long.
  3. If hwaddr1 and hwaddr2 are InfiniBand hardware addresses (that is, if they are <literal>INFINIBAND_ALEN< /literal> bytes long in binary form) then only the last 8 bytes are compared, since those are the only bytes that actually identify the hardware. (The other 12 bytes will change depending on the configuration of the InfiniBand fabric that the device is connected to.)

If a passed-in ASCII hardware address cannot be parsed, or would parse to an address larger than nm_utils_hwaddr_len_max, then it will silently fail to match. (This means that externally-provided address strings do not need to be sanity-checked before comparing them against known good addresses; they are guaranteed to not match if they are invalid.)

Parameters:

hwaddr1

pointer to a binary or ASCII hardware address, or null

hwaddr1_len

size of hwaddr1, or -1 if hwaddr1 is ASCII

hwaddr2

pointer to a binary or ASCII hardware address, or null

hwaddr2_len

size of hwaddr2, or -1 if hwaddr2 is ASCII

Returns:

true if hwaddr1 and hwaddr2 are equivalent, false if they are different (or either of them is invalid).


Namespace: NM.Utils
Package: libnm