mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 17:19:44 -06:00
Fix MAC address reading on Windows.
This commit is contained in:
@ -13,6 +13,7 @@ set(SRCS BreakPoints.cpp
|
||||
Misc.cpp
|
||||
MsgHandler.cpp
|
||||
NandPaths.cpp
|
||||
Network.cpp
|
||||
SettingsHandler.cpp
|
||||
SDCardUtil.cpp
|
||||
StringUtil.cpp
|
||||
|
@ -75,6 +75,7 @@
|
||||
<ClInclude Include="MemoryUtil.h" />
|
||||
<ClInclude Include="MsgHandler.h" />
|
||||
<ClInclude Include="NandPaths.h" />
|
||||
<ClInclude Include="Network.h" />
|
||||
<ClInclude Include="SDCardUtil.h" />
|
||||
<ClInclude Include="SettingsHandler.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
@ -109,6 +110,7 @@
|
||||
<ClCompile Include="Misc.cpp" />
|
||||
<ClCompile Include="MsgHandler.cpp" />
|
||||
<ClCompile Include="NandPaths.cpp" />
|
||||
<ClCompile Include="Network.cpp" />
|
||||
<ClCompile Include="SDCardUtil.cpp" />
|
||||
<ClCompile Include="SettingsHandler.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
|
@ -36,6 +36,7 @@
|
||||
<ClInclude Include="MemoryUtil.h" />
|
||||
<ClInclude Include="MsgHandler.h" />
|
||||
<ClInclude Include="NandPaths.h" />
|
||||
<ClInclude Include="Network.h" />
|
||||
<ClInclude Include="SDCardUtil.h" />
|
||||
<ClInclude Include="SettingsHandler.h" />
|
||||
<ClInclude Include="StdConditionVariable.h" />
|
||||
@ -77,6 +78,7 @@
|
||||
<ClCompile Include="Misc.cpp" />
|
||||
<ClCompile Include="MsgHandler.cpp" />
|
||||
<ClCompile Include="NandPaths.cpp" />
|
||||
<ClCompile Include="Network.cpp" />
|
||||
<ClCompile Include="SDCardUtil.cpp" />
|
||||
<ClCompile Include="SettingsHandler.cpp" />
|
||||
<ClCompile Include="StringUtil.cpp" />
|
||||
|
70
Source/Core/Common/Network.cpp
Normal file
70
Source/Core/Common/Network.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright 2013 Dolphin Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <cctype>
|
||||
#include <ctime>
|
||||
|
||||
#include "Common/Network.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
void GenerateMacAddress(const MACConsumer type, u8* mac)
|
||||
{
|
||||
memset(mac, 0, MAC_ADDRESS_SIZE);
|
||||
|
||||
u8 const oui_bba[] = { 0x00, 0x09, 0xbf };
|
||||
u8 const oui_ios[] = { 0x00, 0x17, 0xab };
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case BBA:
|
||||
memcpy(mac, oui_bba, 3);
|
||||
break;
|
||||
case IOS:
|
||||
memcpy(mac, oui_ios, 3);
|
||||
break;
|
||||
}
|
||||
|
||||
srand((unsigned int)time(nullptr));
|
||||
|
||||
u8 id[3] =
|
||||
{
|
||||
(u8)rand(),
|
||||
(u8)rand(),
|
||||
(u8)rand()
|
||||
};
|
||||
|
||||
memcpy(&mac[3], id, 3);
|
||||
}
|
||||
|
||||
std::string MacAddressToString(const u8* mac)
|
||||
{
|
||||
return StringFromFormat("%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
mac[0], mac[1], mac[2],
|
||||
mac[3], mac[4], mac[5]);
|
||||
}
|
||||
|
||||
bool StringToMacAddress(const std::string& mac_string, u8* mac)
|
||||
{
|
||||
bool success = false;
|
||||
if (!mac_string.empty())
|
||||
{
|
||||
int x = 0;
|
||||
memset(mac, 0, MAC_ADDRESS_SIZE);
|
||||
|
||||
for (size_t i = 0; i < mac_string.size() && x < (MAC_ADDRESS_SIZE*2); ++i)
|
||||
{
|
||||
char c = tolower(mac_string.at(i));
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
mac[x / 2] |= (c - '0') << ((x & 1) ? 0 : 4); ++x;
|
||||
}
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
{
|
||||
mac[x / 2] |= (c - 'a' + 10) << ((x & 1) ? 0 : 4); ++x;
|
||||
}
|
||||
}
|
||||
success = x / 2 == MAC_ADDRESS_SIZE;
|
||||
}
|
||||
return success;
|
||||
}
|
24
Source/Core/Common/Network.h
Normal file
24
Source/Core/Common/Network.h
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2013 Dolphin Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
enum MACConsumer
|
||||
{
|
||||
BBA = 0,
|
||||
IOS = 1
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MAC_ADDRESS_SIZE = 6
|
||||
};
|
||||
|
||||
void GenerateMacAddress(const MACConsumer type, u8* mac);
|
||||
std::string MacAddressToString(const u8* mac);
|
||||
bool StringToMacAddress(const std::string& mac_string, u8* mac);
|
Reference in New Issue
Block a user