1 /*
2  * Copyright (C) 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_WIFI_DNS_CHECKER_H
17 #define OHOS_WIFI_DNS_CHECKER_H
18 #include <arpa/inet.h>
19 #include <netinet/if_ether.h>
20 #include <string>
21 #include <atomic>
22 namespace OHOS {
23 namespace Wifi {
24 
25 class DnsChecker {
26 public:
27     DnsChecker();
28     ~DnsChecker();
29     void Start(std::string priDns, std::string secondDns);
30     void Stop();
31     void StopDnsCheck();
32     bool DoDnsCheck(std::string url, int timeoutMillis);
33 private:
34     void formatHostAdress(char* hostAddress, const char* host);
35     bool checkDnsValid(std::string host, std::string dnsAddress, int timeoutMillis);
36     int recvDnsData(char* buff, int size, int timeout);
37 private:
38     int dnsSocket;
39     std::string primaryDnsAddress;
40     std::string secondDnsAddress;
41     bool socketCreated;
42     std::atomic<bool> isRunning;
43 };
44 }
45 }
46 #endif
47