]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | /* |
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. | |
6 | * | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
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 | |
16 | * under the License. | |
17 | */ | |
18 | /* | |
19 | * Copyright (C) 2014 Cloudius Systems, Ltd. | |
20 | */ | |
21 | ||
9f95a23c | 22 | #include <seastar/core/print.hh> |
11fdf7f2 TL |
23 | #include <seastar/net/ethernet.hh> |
24 | #include <boost/algorithm/string.hpp> | |
25 | #include <string> | |
26 | ||
27 | namespace seastar { | |
28 | ||
29 | namespace net { | |
30 | ||
31 | std::ostream& operator<<(std::ostream& os, ethernet_address ea) { | |
32 | auto& m = ea.mac; | |
33 | using u = uint32_t; | |
20effc67 | 34 | fmt::print(os, "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", |
11fdf7f2 | 35 | u(m[0]), u(m[1]), u(m[2]), u(m[3]), u(m[4]), u(m[5])); |
20effc67 | 36 | return os; |
11fdf7f2 TL |
37 | } |
38 | ||
39 | ethernet_address parse_ethernet_address(std::string addr) | |
40 | { | |
41 | std::vector<std::string> v; | |
42 | boost::split(v, addr , boost::algorithm::is_any_of(":")); | |
43 | ||
44 | if (v.size() != 6) { | |
45 | throw std::runtime_error("invalid mac address\n"); | |
46 | } | |
47 | ||
48 | ethernet_address a; | |
49 | unsigned i = 0; | |
50 | for (auto &x: v) { | |
51 | a.mac[i++] = std::stoi(x, nullptr,16); | |
52 | } | |
53 | return a; | |
54 | } | |
55 | } | |
56 | ||
57 | } | |
58 |