mirror of
https://github.com/yggdrasil-network/water.git
synced 2025-05-20 00:45:09 +03:00

this makes it possible to get *os.File by using type assertion over ReadWriteCloser. resolves #7
39 lines
1,015 B
Go
39 lines
1,015 B
Go
package water
|
|
|
|
import "io"
|
|
|
|
// Interface is a TUN/TAP interface.
|
|
type Interface struct {
|
|
isTAP bool
|
|
io.ReadWriteCloser
|
|
name string
|
|
}
|
|
|
|
// Create a new TAP interface whose name is ifName.
|
|
// If ifName is empty, a default name (tap0, tap1, ... ) will be assigned.
|
|
// ifName should not exceed 16 bytes.
|
|
func NewTAP(ifName string) (ifce *Interface, err error) {
|
|
return newTAP(ifName)
|
|
}
|
|
|
|
// Create a new TUN interface whose name is ifName.
|
|
// If ifName is empty, a default name (tap0, tap1, ... ) will be assigned.
|
|
// ifName should not exceed 16 bytes.
|
|
func NewTUN(ifName string) (ifce *Interface, err error) {
|
|
return newTUN(ifName)
|
|
}
|
|
|
|
// Returns true if ifce is a TUN interface, otherwise returns false;
|
|
func (ifce *Interface) IsTUN() bool {
|
|
return !ifce.isTAP
|
|
}
|
|
|
|
// Returns true if ifce is a TAP interface, otherwise returns false;
|
|
func (ifce *Interface) IsTAP() bool {
|
|
return ifce.isTAP
|
|
}
|
|
|
|
// Returns the interface name of ifce, e.g. tun0, tap1, etc..
|
|
func (ifce *Interface) Name() string {
|
|
return ifce.name
|
|
}
|