Split ethernet support to new file ethernet.hh

This commit is contained in:
Avi Kivity
2014-08-31 13:37:21 +03:00
parent 93804c2b25
commit ee8558283d
3 changed files with 28 additions and 12 deletions

27
ethernet.hh Normal file
View File

@@ -0,0 +1,27 @@
/*
* Copyright (C) 2014 Cloudius Systems, Ltd.
*/
#ifndef ETHERNET_HH_
#define ETHERNET_HH_
#include <array>
#include "byteorder.hh"
namespace net {
using ethernet_address = std::array<uint8_t, 6>;
struct eth_hdr {
ethernet_address dst_mac;
ethernet_address src_mac;
packed<uint16_t> eth_proto;
template <typename Adjuster>
auto adjust_endianness(Adjuster a) {
return a(eth_proto);
}
} __attribute__((packed));
}
#endif /* ETHERNET_HH_ */

12
ip.hh
View File

@@ -13,20 +13,8 @@
namespace net {
using ethernet_address = std::array<uint8_t, 6>;
uint16_t ip_checksum(void* data, size_t len);
struct eth_hdr {
ethernet_address dst_mac;
ethernet_address src_mac;
packed<uint16_t> eth_proto;
template <typename Adjuster>
auto adjust_endianness(Adjuster a) {
return a(eth_proto);
}
} __attribute__((packed));
struct ip_hdr {
uint8_t ihl : 4;
uint8_t ver : 4;

1
net.hh
View File

@@ -7,6 +7,7 @@
#include "reactor.hh"
#include "ip.hh"
#include "ethernet.hh"
#include <unordered_map>
namespace net {