tcp

package
v0.8.10 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseConn

func CloseConn(conn *net.TCPConn)

CloseConn will run Close member function on provided as a parameter *net.TCPConn

func DialIPWithPortAndGetReply

func DialIPWithPortAndGetReply(ip net.IP, port uint16) (string, error)

func DialTCPAddrAndGetReply

func DialTCPAddrAndGetReply(address *net.TCPAddr) (string, error)

func GenRandomAddressIPv4

func GenRandomAddressIPv4(port uint16) *net.TCPAddr

GenRandomAddressIPv4 will generate random *net.TCPAddr (IPv4) with provided port

func GenRandomAddressIPv6

func GenRandomAddressIPv6(port uint16) *net.TCPAddr

GenRandomAddressIPv6 will generate random *net.TCPAddr (IPv6) with provided port

func ReplyWith

func ReplyWith(msg string) func(conn *net.TCPConn)

ReplyWith will return a function which will send to provided *net.TCPConn the message (string) from closure which was provided as a parameter to ReplyWith function

func ReplyWithOriginalDstIPv4

func ReplyWithOriginalDstIPv4(conn *net.TCPConn)

ReplyWithOriginalDstIPv4 will try to extract original destination from the IPv4 socket of the provided *net.TCPConn and send it back as a []byte, if the extraction will fail, the *net.TCPConn will receive error message as []byte instead

func ReplyWithOriginalDstIPv6

func ReplyWithOriginalDstIPv6(conn *net.TCPConn)

ReplyWithOriginalDstIPv6 will try to extract original destination from the IPv6 socket of the provided *net.TCPConn and send it back as a []byte, if the extraction will fail, the *net.TCPConn will receive error message as []byte instead

func UnsafeStartTCPServer

func UnsafeStartTCPServer(
	ns *netns.NetNS,
	address string,
	callbacks ...func(conn *net.TCPConn),
) (<-chan struct{}, <-chan error)

UnsafeStartTCPServer will start TCP server in provided *netns.NesNS. Every initialized tcp connection will be processed via provided callback functions. It was named UnsafeStartTCPServer instead of StartTCPServer because you have to be very cautious and remember to not spawn new goroutines inside provided callbacks (more info in warning below)

WARNING!:

Don't spawn new goroutines inside callback functions as the goroutine inside
UnsafeStartTCPServer function have exclusive access to the current network
namespace, and you should assume, that any new goroutine will be placed
in a different namespace

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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