github.com/bepass-org/wireguard-go@v1.0.4-rc2.0.20240304192354-ebce6572bc24/tun/operateonfd.go (about)

     1  //go:build darwin || freebsd
     2  
     3  /* SPDX-License-Identifier: MIT
     4   *
     5   * Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
     6   */
     7  
     8  package tun
     9  
    10  import (
    11  	"fmt"
    12  )
    13  
    14  func (tun *NativeTun) operateOnFd(fn func(fd uintptr)) {
    15  	sysconn, err := tun.tunFile.SyscallConn()
    16  	if err != nil {
    17  		tun.errors <- fmt.Errorf("unable to find sysconn for tunfile: %s", err.Error())
    18  		return
    19  	}
    20  	err = sysconn.Control(fn)
    21  	if err != nil {
    22  		tun.errors <- fmt.Errorf("unable to control sysconn for tunfile: %s", err.Error())
    23  	}
    24  }