Improve socksaddr

This commit is contained in:
世界 2022-07-20 21:52:04 +08:00
parent 2af19486bb
commit fd4ec74d5e
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
9 changed files with 34 additions and 47 deletions

View file

@ -43,7 +43,15 @@ func NewSerializer(options ...SerializerOption) *Serializer {
}
func (s *Serializer) WriteAddress(writer io.Writer, addr Socksaddr) error {
err := rw.WriteByte(writer, s.familyByteMap[addr.Family()])
var family Family
if addr.IsIPv4() {
family = AddressFamilyIPv4
} else if addr.IsIPv6() {
family = AddressFamilyIPv6
} else {
family = AddressFamilyFqdn
}
err := rw.WriteByte(writer, family)
if err != nil {
return err
}
@ -56,12 +64,11 @@ func (s *Serializer) WriteAddress(writer io.Writer, addr Socksaddr) error {
}
func (s *Serializer) AddressLen(addr Socksaddr) int {
switch addr.Family() {
case AddressFamilyIPv4:
if addr.IsIPv4() {
return 5
case AddressFamilyIPv6:
} else if addr.IsIPv6() {
return 17
default:
} else {
return 2 + len(addr.Fqdn)
}
}