netUtils

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_HTTP_PORT  = 80
	DEFAULT_WS_PORT    = 80
	DEFAULT_WSS_PORT   = 443
	DEFAULT_HTTPS_PORT = 443
	DEFAULT_GRPC_PORT  = 9090
)
View Source
const (
	// network masks
	MASK8  uint32 = 0b11111111_00000000_00000000_00000000
	MASK12 uint32 = 0b11111111_11110000_00000000_00000000
	MASK16 uint32 = 0b11111111_11111111_00000000_00000000
	MASK24 uint32 = 0b11111111_11111111_11111111_00000000
	MASK32 uint32 = 0b11111111_11111111_11111111_11111111
	// reserved IP adresses
	IP_192_168_0_0 uint32 = 0b11000000_10101000_00000000_00000000
	IP_172_16_0_0  uint32 = 0b10101100_00010000_00000000_00000000
	IP_10_0_0_0    uint32 = 0b00001010_00000000_00000000_00000000
	// reserved for Local Network IP addresses
	PRESERVED_IP_RANGE_192 uint32 = IP_192_168_0_0 & MASK16
	PRESERVED_IP_RANGE_172 uint32 = IP_172_16_0_0 & MASK12
	PRESERVED_IP_RANGE_10  uint32 = IP_10_0_0_0 & MASK8
)

Variables

View Source
var (
	ErrInitializingRequest = errors.New("error while initializing the request")
	ErrReadingBody         = errors.New("err while reading the body")
	ErrDialingServ         = errors.New("err while dealing the server")
	ErrInterfaceNotFound   = errors.New("provided network interface name wasn't found")
)
View Source
var DefaultNetInterfaceNames = NetInterfaceNamesT{
	"eth0":  {},
	"wlan0": {},
}

DefaultNetInterfaceNames are interface names that I have on my machine

Functions

func BytesToUint32

func BytesToUint32(in []uint8) (uint32, error)

func ConnHttpReadRespCodes

func ConnHttpReadRespCodes(conn net.Conn) (codes []int, err error)

Optimised to read only response codes Reads response codes until getting EOF or error

func GetLanIP

func GetLanIP(interfaceNames NetInterfaceNamesT) (net.IP, error)

func GetWanIP

func GetWanIP(ipv4 bool) (net.IP, error)

func IpToInt

func IpToInt(ip net.IP) uint32

IpToInt converts IP which is a byte array to an integer So it can be used with the bitmasks or be compared fast

func MaskToBytes

func MaskToBytes[T common.Int](mask T) [4]uint8

Types

type IPortRange

type IPortRange common_utils.IRange[int]

type NetInterfaceNamesT

type NetInterfaceNamesT = map[string]struct{}

type WSMsg

type WSMsg struct {
	Type int
	Data json.RawMessage
}

Jump to

Keyboard shortcuts

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