ncutils

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 24 Imported by: 2

Documentation

Overview

Package ncutils contains utility functions

Index

Constants

View Source
const NetclientDefaultPort = 51821

NetclientDefaultPort - default port

View Source
const PidFile = "/var/run/netclient.pid"

PidFile - path/name of pid file

Variables

This section is empty.

Functions

func ConvertBytesToKey

func ConvertBytesToKey(data []byte) (*[32]byte, error)

ConvertBytesToKey - util to convert bytes to a key to use elsewhere

func ConvertKeyToBytes

func ConvertKeyToBytes(key *[32]byte) ([]byte, error)

ConvertKeyToBytes - util to convert a key to bytes to use elsewhere

func Copy

func Copy(src, dst string) error

Copy - copies a src file to dest

func DNSFormatString

func DNSFormatString(input string) string

DNSFormatString - Formats a string with correct usage for DNS

func FileExists

func FileExists(f string) bool

FileExists - checks if file exists locally

func GetEmbedded

func GetEmbedded() error

GetEmbedded - if files required for linux, put here

func GetFreePort

func GetFreePort(rangestart, currListenPort int, init bool) (int, error)

GetFreePort - gets free port of machine. When currListenPort is set, it is preferred: we retry briefly so a port that our own WireGuard iface just released is not abandoned for curr+1 (e.g. 51821→51822).

func GetInterfaceName

func GetInterfaceName() string

GetInterfaceName - fetches the interface name

func GetInterfaces added in v0.90.0

func GetInterfaces() ([]schema.Iface, error)

func GetMacAddr

func GetMacAddr() ([]net.HardwareAddr, error)

GetMacAddr - get's mac address

func InterfaceExists added in v0.22.0

func InterfaceExists(ifaceName string) (bool, error)

InterfaceExists - checks if iface exists already

func IsBridgeNetwork added in v0.18.6

func IsBridgeNetwork(ifaceName string) bool

IsBridgeNetwork - check if the interface is a bridge type

func IsIPTablesPresent

func IsIPTablesPresent() bool

IsIPTablesPresent - returns true if iptables is present, false otherwise Does not consider OS, up to the caller to determine if the OS supports iptables/whether this check is valid.

func IsLinux

func IsLinux() bool

IsLinux - checks if is linux

func IsNFTablesPresent

func IsNFTablesPresent() bool

IsNFTablesPresent - returns true if nftables is present, false otherwise. Does not consider OS, up to the caller to determine if the OS supports nftables/whether this check is valid.

func IsPortFree added in v0.21.0

func IsPortFree(port int) (free bool)

IsPortFree - checks if port is free

func IsPublicIP added in v0.90.0

func IsPublicIP(ip net.IP) bool

IsPublicIP indicates whether IP is public or not.

func IsWindows

func IsWindows() bool

IsWindows - checks if is windows

func RandomMacAddress added in v0.18.5

func RandomMacAddress() net.HardwareAddr

RandomMacAddress returns a random macaddress

func RandomString added in v0.20.5

func RandomString(length int) string

RandomString - returns a random string in a charset

func ReadPID

func ReadPID() (int, error)

ReadPID - reads a previously saved pid from disk

func RunCmd

func RunCmd(command string, printerr bool) (string, error)

RunCmd - runs a local command

func RunCmdFormatted

func RunCmdFormatted(command string, printerr bool) (string, error)

RunCmdFormatted - does nothing for linux

func SavePID

func SavePID() error

SavePID - saves the pid of running program to disk

func SendRequest added in v1.5.0

func SendRequest(method, endpoint string, headers http.Header, data any) (*bytes.Buffer, error)

func SetInterfaceName added in v0.22.0

func SetInterfaceName(iface string)

func SetVerbosity added in v0.90.0

func SetVerbosity(logLevel int)

func ShortenString

func ShortenString(input string, length int) string

ShortenString - Brings string down to specified length. Stops names from being too long

func TraceCaller added in v0.90.0

func TraceCaller()

func WaitForUDPPortFree added in v1.7.0

func WaitForUDPPortFree(port int, timeout time.Duration) bool

WaitForUDPPortFree polls until port is free or timeout elapses. Used after WireGuard iface Close so GetFreePort does not bump ListenPort.

Types

type ErrStatusNotOk added in v1.5.0

type ErrStatusNotOk struct {
	Status  int
	Message string
}

func (ErrStatusNotOk) Error added in v1.5.0

func (e ErrStatusNotOk) Error() string

type WindowsPIDError

type WindowsPIDError struct{}

WindowsPIDError - error returned from pid function on windows

func (*WindowsPIDError) Error

func (*WindowsPIDError) Error() string

Error generates error for windows os

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL