Fix styling
This commit is contained in:
parent
aec510a47c
commit
4059e4be88
9 changed files with 267 additions and 251 deletions
|
@ -5,7 +5,8 @@
|
|||
|
||||
namespace Net::Arp
|
||||
{
|
||||
enum Operation {
|
||||
enum Operation
|
||||
{
|
||||
ARP_OPERATION_REQUEST = 1,
|
||||
ARP_OPERATION_REPLY = 2,
|
||||
};
|
||||
|
|
|
@ -36,7 +36,8 @@ namespace Net::Dhcp
|
|||
|
||||
size_t Header::Serialize(uint8_t* buffer, const size_t size) const
|
||||
{
|
||||
if (size < Header::SerializedLength()) {
|
||||
if (size < Header::SerializedLength())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -84,7 +85,8 @@ namespace Net::Dhcp
|
|||
size_t Header::Deserialize(
|
||||
Header& out, const uint8_t* buffer, const size_t size
|
||||
) {
|
||||
if (size < SerializedLength()) {
|
||||
if (size < SerializedLength())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -158,7 +160,8 @@ namespace Net::Dhcp
|
|||
size += udpHeader.Serialize(buffer + size);
|
||||
size += dhcpHeader.Serialize(buffer + size, USPI_FRAME_BUFFER_SIZE - size);
|
||||
|
||||
if (size != expectedSize) {
|
||||
if (size != expectedSize)
|
||||
{
|
||||
// TODO Log
|
||||
return;
|
||||
}
|
||||
|
@ -212,7 +215,8 @@ namespace Net::Dhcp
|
|||
size += udpHeader.Serialize(buffer + size);
|
||||
size += dhcpHeader.Serialize(buffer + size, USPI_FRAME_BUFFER_SIZE - size);
|
||||
|
||||
if (size != expectedSize) {
|
||||
if (size != expectedSize)
|
||||
{
|
||||
// TODO Log
|
||||
return;
|
||||
}
|
||||
|
@ -254,7 +258,8 @@ namespace Net::Dhcp
|
|||
) {
|
||||
auto dhcpHeader = Header();
|
||||
const auto dhcpSize = Header::Deserialize(dhcpHeader, buffer, size);
|
||||
if (dhcpSize == 0) {
|
||||
if (dhcpSize == 0)
|
||||
{
|
||||
// TODO log
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include <cstring>
|
||||
#include "net-ethernet.h"
|
||||
|
||||
namespace Net::Ethernet {
|
||||
namespace Net::Ethernet
|
||||
{
|
||||
Header::Header()
|
||||
{}
|
||||
|
||||
|
|
|
@ -296,7 +296,8 @@ namespace Net::Tftp
|
|||
size_t DataPacket::Deserialize(
|
||||
DataPacket& out, const uint8_t* buffer, size_t size
|
||||
) {
|
||||
if (size < sizeof(opcode) + sizeof(blockNumber)) {
|
||||
if (size < sizeof(opcode) + sizeof(blockNumber))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
#include <vector>
|
||||
#include "net-udp.h"
|
||||
|
||||
namespace Net::Tftp {
|
||||
namespace Net::Tftp
|
||||
{
|
||||
const size_t TFTP_BLOCK_SIZE = 512;
|
||||
|
||||
enum class Opcode : uint16_t
|
||||
|
@ -20,9 +21,11 @@ namespace Net::Tftp {
|
|||
{
|
||||
Opcode opcode;
|
||||
|
||||
Packet(Opcode opcode) : opcode(opcode) {}
|
||||
Packet(Opcode opcode) : opcode(opcode)
|
||||
{}
|
||||
|
||||
virtual size_t SerializedLength() const {
|
||||
virtual size_t SerializedLength() const
|
||||
{
|
||||
return sizeof(opcode);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ namespace Net::Utils
|
|||
const MacAddress MacBroadcast{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
uint32_t Ipv4Address = 0xC0A80164;
|
||||
|
||||
static const uint32_t crcTab32[256] = {
|
||||
static const uint32_t crcTab32[256] =
|
||||
{
|
||||
0x00000000ul, 0x77073096ul, 0xEE0E612Cul, 0x990951BAul,
|
||||
0x076DC419ul, 0x706AF48Ful, 0xE963A535ul, 0x9E6495A3ul,
|
||||
0x0EDB8832ul, 0x79DCB8A4ul, 0xE0D5E91Eul, 0x97D2D988ul,
|
||||
|
@ -75,7 +76,8 @@ namespace Net::Utils
|
|||
0xB40BBE37ul, 0xC30C8EA1ul, 0x5A05DF1Bul, 0x2D02EF8Dul
|
||||
};
|
||||
|
||||
uint32_t Crc32(const uint8_t *buffer, size_t size) {
|
||||
uint32_t Crc32(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
uint32_t crc = 0xFFFFFFFFul;
|
||||
|
||||
for (size_t a = 0; a < size; a++)
|
||||
|
@ -90,18 +92,21 @@ namespace Net::Utils
|
|||
uint16_t InternetChecksum(const void* data, size_t size)
|
||||
{
|
||||
uint32_t sum = 0;
|
||||
while (size > 1) {
|
||||
while (size > 1)
|
||||
{
|
||||
sum += *(uint16_t*)data;
|
||||
data = (uint16_t*)data + 1;
|
||||
|
||||
size -= 2;
|
||||
}
|
||||
|
||||
if (size > 0) {
|
||||
if (size > 0)
|
||||
{
|
||||
sum += *(uint16_t*)data;
|
||||
}
|
||||
|
||||
while (sum >> 16) {
|
||||
while (sum >> 16)
|
||||
{
|
||||
sum = (sum & 0xFFFF) + (sum >> 16);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue