• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     int32_t SetInterfaceDummyDown();
39 
40 private:
41     std::string GetPrimaryDnsLists();
42     std::string GetSecondDnsLists();
43     std::string GetIfaceName();
44     std::string GetDefaultNetMask();
45     std::string GetNetIfaceAddress();
46     std::string GetIpv4DeRouteAddr();
47     std::string GetDummyAddress();
48     std::string GetIpv4AddrNetMask();
49     std::string GetRouteEstinationAddr();
50 
51     bool ParseDnsLists(const cJSON &json);
52     bool ParseIfaceName(const cJSON &json);
53     bool ParseDefaultNetMask(const cJSON &json);
54     bool ParseNetIfaceAddress(const cJSON &json);
55     bool ParseIpv4DeRouteAddr(const cJSON &json);
56     bool ParseDummyAddress(const cJSON &json);
57     bool ParseIpv4AddrNetMask(const cJSON &json);
58     bool ParseRouteDestinationAddr(const cJSON &json);
59 
60     bool ReadNetlinkinfoInterfaces(const cJSON &json);
61     std::string ReadJsonFile();
62 
63 private:
64     std::string primaryDnsLists_;
65     std::string secondDnsLists_;
66     std::string ifaceName_;
67     std::string defaultNetMask_;
68     std::string netIfaceAddress_;
69     std::string ipv4DeRouteAddr_;
70     std::string dummyAddress_;
71     std::string ipv4AddrNetMask_;
72     std::string routeDestinationAddr_;
73     std::string configPath_ = WEARABLE_DISTRIBUTED_NET_CONFIG_PATH;
74 };
75 
76 int32_t CreateNetLinkInfo(NetLinkInfo &linkInfo);
77 int32_t SetInterfaceDummyDown();
78 int32_t SetInterfaceDummyUp();
79 } // namespace NetManagerStandard
80 } // namespace OHOS
81 #endif // WEARABLE_DISTRIBUTED_NET_LINK_INFO_H
82