controlfns_unix.go raw
1 //go:build !windows && !linux && !wasm
2
3 /* SPDX-License-Identifier: MIT
4 *
5 * Copyright (C) 2017-2025 WireGuard LLC. All Rights Reserved.
6 */
7
8 package conn
9
10 import (
11 "syscall"
12
13 "golang.org/x/sys/unix"
14 )
15
16 func init() {
17 controlFns = append(controlFns,
18 func(network, address string, c syscall.RawConn) error {
19 return c.Control(func(fd uintptr) {
20 _ = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_RCVBUF, socketBufferSize)
21 _ = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_SNDBUF, socketBufferSize)
22 })
23 },
24
25 func(network, address string, c syscall.RawConn) error {
26 var err error
27 if network == "udp6" {
28 c.Control(func(fd uintptr) {
29 err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_V6ONLY, 1)
30 })
31 }
32 return err
33 },
34 )
35 }
36