golang.org/x/net@v0.25.1-0.20240516223405-c87a5b62e243/quic/udp_darwin.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build go1.21 && darwin 6 7 package quic 8 9 import ( 10 "encoding/binary" 11 12 "golang.org/x/sys/unix" 13 ) 14 15 // See udp.go. 16 const ( 17 udpECNSupport = true 18 udpInvalidLocalAddrIsError = true 19 ) 20 21 // Confusingly, on Darwin the contents of the IP_TOS option differ depending on whether 22 // it is used as an inbound or outbound cmsg. 23 24 func parseIPTOS(b []byte) (ecnBits, bool) { 25 // Single byte. The low two bits are the ECN field. 26 if len(b) != 1 { 27 return 0, false 28 } 29 return ecnBits(b[0] & ecnMask), true 30 } 31 32 func appendCmsgECNv4(b []byte, ecn ecnBits) []byte { 33 // 32-bit integer. 34 // https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/netinet/in_tclass.c#L1062-L1073 35 b, data := appendCmsg(b, unix.IPPROTO_IP, unix.IP_TOS, 4) 36 binary.NativeEndian.PutUint32(data, uint32(ecn)) 37 return b 38 }