1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
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
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #include "netmgr_ext_log_wrapper.h"
17 #include "router_advertisement_params.h"
18 
19 namespace OHOS {
20 namespace NetManagerStandard {
RaParams()21 RaParams::RaParams() : hasDefaultRoute_(false), hopLimit_(DEFAULT_HOPLIMIT), mtu_(IPV6_MIN_MTU) {}
22 
Set(const RaParams & raParam)23 void RaParams::Set(const RaParams &raParam)
24 {
25     hasDefaultRoute_ = raParam.hasDefaultRoute_;
26     hopLimit_ = raParam.hopLimit_;
27     mtu_ = raParam.mtu_;
28     prefixes_ = raParam.prefixes_;
29     dnses_ = raParam.dnses_;
30     macAddr_ = raParam.macAddr_;
31 }
32 
ContainsPrefix(const IpPrefix & prefix)33 bool RaParams::ContainsPrefix(const IpPrefix &prefix)
34 {
35     for (auto &ip : prefixes_) {
36         if ((std::memcmp(ip.prefix.s6_addr, prefix.prefix.s6_addr, sizeof(in6_addr)) == 0) &&
37             ip.prefixesLength == prefix.prefixesLength) {
38             return true;
39         }
40     }
41     return false;
42 }
43 
ContainsDns(const in6_addr & dns)44 bool RaParams::ContainsDns(const in6_addr &dns)
45 {
46     for (auto &d : dnses_) {
47         if (std::memcmp(d.s6_addr, dns.s6_addr, sizeof(in6_addr)) == 0) {
48             return true;
49         }
50     }
51     return false;
52 }
53 
Clear()54 void RaParams::Clear()
55 {
56     prefixes_.clear();
57     dnses_.clear();
58 }
59 
60 } // namespace NetManagerStandard
61 } // namespace OHOS