Fix lint errors

This commit is contained in:
世界 2026-06-22 15:49:11 +08:00
parent a9f4123ba2
commit 46aa536b37
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
41 changed files with 498 additions and 406 deletions

View file

@ -878,7 +878,7 @@ func (o NDPDNSSearchList) iterDomainNames(fn func(string)) error {
}
// Copy the label and add a trailing period.
for i := 0; i < labelLen; i++ {
for i := range labelLen {
b, err := searchList.ReadByte()
if err != nil {
if err != io.EOF {

View file

@ -476,20 +476,14 @@ func ParseSynOptions(opts []byte, isAck bool) TCPSynOptions {
if mss == 0 {
return synOpts
}
synOpts.MSS = mss
if mss < TCPMinimumSendMSS {
synOpts.MSS = TCPMinimumSendMSS
}
synOpts.MSS = max(mss, TCPMinimumSendMSS)
i += 4
case TCPOptionWS:
if i+3 > limit || opts[i+1] != 3 {
return synOpts
}
ws := int(opts[i+2])
if ws > MaxWndScale {
ws = MaxWndScale
}
ws := min(int(opts[i+2]), MaxWndScale)
synOpts.WS = ws
i += 3
@ -561,7 +555,7 @@ func ParseTCPOptions(b []byte) TCPOptions {
}
numBlocks := (sackOptionLen - 2) / 8
opts.SACKBlocks = []SACKBlock{}
for j := 0; j < numBlocks; j++ {
for j := range numBlocks {
start := binary.BigEndian.Uint32(b[i+2+j*8:])
end := binary.BigEndian.Uint32(b[i+2+j*8+4:])
opts.SACKBlocks = append(opts.SACKBlocks, SACKBlock{
@ -646,10 +640,7 @@ func EncodeSACKBlocks(sackBlocks []SACKBlock, b []byte) int {
if len(sackBlocks) == 0 {
return 0
}
l := len(sackBlocks)
if l > TCPMaxSACKBlocks {
l = TCPMaxSACKBlocks
}
l := min(len(sackBlocks), TCPMaxSACKBlocks)
if ll := (len(b) - 2) / 8; ll < l {
l = ll
}

View file

@ -245,6 +245,53 @@ func (a Address) Len() int {
return a.length
}
// String implements the fmt.Stringer interface.
func (a Address) String() string {
switch l := a.Len(); l {
case 4:
return fmt.Sprintf("%d.%d.%d.%d", int(a.addr[0]), int(a.addr[1]), int(a.addr[2]), int(a.addr[3]))
case 16:
// Find the longest subsequence of hexadecimal zeros.
start, end := -1, -1
for i := 0; i < a.Len(); i += 2 {
j := i
for j < a.Len() && a.addr[j] == 0 && a.addr[j+1] == 0 {
j += 2
}
if j > i+2 && j-i > end-start {
start, end = i, j
}
}
var b strings.Builder
for i := 0; i < a.Len(); i += 2 {
if i == start {
b.WriteString("::")
i = end
if end >= a.Len() {
break
}
} else if i > 0 {
b.WriteByte(':')
}
v := uint16(a.addr[i+0])<<8 | uint16(a.addr[i+1])
if v == 0 {
b.WriteByte('0')
} else {
const digits = "0123456789abcdef"
for i := uint(3); i < 4; i-- {
if v := v >> (i * 4); v != 0 {
b.WriteByte(digits[v&0xf])
}
}
}
}
return b.String()
default:
return fmt.Sprintf("%x", a.addr[:l])
}
}
// WithPrefix returns the address with a prefix that represents a point subnet.
func (a Address) WithPrefix() AddressWithPrefix {
return AddressWithPrefix{
@ -541,7 +588,7 @@ func (a AddressWithPrefix) Subnet() Subnet {
address: a.Address,
mask: AddressMask{length: addrLen},
}
for i := 0; i < addrLen; i++ {
for i := range addrLen {
sub.mask.mask[i] = 0xff
}
return sub
@ -550,7 +597,7 @@ func (a AddressWithPrefix) Subnet() Subnet {
sa := Address{length: addrLen}
sm := AddressMask{length: addrLen}
n := uint(a.PrefixLen)
for i := 0; i < addrLen; i++ {
for i := range addrLen {
if n >= 8 {
sa.addr[i] = a.Address.addr[i]
sm.mask[i] = 0xff