Skip to content

Instantly share code, notes, and snippets.

@eyberg
Created January 1, 2025 16:41
Show Gist options
  • Save eyberg/aec645c5166e8945b94206d4bb46b859 to your computer and use it in GitHub Desktop.
Save eyberg/aec645c5166e8945b94206d4bb46b859 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net"
"golang.org/x/sys/unix"
)
func main() {
conn, err := net.ListenUDP("udp", nil)
if err != nil {
panic(err)
}
defer conn.Close()
rc, err := conn.SyscallConn()
if err != nil {
panic(err)
}
err = rc.Control(func(fd uintptr) {
err := unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_MTU_DISCOVER, unix.IP_PMTUDISC_DO)
if err != nil {
panic(err)
}
})
if err != nil {
panic(err)
}
bs := make([]byte, 7000)
fmt.Println(conn.WriteToUDP(bs, &net.UDPAddr{
IP: net.IPv4(8, 8, 8, 8),
Port: 53,
}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment