github.com/tailscale/wireguard-go@v0.0.20201119-0.20210522003738-46b531feb08a/tun/operateonfd.go (about)

     1  // +build !windows
     2  
     3  /* SPDX-License-Identifier: MIT
     4   *
     5   * Copyright (C) 2017-2021 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  }