1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
3 * This file is open source software, licensed to you under the terms
4 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
5 * distributed with this work for additional information regarding copyright
6 * ownership. You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 * Copyright (C) 2014 Cloudius Systems, Ltd.
23 #ifndef CEPH_MSG_ETHERNET_H_
24 #define CEPH_MSG_ETHERNET_H_
29 #include "include/assert.h"
30 #include "byteorder.h"
32 struct ethernet_address {
35 ethernet_address(const uint8_t *eaddr) {
36 std::copy(eaddr, eaddr + 6, mac.begin());
39 ethernet_address(std::initializer_list<uint8_t> eaddr) {
40 assert(eaddr.size() == mac.size());
41 std::copy(eaddr.begin(), eaddr.end(), mac.begin());
44 ethernet_address ntoh() {
47 ethernet_address hton() {
50 std::array<uint8_t, 6> mac;
51 } __attribute__((packed));
53 inline bool operator==(const ethernet_address& a, const ethernet_address& b) {
54 return a.mac == b.mac;
56 std::ostream& operator<<(std::ostream& os, const ethernet_address& ea);
59 using address = ethernet_address;
60 static address broadcast_address() {
61 return {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
63 static constexpr uint16_t arp_hardware_type() { return 1; }
67 ethernet_address dst_mac;
68 ethernet_address src_mac;
72 hdr.eth_proto = ::hton(eth_proto);
77 hdr.eth_proto = ::ntoh(eth_proto);
80 } __attribute__((packed));
82 ethernet_address parse_ethernet_address(std::string addr);
84 #endif /* CEPH_MSG_ETHERNET_H_ */