github.com/cawidtu/notwireguard-go/tun@v0.0.0-20230523131112-68e8e5ce9cdf/tun.go (about)

     1  /* SPDX-License-Identifier: MIT
     2   *
     3   * Copyright (C) 2017-2021 WireGuard LLC. All Rights Reserved.
     4   */
     5  
     6  package tun
     7  
     8  import (
     9  	"os"
    10  )
    11  
    12  type Event int
    13  
    14  const (
    15  	EventUp = 1 << iota
    16  	EventDown
    17  	EventMTUUpdate
    18  )
    19  
    20  type Device interface {
    21  	File() *os.File                 // returns the file descriptor of the device
    22  	Read([]byte, int) (int, error)  // read a packet from the device (without any additional headers)
    23  	Write([]byte, int) (int, error) // writes a packet to the device (without any additional headers)
    24  	Flush() error                   // flush all previous writes to the device
    25  	MTU() (int, error)              // returns the MTU of the device
    26  	Name() (string, error)          // fetches and returns the current name
    27  	Events() chan Event             // returns a constant channel of events related to the device
    28  	Close() error                   // stops the device and closes the event channel
    29  }