Standardize a utility method for getting local host names.

This commit is contained in:
Jon Chambers
2021-06-09 12:19:53 -04:00
committed by Jon Chambers
parent 827a3af419
commit c634185b6f
4 changed files with 32 additions and 22 deletions

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2013-2021 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Locale;
public class HostnameUtil {
private static final Logger log = LoggerFactory.getLogger(HostnameUtil.class);
public static String getLocalHostname() {
try {
return InetAddress.getLocalHost().getHostName().toLowerCase(Locale.US);
} catch (final UnknownHostException e) {
log.warn("Failed to get hostname", e);
return "unknown";
}
}
}