github.com/tumi8/quic-go@v0.37.4-tum/sys_conn_helper_darwin.go (about) 1 //go:build darwin 2 3 package quic 4 5 import ( 6 "encoding/binary" 7 "net/netip" 8 9 "golang.org/x/sys/unix" 10 ) 11 12 const ( 13 msgTypeIPTOS = unix.IP_RECVTOS 14 ipv4PKTINFO = unix.IP_RECVPKTINFO 15 ) 16 17 // ReadBatch only returns a single packet on OSX, 18 // see https://godoc.org/golang.org/x/net/ipv4#PacketConn.ReadBatch. 19 const batchSize = 1 20 21 func parseIPv4PktInfo(body []byte) (ip netip.Addr, ifIndex uint32, ok bool) { 22 // struct in_pktinfo { 23 // unsigned int ipi_ifindex; /* Interface index */ 24 // struct in_addr ipi_spec_dst; /* Local address */ 25 // struct in_addr ipi_addr; /* Header Destination address */ 26 // }; 27 if len(body) != 12 { 28 return netip.Addr{}, 0, false 29 } 30 return netip.AddrFrom4(*(*[4]byte)(body[8:12])), binary.LittleEndian.Uint32(body), true 31 }