github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/sys_conn_helper_darwin.go (about)

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