Created
July 7, 2022 17:24
-
-
Save kevmo314/78e5af0583ca74196715e94d02da8a27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ecn | |
import ( | |
"net" | |
"reflect" | |
"syscall" | |
) | |
// EnableExplicitCongestionNotification enables ECN on the given connection. | |
func EnableExplicitCongestionNotification(conn *net.UDPConn) { | |
ptrVal := reflect.ValueOf(*conn) | |
fdmember := reflect.Indirect(ptrVal).FieldByName("fd") | |
pfdmember := reflect.Indirect(fdmember).FieldByName("pfd") | |
netfdmember := reflect.Indirect(pfdmember).FieldByName("Sysfd") | |
fd := int(netfdmember.Int()) | |
syscall.SetsockoptInt(fd, syscall.IPPROTO_IP, syscall.IP_RECVTOS, 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment