netif

package module
v0.0.0-...-29cf9de Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: BSD-3-Clause Imports: 8 Imported by: 0

README

Netif

This is a simple Golang package for reading, manipulating and writing the /etc/network/interface file in most Debian based distributions.

This package is heavily based on the Python library Debinterface github.com/dggreenbaum/debinterface.

Installation
go get github.com/xtmono/netif
Basic usage
package main

import (
    "github.com/xtmono/netif"
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Path

func Path(path string) fn.Option

Types

type AddrFamily

type AddrFamily int
const (
	INET AddrFamily = 1 + iota
	INET6
)

type AddrSource

type AddrSource int
const (
	DHCP AddrSource = 1 + iota
	STATIC
	LOOPBACK
	MANUAL
)

type InterfaceSet

type InterfaceSet struct {
	InterfacesReader

	InterfacesPath string
	Others         []string
	Adapters       []*NetworkAdapter
}

func NewInterfaceSet

func NewInterfaceSet(opts ...fn.Option) *InterfaceSet

func Parse

func Parse(opts ...fn.Option) (*InterfaceSet, error)

func (*InterfaceSet) Write

func (is *InterfaceSet) Write(opts ...fn.Option) error

func (*InterfaceSet) WriteToFile

func (is *InterfaceSet) WriteToFile(f *os.File) error

type InterfacesReader

type InterfacesReader struct {
	// contains filtered or unexported fields
}

TODO get rid of interfaceReader

func NewInterfacesReader

func NewInterfacesReader(filePath string) *InterfacesReader

func (*InterfacesReader) ParseInterfaces

func (ir *InterfacesReader) ParseInterfaces() ([]string, []*NetworkAdapter, error)

type NetworkAdapter

type NetworkAdapter struct {
	Name    string
	Auto    bool
	Hotplug bool
	IPs     []*NetworkIP
}

A representation of a network adapter

func (*NetworkAdapter) ParseAddressFamily

func (na *NetworkAdapter) ParseAddressFamily(AddressFamily string) (AddrFamily, error)

func (*NetworkAdapter) ParseAddressSource

func (na *NetworkAdapter) ParseAddressSource(AddressSource string) (AddrSource, error)

type NetworkIP

type NetworkIP struct {
	AddrSource     AddrSource
	AddrFamily     AddrFamily
	Address        net.IP
	Netmask        net.IPMask
	Broadcast      net.IP
	Network        net.IP
	Metric         *int
	Gateway        net.IP
	DNSNameServers []net.IP
	Others         []string
}

func (*NetworkIP) DNSConcatString

func (na *NetworkIP) DNSConcatString() string

func (*NetworkIP) GetAddrFamilyString

func (a *NetworkIP) GetAddrFamilyString() string

func (*NetworkIP) GetSourceFamilyString

func (a *NetworkIP) GetSourceFamilyString() string

func (*NetworkIP) SetAddress

func (na *NetworkIP) SetAddress(address string) error

func (*NetworkIP) SetBroadcast

func (na *NetworkIP) SetBroadcast(address string) error

func (*NetworkIP) SetConfigType

func (na *NetworkIP) SetConfigType(configType string) error

func (*NetworkIP) SetDNSNameServers

func (na *NetworkIP) SetDNSNameServers(address string) error

func (*NetworkIP) SetGateway

func (na *NetworkIP) SetGateway(address string) error

func (*NetworkIP) SetMetric

func (na *NetworkIP) SetMetric(address string) error

func (*NetworkIP) SetNetmask

func (na *NetworkIP) SetNetmask(address string) error

func (*NetworkIP) SetNetwork

func (na *NetworkIP) SetNetwork(address string) error

func (*NetworkIP) SetOthers

func (na *NetworkIP) SetOthers(address string) error

Directories

Path Synopsis
examples
1 command

Jump to

Keyboard shortcuts

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