diff --git a/Source/Core/Common/Network.cpp b/Source/Core/Common/Network.cpp index 59d0c9026e..5bc6469912 100644 --- a/Source/Core/Common/Network.cpp +++ b/Source/Core/Common/Network.cpp @@ -85,9 +85,13 @@ std::optional StringToMacAddress(std::string_view mac_string) EthernetHeader::EthernetHeader() = default; -EthernetHeader::EthernetHeader(u16 ether_type) +EthernetHeader::EthernetHeader(u16 ether_type) : ethertype(htons(ether_type)) +{ +} + +EthernetHeader::EthernetHeader(const MACAddress& dest, const MACAddress& src, u16 ether_type) + : destination(dest), source(src), ethertype(htons(ether_type)) { - ethertype = htons(ether_type); } u16 EthernetHeader::Size() const @@ -339,13 +343,10 @@ TCPPacket::TCPPacket() = default; TCPPacket::TCPPacket(const MACAddress& destination, const MACAddress& source, const sockaddr_in& from, const sockaddr_in& to, u32 seq, u32 ack, u16 flags) + : eth_header(destination, source, IPV4_ETHERTYPE), + ip_header(Common::TCPHeader::SIZE, IPPROTO_TCP, from, to), + tcp_header(from, to, seq, ack, flags) { - eth_header.destination = destination; - eth_header.source = source; - eth_header.ethertype = htons(IPV4_ETHERTYPE); - - ip_header = Common::IPv4Header(Common::TCPHeader::SIZE, IPPROTO_TCP, from, to); - tcp_header = Common::TCPHeader(from, to, seq, ack, flags); } std::vector TCPPacket::Build() @@ -401,15 +402,10 @@ UDPPacket::UDPPacket() = default; UDPPacket::UDPPacket(const MACAddress& destination, const MACAddress& source, const sockaddr_in& from, const sockaddr_in& to, const std::vector& payload) + : eth_header(destination, source, IPV4_ETHERTYPE), + ip_header(static_cast(payload.size() + Common::UDPHeader::SIZE), IPPROTO_UDP, from, to), + udp_header(from, to, static_cast(payload.size())), data(payload) { - eth_header.destination = destination; - eth_header.source = source; - eth_header.ethertype = htons(IPV4_ETHERTYPE); - - ip_header = Common::IPv4Header(static_cast(payload.size() + Common::UDPHeader::SIZE), - IPPROTO_UDP, from, to); - udp_header = Common::UDPHeader(from, to, static_cast(payload.size())); - data = payload; } std::vector UDPPacket::Build() diff --git a/Source/Core/Common/Network.h b/Source/Core/Common/Network.h index 57479a1f11..718a297f09 100644 --- a/Source/Core/Common/Network.h +++ b/Source/Core/Common/Network.h @@ -47,6 +47,7 @@ struct EthernetHeader { EthernetHeader(); explicit EthernetHeader(u16 ether_type); + EthernetHeader(const MACAddress& dest, const MACAddress& src, u16 ether_type); u16 Size() const; static constexpr std::size_t SIZE = 14;