private static String getRequestingHost(String requestingUser, HttpServletRequest request) {
    final String unkHost = "???";
    if(request == null) {
      LOG.warn("request is null; cannot determine hostname");
      return unkHost;
    }
    try {
      String address = request.getRemoteAddr();//returns IP addr
      if(address == null) {
        LOG.warn(MessageFormat.format("Request remote address is NULL for user [{0}]", requestingUser));
        return unkHost;
      }

      //Inet4Address/Inet6Address
      String hostName = InetAddress.getByName(address).getCanonicalHostName();
      if(LOG.isDebugEnabled()) {
        LOG.debug(MessageFormat.format("Resolved remote hostname: [{0}]", hostName));
      }
      return hostName;

    } catch (UnknownHostException ex) {
      LOG.warn(MessageFormat.format("Request remote address could not be resolved, {0}", ex.toString(), ex));
      return unkHost;
    }
  }
Returns canonical host name from which the request is made; used for doAs validation
hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java