• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 DNS_GETADDRINFO_H
17 #define DNS_GETADDRINFO_H
18 
19 #include "dns_lookup_name.h"
20 
21 #include <endian.h>
22 
23 namespace OHOS {
24 namespace nmd {
25 class DnsGetAddrInfo {
26 public:
27     DnsGetAddrInfo() = default;
28     ~DnsGetAddrInfo() = default;
29 
30     /**
31      * Get the Addr Info object
32      *
33      * @param host host name
34      * @param serv server
35      * @param hint limits
36      * @param res after look up back data
37      * @param netId designated network
38      * @return int 0-success, <0-failed
39      */
40     int32_t GetAddrInfo(const std::string &hostName, const std::string &serverName, const AddrInfo &hints,
41                         uint16_t netId, std::vector<AddrInfo> &res);
42 
43 private:
44     static void ParseAddr(int32_t nAddrs, int32_t nServ, ServData (&ports)[MAXSERVS], AddrData (&addrs)[MAXADDRS],
45                           char *outCanon, int32_t canonLen, std::vector<AddrInfo> &out);
46     static int32_t CheckHints(const AddrInfo &hints);
47     static void SwitchFamilyInet(AddrInfo &node, AddrData addrs, uint16_t port);
48     static void SwitchFamilyInet6(AddrInfo &node, AddrData addrs, uint16_t port);
49 };
50 } // namespace nmd
51 } // namespace OHOS
52 #endif // DNS_GETADDRINFO_H
53