View Javadoc
1   /*
2    * Copyright 2019 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.resolver.dns.macos;
17  
18  import io.netty.channel.unix.NativeInetAddress;
19  
20  import java.net.InetSocketAddress;
21  
22  /**
23   * Represent the {@code dns_resolver_t} struct.
24   */
25  final class DnsResolver {
26  
27      private final String domain;
28      private final InetSocketAddress[] nameservers;
29      private final int port;
30      private final String[] searches;
31      private final String options;
32      private final int timeout;
33      private final int searchOrder;
34  
35      DnsResolver(String domain, byte[][] nameservers, int port,
36                  String[] searches, String options, int timeout, int searchOrder) {
37          this.domain = domain;
38          if (nameservers == null) {
39              this.nameservers = new InetSocketAddress[0];
40          } else {
41              this.nameservers = new InetSocketAddress[nameservers.length];
42              for (int i = 0; i < nameservers.length; i++) {
43                  byte[] addr = nameservers[i];
44                  this.nameservers[i] = NativeInetAddress.address(addr, 0, addr.length);
45              }
46          }
47          this.port = port;
48          this.searches = searches;
49          this.options = options;
50          this.timeout = timeout;
51          this.searchOrder = searchOrder;
52      }
53  
54      String domain() {
55          return domain;
56      }
57  
58      InetSocketAddress[] nameservers() {
59          return nameservers;
60      }
61  
62      int port() {
63          return port;
64      }
65  
66      String[] searches() {
67          return searches;
68      }
69  
70      String options() {
71          return options;
72      }
73  
74      int timeout() {
75          return timeout;
76      }
77  
78      int searchOrder() {
79          return searchOrder;
80      }
81  }