Skip to content

Instantly share code, notes, and snippets.

@kevmo314
Created July 7, 2022 17:24
Show Gist options
  • Save kevmo314/78e5af0583ca74196715e94d02da8a27 to your computer and use it in GitHub Desktop.
Save kevmo314/78e5af0583ca74196715e94d02da8a27 to your computer and use it in GitHub Desktop.
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