forked from quic-go/quic-go
check the length of IPv4 packet info control messages, add log message (#3920)
This commit is contained in:
@@ -2,7 +2,12 @@
|
||||
|
||||
package quic
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
import (
|
||||
"encoding/binary"
|
||||
"net/netip"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
const (
|
||||
msgTypeIPTOS = unix.IP_RECVTOS
|
||||
@@ -12,3 +17,15 @@ const (
|
||||
// ReadBatch only returns a single packet on OSX,
|
||||
// see https://godoc.org/golang.org/x/net/ipv4#PacketConn.ReadBatch.
|
||||
const batchSize = 1
|
||||
|
||||
func parseIPv4PktInfo(body []byte) (ip netip.Addr, ifIndex uint32, ok bool) {
|
||||
// struct in_pktinfo {
|
||||
// unsigned int ipi_ifindex; /* Interface index */
|
||||
// struct in_addr ipi_spec_dst; /* Local address */
|
||||
// struct in_addr ipi_addr; /* Header Destination address */
|
||||
// };
|
||||
if len(body) != 12 {
|
||||
return netip.Addr{}, 0, false
|
||||
}
|
||||
return netip.AddrFrom4(*(*[4]byte)(body[8:12])), binary.LittleEndian.Uint32(body), true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user