net server: IPv6 local link, Use BNetworkAddress tools for mac
* Stop using sscanf * Start using BNetworkAddress LinkLevelAddress and friends * Thanks Axel!
This commit is contained in:
@@ -863,29 +863,17 @@ NetServer::_ConfigureIPv6LinkLocal(const char* name)
|
|||||||
BNetworkInterface interface(name);
|
BNetworkInterface interface(name);
|
||||||
BNetworkAddress link;
|
BNetworkAddress link;
|
||||||
status_t result = interface.GetHardwareAddress(link);
|
status_t result = interface.GetHardwareAddress(link);
|
||||||
if (result != B_OK)
|
|
||||||
|
if (result != B_OK || link.LinkLevelAddressLength() != 6)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BString macString = link.ToString();
|
const uint8* mac = link.LinkLevelAddress();
|
||||||
|
|
||||||
int32 macLength = macString.Length();
|
|
||||||
if (macLength != 17) {
|
|
||||||
syslog(LOG_DEBUG, "%s: MacAddress length (%" B_PRIu32 ") for interface"
|
|
||||||
" '%s' is invalid\n", __func__, macLength, name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8 mac[6];
|
|
||||||
char* macBuffer = macString.LockBuffer(macLength);
|
|
||||||
sscanf(macBuffer, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
|
|
||||||
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
|
|
||||||
macString.UnlockBuffer(macLength);
|
|
||||||
|
|
||||||
// Check for a few failure situations
|
// Check for a few failure situations
|
||||||
static const char zeroMac[6] = {0, 0, 0, 0, 0, 0};
|
static const char zeroMac[6] = {0, 0, 0, 0, 0, 0};
|
||||||
static const char fullMac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
static const char fullMac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
if (memcmp(macBuffer, zeroMac, 6) == 0
|
if (memcmp(mac, zeroMac, 6) == 0
|
||||||
|| memcmp(macBuffer, fullMac, 6) == 0) {
|
|| memcmp(mac, fullMac, 6) == 0) {
|
||||||
// Mac address is all 0 or all FF's
|
// Mac address is all 0 or all FF's
|
||||||
syslog(LOG_DEBUG, "%s: MacAddress for interface '%s' is invalid.",
|
syslog(LOG_DEBUG, "%s: MacAddress for interface '%s' is invalid.",
|
||||||
__func__, name);
|
__func__, name);
|
||||||
|
|||||||
Reference in New Issue
Block a user