2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 * Copyright (C) 2014 Cloudius Systems, Ltd.
27 #include <seastar/net/byteorder.hh>
33 struct ethernet_address {
34 ethernet_address() noexcept
37 ethernet_address(const uint8_t *eaddr) noexcept {
38 std::copy(eaddr, eaddr + 6, mac.begin());
41 ethernet_address(std::initializer_list<uint8_t> eaddr) noexcept {
42 assert(eaddr.size() == mac.size());
43 std::copy(eaddr.begin(), eaddr.end(), mac.begin());
46 std::array<uint8_t, 6> mac;
48 template <typename Adjuster>
49 void adjust_endianness(Adjuster a) noexcept {}
51 static ethernet_address read(const char* p) noexcept {
53 std::copy_n(p, size(), reinterpret_cast<char*>(ea.mac.data()));\
56 static ethernet_address consume(const char*& p) noexcept {
61 void write(char* p) const noexcept {
62 std::copy_n(reinterpret_cast<const char*>(mac.data()), size(), p);
64 void produce(char*& p) const noexcept {
68 static constexpr size_t size() noexcept {
71 } __attribute__((packed));
73 std::ostream& operator<<(std::ostream& os, ethernet_address ea);
76 using address = ethernet_address;
77 static address broadcast_address() {
78 return {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
80 static constexpr uint16_t arp_hardware_type() { return 1; }
84 ethernet_address dst_mac;
85 ethernet_address src_mac;
86 packed<uint16_t> eth_proto;
87 template <typename Adjuster>
88 auto adjust_endianness(Adjuster a) {
91 } __attribute__((packed));
93 ethernet_address parse_ethernet_address(std::string addr);