code: private static String getHostAddress(InetSocketAddress addr) {
      String hostToAppend = "";
      if (addr.isUnresolved()) {
        hostToAppend = addr.getHostName();
      } else {
        hostToAppend = addr.getAddress().getHostAddress();
      }
      return hostToAppend;
    }
docs: Returns the address of the host minimizing DNS lookups.
  @param addr
  @return