2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <vom/api_types.hpp>
20 static vapi_type_ip4_address
21 to_api(const boost::asio::ip::address_v4& a)
23 vapi_type_ip4_address v;
25 std::copy_n(a.to_bytes().data(), 4, v.address);
30 static vapi_type_ip6_address
31 to_api(const boost::asio::ip::address_v6& a)
33 vapi_type_ip6_address v;
35 std::copy_n(a.to_bytes().data(), 16, v.address);
41 to_api(const ip_address_t& a)
44 vapi_type_address v = {
48 .ip4 = to_api(a.to_v4()),
53 vapi_type_address v = {
57 .ip6 = to_api(a.to_v6()),
65 from_api(const vapi_type_address& v)
67 boost::asio::ip::address addr;
69 if (ADDRESS_IP6 == v.af) {
70 std::array<uint8_t, 16> a;
71 std::copy(v.un.ip6.address, v.un.ip6.address + 16, std::begin(a));
72 boost::asio::ip::address_v6 v6(a);
75 std::array<uint8_t, 4> a;
76 std::copy(v.un.ip6.address, v.un.ip6.address + 4, std::begin(a));
77 boost::asio::ip::address_v4 v4(a);
85 to_api(const mac_address_t& a)
87 vapi_type_mac_address v;
89 std::copy(std::begin(a.bytes), std::end(a.bytes), v.bytes);
95 from_api(const vapi_type_mac_address& v)
97 return mac_address_t(v.bytes);
101 from_api(const vapi_type_prefix& v)
103 return route::prefix_t(from_api(v.address), v.address_length);
107 to_api(const route::prefix_t& p)
109 vapi_type_prefix v = {
110 .address = to_api(p.address()), .address_length = p.mask_width(),
118 * fd.io coding-style-patch-verification: ON
121 * eval: (c-set-style "mozilla")