transfer

package
v0.0.0-...-bb0ef8c Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MulanPSL-2.0 Imports: 6 Imported by: 0

README

transfer

传输层协议库。

  • ReadSocket:从Socket中读取指定长度数据。
  • ReadSocketWithMaxLength:从Socket中读取指定长度的数据,校验最大长度是否有效。
  • IsLAN:判断是否是局域网IP地址。
  • CheckIpRange:判断IP是否位于区间内。
  • 字节流大端序:ReadBigEndianWriteBigEndian
  • 字节流小端序:ReadLittleEndianWriteLittleEndian

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AFromIp = net.ParseIP("10.0.0.0")
	AToIp   = net.ParseIP("10.255.255.255")
	BFromIp = net.ParseIP("172.16.0.0")
	BToIp   = net.ParseIP("172.31.255.255")
	CFromIp = net.ParseIP("192.168.0.0")
	CToIp   = net.ParseIP("192.168.255.255")
)

局域网网段

Functions

func CheckIpRange

func CheckIpRange(
	curIp net.IP,
	fromIp net.IP,
	toIp net.IP,
) bool

检查IP是否位于区间中

func IsLAN

func IsLAN(addr string) bool

检查是否为局域网地址

func ReadBigEndian

func ReadBigEndian(content []byte, target interface{}) (err error)

按大端序解析[]byte到结构体

func ReadLittleEndian

func ReadLittleEndian(content []byte, target interface{}) (err error)

按小端序解析[]byte到结构体

func ReadSocket

func ReadSocket(
	conn net.Conn,
	length uint32,
) (buf []byte, err error)

从连接中读取数据,不判断最大长度

func ReadSocketWithMaxLength

func ReadSocketWithMaxLength(
	conn net.Conn,
	length uint32,
	maxLength uint32,
) (buf []byte, err error)

从连接中读取数据,判断最大长度

func WriteBigEndian

func WriteBigEndian(content interface{}) (result []byte, err error)

将数据转换为大端序

func WriteLittleEndian

func WriteLittleEndian(content interface{}) (result []byte, err error)

将数据转换为小端序

Types

This section is empty.

Jump to

Keyboard shortcuts

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