Default network interface used
This commit is contained in:
parent
23e02c1b6f
commit
66d74acbfc
2 changed files with 16 additions and 15 deletions
|
@ -19,27 +19,28 @@ class ServerInfoProviderImpl(
|
||||||
@param:Value("\${server.port}") override val port: Int,
|
@param:Value("\${server.port}") override val port: Int,
|
||||||
@param:Value("\${server.interface}") private val networkInterface: String
|
@param:Value("\${server.interface}") private val networkInterface: String
|
||||||
) : ServerInfoProvider {
|
) : ServerInfoProvider {
|
||||||
override val host: String get() = address!!.hostAddress
|
override val host: String get() = address.hostAddress
|
||||||
var address: InetAddress? = null
|
val address: InetAddress = guessInetAddress()
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
fun init() {
|
fun init() {
|
||||||
address = guessInetAddress()
|
logger.info("Using server address: {} and port {}", address.hostAddress, port)
|
||||||
logger.info("Using server address: {} and port {}", address!!.hostAddress, port)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun guessInetAddress(): InetAddress {
|
private fun guessInetAddress(): InetAddress {
|
||||||
return try {
|
try {
|
||||||
val iface = NetworkInterface.getByName(networkInterface)
|
return if (networkInterface.isNotEmpty()) {
|
||||||
?: throw RuntimeException("Could not find network interface $networkInterface")
|
logger.debug { "Using network interface $networkInterface" }
|
||||||
val addresses = iface.inetAddresses
|
val iface = NetworkInterface.getByName(networkInterface)
|
||||||
while (addresses.hasMoreElements()) {
|
?: throw RuntimeException("Could not find network interface $networkInterface")
|
||||||
val x = addresses.nextElement()
|
|
||||||
if (x is Inet4Address) {
|
iface.inetAddresses.toList().filterIsInstance<Inet4Address>().first()
|
||||||
return x
|
} else {
|
||||||
}
|
logger.info { "No network interface given, using default local address" }
|
||||||
|
InetAddress.getLocalHost()
|
||||||
|
}.also {
|
||||||
|
logger.debug { "Found local address ${it.hostAddress}" }
|
||||||
}
|
}
|
||||||
InetAddress.getLocalHost()
|
|
||||||
} catch (e: UnknownHostException) {
|
} catch (e: UnknownHostException) {
|
||||||
throw RuntimeException(e)
|
throw RuntimeException(e)
|
||||||
} catch (e: SocketException) {
|
} catch (e: SocketException) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
server:
|
server:
|
||||||
port: ${NEXTCLOUD_DLNA_SERVER_PORT:8080}
|
port: ${NEXTCLOUD_DLNA_SERVER_PORT:8080}
|
||||||
interface: ${NEXTCLOUD_DLNA_INTERFACE:eth0}
|
interface: ${NEXTCLOUD_DLNA_INTERFACE:}
|
||||||
friendlyName: ${NEXTCLOUD_DLNA_FRIENDLY_NAME:Nextcloud-DLNA}
|
friendlyName: ${NEXTCLOUD_DLNA_FRIENDLY_NAME:Nextcloud-DLNA}
|
||||||
|
|
||||||
nextcloud:
|
nextcloud:
|
||||||
|
|
Loading…
Reference in a new issue