View Javadoc
1   /*
2    * Copyright 2017-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.software.os.unix.solaris;
6   
7   import static com.sun.jna.platform.unix.LibCAPI.HOST_NAME_MAX;
8   
9   import com.sun.jna.Native;
10  
11  import oshi.annotation.concurrent.ThreadSafe;
12  import oshi.jna.platform.unix.SolarisLibc;
13  import oshi.software.common.AbstractNetworkParams;
14  import oshi.util.ExecutingCommand;
15  
16  /**
17   * SolarisNetworkParams class.
18   */
19  @ThreadSafe
20  final class SolarisNetworkParams extends AbstractNetworkParams {
21  
22      private static final SolarisLibc LIBC = SolarisLibc.INSTANCE;
23  
24      @Override
25      public String getHostName() {
26          byte[] hostnameBuffer = new byte[HOST_NAME_MAX + 1];
27          if (0 != LIBC.gethostname(hostnameBuffer, hostnameBuffer.length)) {
28              return super.getHostName();
29          }
30          return Native.toString(hostnameBuffer);
31      }
32  
33      @Override
34      public String getIpv4DefaultGateway() {
35          return searchGateway(ExecutingCommand.runNative("route get -inet default"));
36      }
37  
38      @Override
39      public String getIpv6DefaultGateway() {
40          return searchGateway(ExecutingCommand.runNative("route get -inet6 default"));
41      }
42  }