github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/proxy/vmess/addr.go (about) 1 package vmess 2 3 import ( 4 "context" 5 6 "github.com/Asutorufa/yuhaiin/pkg/net/netapi" 7 ) 8 9 // Atyp is vmess addr type 10 type Atyp byte 11 12 // Atyp 13 const ( 14 AtypErr Atyp = 0 15 AtypIP4 Atyp = 1 16 AtypDomain Atyp = 2 17 AtypIP6 Atyp = 3 18 ) 19 20 type address struct{ netapi.Address } 21 22 func (a address) Type() Atyp { 23 if a.IsFqdn() { 24 return AtypDomain 25 } 26 27 if a.AddrPort(context.Background()).V.Addr().Is6() { 28 return AtypIP6 29 } 30 31 return AtypIP4 32 } 33 34 func (a address) Bytes() []byte { 35 36 if a.IsFqdn() { 37 return append([]byte{byte(len(a.Hostname()))}, []byte(a.Hostname())...) 38 } 39 40 return a.AddrPort(context.Background()).V.Addr().AsSlice() 41 }