nwm/uds_data: specify endianness for enum

This commit is contained in:
Weiyi Wang 2018-09-21 21:05:47 -04:00
parent e0336403ee
commit 41d53cee1f
2 changed files with 6 additions and 8 deletions

View File

@ -26,7 +26,7 @@ using MacAddress = std::array<u8, 6>;
*/
static std::vector<u8> GenerateLLCHeader(EtherType protocol) {
LLCHeader header{};
header.protocol = static_cast<u16>(protocol);
header.protocol = protocol;
std::vector<u8> buffer(sizeof(header));
memcpy(buffer.data(), &header, sizeof(header));
@ -313,9 +313,7 @@ std::vector<u8> GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node
EtherType GetFrameEtherType(const std::vector<u8>& frame) {
LLCHeader header;
std::memcpy(&header, frame.data(), sizeof(header));
u16 ethertype = header.protocol;
return static_cast<EtherType>(ethertype);
return header.protocol;
}
u16 GetEAPoLFrameType(const std::vector<u8>& frame) {

View File

@ -26,11 +26,11 @@ enum class EtherType : u16 { SecureData = 0x876D, EAPoL = 0x888E };
* and the OUI is always 0.
*/
struct LLCHeader {
u8 dsap = static_cast<u8>(SAP::SNAPExtensionUsed);
u8 ssap = static_cast<u8>(SAP::SNAPExtensionUsed);
u8 control = static_cast<u8>(PDUControl::UnnumberedInformation);
SAP dsap = SAP::SNAPExtensionUsed;
SAP ssap = SAP::SNAPExtensionUsed;
PDUControl control = PDUControl::UnnumberedInformation;
std::array<u8, 3> OUI = {};
u16_be protocol;
enum_be<EtherType> protocol;
};
static_assert(sizeof(LLCHeader) == 8, "LLCHeader has the wrong size");