• Home
Name Date Size #Lines LOC

..--

figures/12-May-2024-

frameworks/12-May-2024-1,092911

interfaces/12-May-2024-550303

sa_profile/12-May-2024-7942

services/ethernetmanager/12-May-2024-2,1861,767

test/ethernetmanager/12-May-2024-226158

utils/12-May-2024-184122

LICENSED12-May-20249.9 KiB177150

OAT.xmlD12-May-20244.2 KiB6715

README.mdD12-May-2024977 3725

README_zh.mdD12-May-202413 KiB334235

bundle.jsonD12-May-20241.9 KiB6160

netmanager_ext_config.gniD12-May-20242.3 KiB4742

README.md

1# communication_netmanager_standard
2
3#### Description
4{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
5
6#### Software Architecture
7Software architecture description
8
9#### Installation
10
111.  xxxx
122.  xxxx
133.  xxxx
14
15#### Instructions
16
171.  xxxx
182.  xxxx
193.  xxxx
20
21#### Contribution
22
231.  Fork the repository
242.  Create Feat_xxx branch
253.  Commit your code
264.  Create Pull Request
27
28
29#### Gitee Feature
30
311.  You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
322.  Gitee blog [blog.gitee.com](https://blog.gitee.com)
333.  Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
344.  The most valuable open source project [GVP](https://gitee.com/gvp)
355.  The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
366.  The most popular members  [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
37

README_zh.md

1# Net Manager<a name="EN-US_TOPIC_0000001105058232"></a>
2
3-    [简介](#简介)
4-    [目录](#目录)
5-    [约束](#约束)
6-    [接口说明](#接口说明)
7-    [使用说明](#使用说明)
8-    [相关仓](#相关仓)
9
10
11
12## 简介
13
14网络管理介绍:
15
16​    网络管理主要分为连接管理、策略管理、流量管理、网络共享、VPN管理以及以太网连接等模块,其中连接管理、策略管理、流量管理为基础服务,归档在netmanager_base仓,以太网连接、网络共享、VPN管理三个模块为可裁剪扩展模块,归档在netmanager_ext仓,netmanager_ext编译构建依赖netmanager_base库内容。如图1:网络管理架构图;
17
18**图 1**  网络管理架构图
19
20![net_conn_manager_arch_zh](figures/net_conn_manager_arch_zh.png)
21
22## 目录
23
24```
25foundation/communication/netmanager_ext/
26├─figures                            #README用于的png图片
27├─frameworks                         #
28│  ├─js                              #js接口实现
29│  │  └─napi
30│  │      └─ethernet                 #以太网
31│  │          ├─include
32│  │          └─src
33│  └─native                          #C++接口实现
34│      └─ethernetclient              #以太网
35│         └─src                      #
36│             └─proxy                #
37
38├─interfaces                         #C++接口头文件
39│  ├─innerkits
40│  │  ├─ethernetclient               #以太网
41│  │  │  └─include
42│  │  │      └─proxy                 #SA IPC头文件
43│  │  └─include
44│  └─kits
45│      └─js
46├─sa_profile                         #SA服务配置文件
47├─services                           #C++内部实现
48│  └─ethernetmanager                 #以太网模块
49│      ├─include
50│      │  └─stub
51│      └─src
52│          └─stub
53├─test                               #单元测试代码
54│  └─ethernetmanager                 #以太网模块
55│      └─unittest
56│          └─ethernet_manager_test
57└─utils                              #公共功能
58    └─log                            #日志实现
59        ├─include
60        └─src
61```
62
63## 约束
64
65-    开发语言:C++
66-    软件层,需要以下子系统和服务配合使用:蜂窝数据、WiFi系统、安全子系统、软总线子系统、USB子系统、电源管理子系统等;
67-    硬件层,需要搭载的设备支持以下硬件:可以进行独立蜂窝通信的Modem以及SIM卡;
68
69## 接口使用说明
70
71## ethernet.setIfaceConfig<a name=ethernet.setIfaceConfig-callback></a>
72
73setIfaceConfig\(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback<void\>\): void
74
75设置网络接口配置信息,使用callback方式作为异步方法。
76
77需要ohos.permission.GET\_NETWORK\_INFO权限,该权限为系统权限。
78
79- 参数
80
81  | 参数名   | 类型                                              | 必填 | 说明                                       |
82  | -------- | ------------------------------------------------- | ---- | ------------------------------------------ |
83  | iface    | string                                            | 是   | 接口名                                     |
84  | ic       | [InterfaceConfiguration](#InterfaceConfiguration) | 是   | 要设置的网络接口配置信息                   |
85  | callback | AsyncCallback&lt;void&gt;                         | 是   | 回调函数。成功无返回,失败返回对应错误码。 |
86
87
88- 示例
89
90  ```js
91  ethernet.setIfaceConfig("eth0", {mode:ethernet.STATIC,ipAddr:"192.168.1.123", routeAddr:"192.168.1.1",
92      gateAddr:"192.168.1.1", maskAddr:"255.255.255.0", dnsAddr0:"1.1.1.1", dnsAddr1:"2.2.2.2"},
93      (error) => {
94          if (error) {
95              console.log("setIfaceConfig callback error = " + error);
96          } else {
97              console.log("setIfaceConfig callback ok ");
98          }
99      });
100  ```
101
102
103## ethernet.setIfaceConfig<a name=ethernet.setIfaceConfig-promise></a>
104
105setIfaceConfig\(iface: string, ic: InterfaceConfiguration\): Promise<void\>
106
107设置网络接口配置信息,使用Promise方式作为异步方法。
108
109需要ohos.permission.GET\_NETWORK\_INFO权限,该权限为系统权限。
110
111- 参数
112
113  | 参数名 | 类型                                              | 必填 | 说明                     |
114  | ------ | ------------------------------------------------- | ---- | ------------------------ |
115  | iface  | string                                            | 是   | 接口名                   |
116  | ic     | [InterfaceConfiguration](#InterfaceConfiguration) | 是   | 要设置的网络接口配置信息 |
117
118- 返回值
119
120  | 类型                | 说明                                                        |
121  | ------------------- | ----------------------------------------------------------- |
122  | Promise&lt;void&gt; | 以Promise形式返回执行结果。成功无返回,失败返回对应错误码。 |
123
124- 示例
125
126  ```js
127  ethernet.setIfaceConfig("eth0", {mode:ethernet.STATIC,ipAddr:"192.168.1.123", routeAddr:"192.168.1.1",
128      gateAddr:"192.168.1.1", maskAddr:"255.255.255.0", dnsAddr0:"1.1.1.1", dnsAddr1:"2.2.2.2"}).then(() => {
129      console.log("setIfaceConfig promiss ok ");
130  }).catch((error) => {
131      console.log("setIfaceConfig promiss error = " + error);
132  });
133  ```
134
135## ethernet.getIfaceConfig<a name=ethernet.getIfaceConfig-callback></a>
136
137getIfaceConfig\(iface: string, callback: AsyncCallback<InterfaceConfiguration\>\): void
138
139获取网络接口配置信息,使用callback方式作为异步方法。
140
141需要ohos.permission.GET\_NETWORK\_INFO权限,该权限为系统权限。
142
143- 参数
144
145  | 参数名   | 类型                                                         | 必填 | 说明                                                         |
146  | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
147  | iface    | string                                                       | 是   | 接口名                                                       |
148  | callback | AsyncCallback&lt;[InterfaceConfiguration](#InterfaceConfiguration)&gt; | 是   | 回调函数。成功返回[InterfaceConfiguration](#InterfaceConfiguration),失败返回对应错误码。 |
149
150
151- 示例
152
153  ```js
154  ethernet.getIfaceConfig("eth0", (error, value) => {
155      if (error) {
156          console.log("getIfaceConfig  callback error = " + error);
157      } else {
158          console.log("getIfaceConfig callback mode = " + value.mode);
159          console.log("getIfaceConfig callback ipAddr = " + value.ipAddr);
160          console.log("getIfaceConfig callback routeAddr = " + value.routeAddr);
161          console.log("getIfaceConfig callback gateAddr = " + value.gateAddr);
162          console.log("getIfaceConfig callback maskAddr = " + value.maskAddr);
163          console.log("getIfaceConfig callback dns0Addr = " + value.dns0Addr);
164          console.log("getIfaceConfig callback dns1Addr = " + value.dns1Addr);
165      }
166  });
167  ```
168
169
170## ethernet.getIfaceConfig<a name=ethernet.getIfaceConfig-promise></a>
171
172getIfaceConfig\(iface: string\): Promise<InterfaceConfiguration\>
173
174获取网络接口配置信息,使用Promise方式作为异步方法。
175
176需要ohos.permission.GET\_NETWORK\_INFO权限,该权限为系统权限。
177
178- 参数
179
180  | 参数名 | 类型   | 必填 | 说明   |
181  | ------ | ------ | ---- | ------ |
182  | iface  | string | 是   | 接口名 |
183
184- 返回值
185
186  | 类型                                                         | 说明                                                         |
187  | ------------------------------------------------------------ | ------------------------------------------------------------ |
188  | Promise&lt;[InterfaceConfiguration](#InterfaceConfiguration)&gt; | 以Promise形式返回执行结果。成功返回[InterfaceConfiguration](#InterfaceConfiguration),失败返回对应错误码。 |
189
190- 示例
191
192  ```js
193  ethernet.getIfaceConfig("eth0").then((data) => {
194      console.log("getIfaceConfig promiss mode = " + data.mode);
195      console.log("getIfaceConfig promiss ipAddr = " + data.ipAddr);
196      console.log("getIfaceConfig promiss routeAddr = " + data.routeAddr);
197      console.log("getIfaceConfig promiss gateAddr = " + data.gateAddr);
198      console.log("getIfaceConfig promiss maskAddr = " + data.maskAddr);
199      console.log("getIfaceConfig promiss dns0Addr = " + data.dns0Addr);
200      console.log("getIfaceConfig promiss dns1Addr = " + data.dns1Addr);
201  }).catch((error) => {
202      console.log("getIfaceConfig promiss error = " + error);
203  });
204  ```
205
206## ethernet.isIfaceActive<a name=ethernet.isIfaceActive-callback></a>
207
208isIfaceActive\(iface: string, callback: AsyncCallback<number\>\): void
209
210判断接口是否已激活,使用callback方式作为异步方法。
211
212需要ohos.permission.GET\_NETWORK\_INFO权限,该权限为系统权限。
213
214- 参数
215
216  | 参数名   | 类型                        | 必填 | 说明                                               |
217  | -------- | --------------------------- | ---- | -------------------------------------------------- |
218  | iface    | string                      | 是   | 接口名                                             |
219  | callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。已激活:1,未激活:0,其他为获取失败错误码。 |
220
221
222- 示例
223
224  ```js
225  ethernet.isIfaceActive("eth0", (error, value) => {
226  	if (error) {
227  		console.log("whether2Activate callback error = " + error);
228  	} else {
229  		console.log("whether2Activate callback = " + value);
230  	}
231  });
232  ```
233
234
235## ethernet.isIfaceActive<a name=ethernet.isIfaceActive-promise></a>
236
237isIfaceActive\(iface: string\): Promise<number\>
238
239判断接口是否已激活,使用Promise方式作为异步方法。
240
241需要ohos.permission.GET\_NETWORK\_INFO权限,该权限为系统权限。
242
243- 参数
244
245  | 参数名 | 类型   | 必填 | 说明   |
246  | ------ | ------ | ---- | ------ |
247  | iface  | string | 是   | 接口名 |
248
249- 返回值
250
251  | 类型                  | 说明                                                         |
252  | --------------------- | ------------------------------------------------------------ |
253  | Promise&lt;number&gt; | 以Promise形式返回获取结果。已激活:1,未激活:0,其他为获取失败错误码。 |
254
255- 示例
256
257  ```js
258  ethernet.isIfaceActive("eth0").then((data) => {
259  	console.log("isIfaceActive promiss = " + data);
260  }).catch((error) => {
261  	console.log("isIfaceActive promiss error = " + error);
262  });
263  ```
264
265## ethernet.getAllActiveIfaces<a name=ethernet.getAllActiveIfaces-callback></a>
266
267getAllActiveIfaces\(callback: AsyncCallback<Array\<string\>\>\): void
268
269获取活动的网络接口,使用callback方式作为异步方法。
270
271需要ohos.permission.GET\_NETWORK\_INFO权限,该权限为系统权限。
272
273- 参数
274
275  | 参数名   | 类型                                 | 必填 | 说明                           |
276  | -------- | ------------------------------------ | ---- | ------------------------------ |
277  | callback | AsyncCallback&lt;Array\<string\>&gt; | 是   | 回调函数。返回值为对应接口名。 |
278
279
280- 示例
281
282  ```js
283  ethernet.getAllActiveIfaces((error, value) => {
284  	if (error) {
285  		console.log("getAllActiveIfaces callback error = " + error);
286  	} else {
287          console.log("getAllActiveIfaces callback value.length = " + value.length);
288  		for (let i = 0; i < value.length; i++) {
289  			console.log("getAllActiveIfaces callback = " + value[i]);
290  		}
291  	}
292  });
293  ```
294
295## ethernet.getAllActiveIfaces<a name=ethernet.getAllActiveIfaces-promise></a>
296
297getAllActiveIfaces\(\): Promise<Array\<string\>\>
298
299获取活动的网络接口,使用Promise方式作为异步方法。
300
301需要ohos.permission.GET\_NETWORK\_INFO权限,该权限为系统权限。
302
303- 返回值
304
305  | 类型                           | 说明                                            |
306  | ------------------------------ | ----------------------------------------------- |
307  | Promise&lt;Array\<string\>&gt; | 以Promise形式返回获取结果。返回值为对应接口名。 |
308
309- 示例
310
311  ```js
312  ethernet.getAllActiveIfaces().then((data) => {
313      console.log("getAllActiveIfaces promiss data.length = " + data.length);
314  	for (let i = 0; i < data.length; i++) {
315  		console.log("getAllActiveIfaces promiss  = " + data[i]);
316  	}
317  }).catch((error) => {
318  	console.log("getAllActiveIfaces promiss error = " + error);
319  });
320  ```
321
322##
323
324## 相关仓
325
326netmanager_base
327
328netmanager_ext
329
330[电话服务子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E7%94%B5%E8%AF%9D%E6%9C%8D%E5%8A%A1%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
331
332[ telephony_cellular_data](https://gitee.com/openharmony/telephony_cellular_data/blob/master/README.md)
333
334