mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-10-24 08:59:15 +00:00
Common/Network: Add BluetoothAddress struct and string conversion functions.
This commit is contained in:
parent
b1e8de82a6
commit
b2fef6ee1f
2 changed files with 26 additions and 0 deletions
|
|
@ -86,6 +86,21 @@ std::optional<MACAddress> StringToMacAddress(std::string_view mac_string)
|
||||||
return std::make_optional(mac);
|
return std::make_optional(mac);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string BluetoothAddressToString(BluetoothAddress bdaddr)
|
||||||
|
{
|
||||||
|
std::ranges::reverse(bdaddr);
|
||||||
|
return MacAddressToString(std::bit_cast<MACAddress>(bdaddr));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<BluetoothAddress> StringToBluetoothAddress(std::string_view str)
|
||||||
|
{
|
||||||
|
auto result = StringToMacAddress(str);
|
||||||
|
if (!result)
|
||||||
|
return std::nullopt;
|
||||||
|
std::ranges::reverse(*result);
|
||||||
|
return std::bit_cast<BluetoothAddress>(*result);
|
||||||
|
}
|
||||||
|
|
||||||
EthernetHeader::EthernetHeader() = default;
|
EthernetHeader::EthernetHeader() = default;
|
||||||
|
|
||||||
EthernetHeader::EthernetHeader(u16 ether_type) : ethertype(htons(ether_type))
|
EthernetHeader::EthernetHeader(u16 ether_type) : ethertype(htons(ether_type))
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,12 @@ enum DHCPConst
|
||||||
};
|
};
|
||||||
|
|
||||||
using MACAddress = std::array<u8, MAC_ADDRESS_SIZE>;
|
using MACAddress = std::array<u8, MAC_ADDRESS_SIZE>;
|
||||||
|
|
||||||
|
// Note: Bluetooth address display order is reverse of the storage order.
|
||||||
|
struct BluetoothAddress : std::array<u8, MAC_ADDRESS_SIZE>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
constexpr std::size_t IPV4_ADDR_LEN = 4;
|
constexpr std::size_t IPV4_ADDR_LEN = 4;
|
||||||
using IPAddress = std::array<u8, IPV4_ADDR_LEN>;
|
using IPAddress = std::array<u8, IPV4_ADDR_LEN>;
|
||||||
constexpr IPAddress IP_ADDR_ANY = {0, 0, 0, 0};
|
constexpr IPAddress IP_ADDR_ANY = {0, 0, 0, 0};
|
||||||
|
|
@ -259,8 +265,13 @@ struct NetworkErrorState
|
||||||
};
|
};
|
||||||
|
|
||||||
MACAddress GenerateMacAddress(MACConsumer type);
|
MACAddress GenerateMacAddress(MACConsumer type);
|
||||||
|
|
||||||
std::string MacAddressToString(const MACAddress& mac);
|
std::string MacAddressToString(const MACAddress& mac);
|
||||||
std::optional<MACAddress> StringToMacAddress(std::string_view mac_string);
|
std::optional<MACAddress> StringToMacAddress(std::string_view mac_string);
|
||||||
|
|
||||||
|
std::string BluetoothAddressToString(BluetoothAddress bdaddr);
|
||||||
|
std::optional<BluetoothAddress> StringToBluetoothAddress(std::string_view str);
|
||||||
|
|
||||||
u16 ComputeNetworkChecksum(const void* data, u16 length, u32 initial_value = 0);
|
u16 ComputeNetworkChecksum(const void* data, u16 length, u32 initial_value = 0);
|
||||||
u16 ComputeTCPNetworkChecksum(const IPAddress& from, const IPAddress& to, const void* data,
|
u16 ComputeTCPNetworkChecksum(const IPAddress& from, const IPAddress& to, const void* data,
|
||||||
u16 length, u8 protocol);
|
u16 length, u8 protocol);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue