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 #ifndef WEARABLE_DISTRIBUTED_NET_LINK_INFO_H 17 #define WEARABLE_DISTRIBUTED_NET_LINK_INFO_H 18 19 #include <fstream> 20 #include "cJSON.h" 21 #include "inet_addr.h" 22 #include "net_link_info.h" 23 #include "net_manager_constants.h" 24 #include "route.h" 25 #include "wearable_distributed_net_config_constants.h" 26 27 namespace OHOS { 28 namespace NetManagerStandard { 29 class WearableDistributedNetLinkInfo { 30 public: 31 bool ReadSystemNetlinkinfoConfiguration(); 32 void SetInterFaceName(NetLinkInfo &linkInfo); 33 int32_t SetNetLinkIPInfo(NetLinkInfo &linkInfo); 34 int32_t SetNetLinkRouteInfo(NetLinkInfo &linkInfo); 35 int32_t SetDnsLists(NetLinkInfo &linkInfo); 36 void SetMtu(NetLinkInfo &linkInfo); 37 int32_t SetInterfaceDummyUp(); 38 39 private: 40 std::string GetPrimaryDnsLists(); 41 std::string GetSecondDnsLists(); 42 std::string GetIfaceName(); 43 std::string GetDefaultNetMask(); 44 std::string GetNetIfaceAddress(); 45 std::string GetIpv4DeRouteAddr(); 46 std::string GetDummyAddress(); 47 std::string GetIpv4AddrNetMask(); 48 std::string GetRouteEstinationAddr(); 49 50 bool ParseDnsLists(const cJSON &json); 51 bool ParseIfaceName(const cJSON &json); 52 bool ParseDefaultNetMask(const cJSON &json); 53 bool ParseNetIfaceAddress(const cJSON &json); 54 bool ParseIpv4DeRouteAddr(const cJSON &json); 55 bool ParseDummyAddress(const cJSON &json); 56 bool ParseIpv4AddrNetMask(const cJSON &json); 57 bool ParseRouteDestinationAddr(const cJSON &json); 58 59 bool ReadNetlinkinfoInterfaces(const cJSON &json); 60 std::string ReadJsonFile(); 61 62 private: 63 std::string primaryDnsLists_; 64 std::string secondDnsLists_; 65 std::string ifaceName_; 66 std::string defaultNetMask_; 67 std::string netIfaceAddress_; 68 std::string ipv4DeRouteAddr_; 69 std::string dummyAddress_; 70 std::string ipv4AddrNetMask_; 71 std::string routeDestinationAddr_; 72 std::string configPath_ = WEARABLE_DISTRIBUTED_NET_CONFIG_PATH; 73 }; 74 75 int32_t CreateNetLinkInfo(NetLinkInfo &linkInfo); 76 int32_t SetInterfaceDummyDown(); 77 } // namespace NetManagerStandard 78 } // namespace OHOS 79 #endif // WEARABLE_DISTRIBUTED_NET_LINK_INFO_H 80