• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 OHOS_ADDRESS_UTILS_H
17 #define OHOS_ADDRESS_UTILS_H
18 
19 #include <stdint.h>
20 #include <stddef.h>
21 #include <dhcp_define.h>
22 
23 #define MAC_ADDR_LENGTH 6
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 uint32_t NetworkAddress(uint32_t ip, uint32_t netmask);
30 uint32_t FirstIpAddress(uint32_t ip, uint32_t netmask);
31 uint32_t NextIpAddress(uint32_t currIp, uint32_t netmask, uint32_t offset);
32 uint32_t FirstNetIpAddress(uint32_t networkAddr);
33 uint32_t LastIpAddress(uint32_t ip, uint32_t netmask);
34 int IpInNetwork(uint32_t ip, uint32_t network, uint32_t netmask);
35 int IpInRange(uint32_t ip, uint32_t beginIp, uint32_t endIp, uint32_t netmask);
36 uint32_t BroadCastAddress(uint32_t ip, uint32_t netmask);
37 uint32_t ParseIpAddr(const char *strIp);
38 uint32_t ParseIpHtonl(const char *strIp);
39 int NetworkBits(uint32_t netmask);
40 uint32_t HostBits(uint32_t netmask);
41 uint32_t HostTotal(uint32_t netmask);
42 uint32_t ParseIp(const uint8_t *ipAddr);
43 const char *ParseStrIp(uint32_t ipAddr);
44 int IsEmptyHWAddr(const uint8_t macAddr[DHCP_HWADDR_LENGTH]);
45 char *ParseStrMac(const uint8_t *macAddr, size_t addrSize);
46 int ParseMacAddress(const char *strMac, uint8_t macAddr[DHCP_HWADDR_LENGTH]);
47 
48 uint32_t HostToNetwork(uint32_t host);
49 uint32_t NetworkToHost(uint32_t network);
50 
51 char *ParseLogMac(uint8_t macAddr[DHCP_HWADDR_LENGTH]);
52 int AddrEquels(const uint8_t firstAddr[DHCP_HWADDR_LENGTH], uint8_t secondAddr[DHCP_HWADDR_LENGTH], int addrLength);
53 #ifdef __cplusplus
54 }
55 #endif
56 #endif
57