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 {
|
||||||
|
return if (networkInterface.isNotEmpty()) {
|
||||||
|
logger.debug { "Using network interface $networkInterface" }
|
||||||
val iface = NetworkInterface.getByName(networkInterface)
|
val iface = NetworkInterface.getByName(networkInterface)
|
||||||
?: throw RuntimeException("Could not find network interface $networkInterface")
|
?: throw RuntimeException("Could not find network interface $networkInterface")
|
||||||
val addresses = iface.inetAddresses
|
|
||||||
while (addresses.hasMoreElements()) {
|
iface.inetAddresses.toList().filterIsInstance<Inet4Address>().first()
|
||||||
val x = addresses.nextElement()
|
} else {
|
||||||
if (x is Inet4Address) {
|
logger.info { "No network interface given, using default local address" }
|
||||||
return x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
InetAddress.getLocalHost()
|
InetAddress.getLocalHost()
|
||||||
|
}.also {
|
||||||
|
logger.debug { "Found local address ${it.hostAddress}" }
|
||||||
|
}
|
||||||
} 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