Post by s***@gmail.comSorry for the confusion. What I want is I have 2 MAC address
1. 00:5E:6E:2A:AA:BB
2. AA:BB:CC:DD:EE:FF
The first MAC address is in decimal format. 00,94,110,42,xx,xx
The second MAC address is in MAC address Format AA:BB:CC:DD:EE:FF
I don't know a lot about the different representations of MACs, but I
would compare each of the six "sections" of the MAC address one by
one. To do this, convert the text representations of each section to a
common ground, like an int.
You'll need to write a routine converting a decimal string to an int,
and a hexadecimal string to an int. Then compare the ints.
A decimal-to-int routine would consist basically of
int atoi(char const * s) {
unsigned i = 0;
int value = 0;
while (s && '0' < s[i] && s[i] < '9')
value = value * 10 + (s[i++] - '0');
return value;
}
A hexadecimal routine, htoi, is a little more complicated because you
have to handle the ASCII letters 'a' through 'f' and 'A' through 'F'.
I'd also worry about "i" running away past the end of "s" in a robust
implementation.
So, that would basically give us
bool are_macs_equal(char const * dmac, char const *hmac) {
int j = 0;
unsigned idmac = 0;
unsigned ihmac = 0;
while (j < 6) {
if (atoi(dmac + idmac) != htoi(hmac + ihmac))
break; // they're different, bail
j++; // another section is equal
while (dmac[idmac++] != ':') /* scan past delimiter */;
while (hmac[ihmac++] != ':') /* ditto */;
}
return (j == 6);
}
Actually, you'll want to watch that "while(dmac[idmac++] != ':')"
doesn't skip over the terminating null character either. But that's
the basic idea.
--Jonathan
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]