ping: Fix read ipv4 header on darwin

This commit is contained in:
世界 2025-08-25 01:19:52 +08:00
parent fe4e54bb0d
commit c089ffbd6c
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 25 additions and 0 deletions

View file

@ -159,6 +159,10 @@ func (c *Conn) ReadIP(buffer *buf.Buffer) error {
}
if !c.destination.Is6() {
ipHdr := header.IPv4(buffer.Bytes())
if runtime.GOOS == "darwin" || runtime.GOOS == "ios" {
ipHdr.SetTotalLength(ipHdr.TotalLengthDarwinRaw())
ipHdr.SetFlagsFragmentOffset(ipHdr.FlagsDarwinRaw(), ipHdr.FragmentOffsetDarwinRaw())
}
if !ipHdr.IsValid(buffer.Len()) {
return E.New("invalid IPv4 header received")
}