mihomo/constant/addr.go

41 lines
507 B
Go
Raw Normal View History

2018-06-10 22:50:03 +08:00
package constant
2018-06-11 18:36:39 +08:00
import (
"net"
)
2018-06-10 22:50:03 +08:00
// Socks addr type
const (
AtypIPv4 = 1
AtypDomainName = 3
AtypIPv6 = 4
2018-06-14 01:00:58 +08:00
TCP = iota
UDP
2018-06-10 22:50:03 +08:00
)
2018-06-14 01:00:58 +08:00
type NetWork int
func (n *NetWork) String() string {
if *n == TCP {
return "tcp"
}
return "udp"
}
2018-06-10 22:50:03 +08:00
// Addr is used to store connection address
type Addr struct {
2018-06-14 01:00:58 +08:00
NetWork NetWork
2018-06-10 22:50:03 +08:00
AddrType int
Host string
2018-06-11 18:36:39 +08:00
IP *net.IP
2018-06-10 22:50:03 +08:00
Port string
}
2018-06-11 18:36:39 +08:00
func (addr *Addr) String() string {
if addr.Host == "" {
return addr.IP.String()
}
return addr.Host
}