53 lines
913 B
Go
53 lines
913 B
Go
package host
|
|
|
|
import (
|
|
"lux/proto"
|
|
"net/netip"
|
|
)
|
|
|
|
type LuxOptionWAN struct {
|
|
Addr4 netip.Addr
|
|
Addr6 netip.Addr
|
|
}
|
|
|
|
// always use this constructor, since if there is no IPv6 or no IPv4,
|
|
// they must be zeroed
|
|
func NewLuxOptionWAN() LuxOptionWAN {
|
|
return LuxOptionWAN{
|
|
Addr4: netip.IPv4Unspecified(),
|
|
Addr6: netip.IPv6Unspecified(),
|
|
}
|
|
}
|
|
|
|
func (opt *LuxOptionWAN) HasIPv4() bool {
|
|
return !opt.Addr4.IsUnspecified()
|
|
}
|
|
|
|
func (opt *LuxOptionWAN) HasIPv6() bool {
|
|
return !opt.Addr6.IsUnspecified()
|
|
}
|
|
|
|
func (opt *LuxOptionWAN) Read(rd *proto.LuxBuffer) error {
|
|
addr4, err := rd.ReadIP()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
opt.Addr4 = addr4
|
|
|
|
addr6, err := rd.ReadIP()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
opt.Addr6 = addr6
|
|
|
|
return nil
|
|
}
|
|
|
|
func (opt *LuxOptionWAN) Write(wd *proto.LuxBuffer) {
|
|
wd.WriteIP(opt.Addr4)
|
|
wd.WriteIP(opt.Addr6)
|
|
}
|
|
|
|
func (*LuxOptionWAN) Type() LuxOptionType {
|
|
return LuxOptionTypeWAN
|
|
}
|