NetworkUtils/src/dorkbox/netUtil/VirtualEth.kt

35 lines
942 B
Kotlin

package dorkbox.netUtil
import dorkbox.executor.Executor
object VirtualEth {
/**
* Gets the version number.
*/
const val version = "2.9.1"
fun add(host: String, guest: String) {
if (Common.OS_LINUX) {
Executor().command("/sbin/ip", "link", "add", "name", host, "type", "veth", "peer", "name", guest).startBlocking()
} else {
throw RuntimeException("NOT IMPL.")
}
}
fun delete(host: String) {
if (Common.OS_LINUX) {
Executor().command("/sbin/ip", "link", "del", host).startBlocking()
} else {
throw RuntimeException("NOT IMPL.")
}
}
fun assignNameSpace(nameSpace: String, guest: String) {
if (Common.OS_LINUX) {
Executor().command("/sbin/ip", "link", "set", guest, "netns", nameSpace).startBlocking()
} else {
throw RuntimeException("NOT IMPL.")
}
}
}