Source file src/vendor/golang.org/x/net/quic/udp_darwin.go
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 darwin 6 7 package quic 8 9 import ( 10 "encoding/binary" 11 "syscall" 12 ) 13 14 // These socket options are available on darwin, but are not in the syscall 15 // package. Since syscall package is frozen, just define them manually here. 16 const ( 17 ip_recvtos = 0x1b 18 ipv6_recvpktinfo = 0x3d 19 ipv6_pktinfo = 0x2e 20 ) 21 22 // See udp.go. 23 const ( 24 udpECNSupport = true 25 udpInvalidLocalAddrIsError = true 26 ) 27 28 // Confusingly, on Darwin the contents of the IP_TOS option differ depending on whether 29 // it is used as an inbound or outbound cmsg. 30 31 func parseIPTOS(b []byte) (ecnBits, bool) { 32 // Single byte. The low two bits are the ECN field. 33 if len(b) != 1 { 34 return 0, false 35 } 36 return ecnBits(b[0] & ecnMask), true 37 } 38 39 func appendCmsgECNv4(b []byte, ecn ecnBits) []byte { 40 // 32-bit integer. 41 // https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/netinet/in_tclass.c#L1062-L1073 42 b, data := appendCmsg(b, syscall.IPPROTO_IP, syscall.IP_TOS, 4) 43 binary.NativeEndian.PutUint32(data, uint32(ecn)) 44 return b 45 } 46