1 /*
2 * Copyright (C) 2021-2022 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 "base_address.h"
17 #include <string>
18 #include "wifi_log.h"
19
20 #undef LOG_TAG
21 #define LOG_TAG "OHWIFI_UTIL_BaseAddress"
22
23 #define BUFFER_SIZE 64
24
25 namespace OHOS {
26 namespace Wifi {
BaseAddress(const std::string & ip,size_t prefixLength,FamilyType family)27 BaseAddress::BaseAddress(const std::string &ip, size_t prefixLength, FamilyType family)
28 : family_(family), prefixLength_(prefixLength), ipAddress_(ip)
29 {}
30
operator ==(const BaseAddress & address) const31 bool BaseAddress::operator==(const BaseAddress &address) const
32 {
33 return (family_ == address.family_) && (ipAddress_ == address.ipAddress_);
34 }
35
~BaseAddress()36 BaseAddress::~BaseAddress()
37 {}
38
Dump() const39 void BaseAddress::Dump() const
40 {
41 std::string ipType;
42 switch (family_) {
43 case FamilyType::FAMILY_INET: {
44 ipType = "IPv4";
45 break;
46 }
47 case FamilyType::FAMILY_INET6: {
48 ipType = "IPv6";
49 break;
50 }
51 default:
52 ipType = "NONE";
53 break;
54 }
55 LOGI("TYPE: [%{public}s] address [%s/%zu]", ipType.c_str(), ipAddress_.c_str(), prefixLength_);
56 }
57 } // namespace Wifi
58 } // namespace OHOS
59