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 #ifndef OHOS_FUNCTION_H 17 #define OHOS_FUNCTION_H 18 19 #include <cstring> 20 #include <iomanip> 21 #include <arpa/inet.h> 22 #include <string> 23 #include <cstdio> 24 25 #include "dhcp_define.h" 26 27 namespace OHOS { 28 namespace DHCP { 29 class DhcpFunction { 30 public: DhcpFunction()31 DhcpFunction() {} ~DhcpFunction()32 ~DhcpFunction() {} 33 34 static bool Ip4StrConToInt(const std::string& strIp, uint32_t& uIp, bool bHost = true); 35 static bool Ip6StrConToChar(const std::string& strIp, uint8_t chIp[], size_t uSize); 36 static std::string Ip6CharConToStr(uint8_t chIp[], int size); 37 static bool CheckIpStr(const std::string& strIp); 38 static int GetLocalIp(const std::string strInf, std::string& strIp, std::string& strMask); 39 static int GetLocalMac(const std::string ethInf, std::string& ethMac); 40 static int CheckRangeNetwork(const std::string strInf, const std::string strBegin, const std::string strEnd); 41 static bool CheckSameNetwork(const uint32_t srcIp, const uint32_t dstIp, const uint32_t maskIp); 42 43 static bool IsExistFile(const std::string& filename); 44 static bool CreateFile(const std::string& filename, const std::string& filedata); 45 static bool RemoveFile(const std::string& filename); 46 static int FormatString(struct DhcpPacketResult &result); 47 static int CreateDirs(const std::string dirs, int mode = DIR_DEFAULT_MODE); 48 static bool SplitString( 49 const std::string src, const std::string delim, const int count, std::vector<std::string> &splits); 50 #ifdef OHOS_ARCH_LITE 51 static int GetDhcpPacketResult(const std::string& filename, struct DhcpPacketResult &result); 52 #else 53 #endif 54 }; 55 } // namespace DHCP 56 } // namespace OHOS 57 #endif