tcpip

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: MIT Imports: 5 Imported by: 0

README

1. INSTALL

go get -u github.com/ShaunPort/tcpip

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCountIPNum = errors.New("Start IP is greater than end IP") // 起始IP>结束IP
View Source
var ErrNotIP = errors.New("Not IPv4") // 不是IP数据包

错误列表

View Source
var ErrNotIPv4 = errors.New("Not IPv4 package") // 不是IPv4 无法解析
View Source
var ErrNotIPv6 = errors.New("Not IPv6 package") // 不是IPv4 无法解析
View Source
var ErrNullIP = errors.New("IP is null") // IP地址为空

Functions

func AdjustIPv4

func AdjustIPv4(pkg []byte, v4 string, start int, end int) error

*

  • 把点分十进制ip地址写入字符数组pkg start初始位置下标索引 end是最后位置下标索引+1

func AdjustIPv4Dst

func AdjustIPv4Dst(pkg []byte, v4 string) error

*

  • 写入IPv4目标地址到pkg报文中

func AdjustIPv4Src

func AdjustIPv4Src(pkg []byte, v4 string) error

*

  • 写入IPv4源地址到pkg报文中

func CountHostWithIPNet

func CountHostWithIPNet(ipNet *net.IPNet) uint32

CountHostWithIPNet 通过掩码计算得到CIDR地址范围内可拥有的主机数(去除广播地址和组播地址)

func CountIPNum

func CountIPNum(startIP, endIP net.IP) uint32

CountIPNum 通过起始地址、结束地址计算地址总数

func CountIPNumWithIPNet

func CountIPNumWithIPNet(ipNet *net.IPNet) uint32

CountIPNumWithIPNet 通过掩码计算得到CIDR地址范围内可拥有的地址总数

func CountIPNumWithMask

func CountIPNumWithMask(mask *net.IPMask) uint32

CountIPNumWithMask 通过掩码计算得到CIDR地址范围内地址总数

func DiffIP

func DiffIP(s, e net.IP) uint32

DiffIP 计算两个IP地址的差

func IPToUint32

func IPToUint32(ip net.IP) uint32

IPToUint32 IP转uint32 不用考虑字节序,已经处理了

func ObtainRangeSubnet

func ObtainRangeSubnet(ipNet *net.IPNet) (startIP, endIP net.IP)

ObtainRangeSubnet 得到一段子网的IP地址范围

func ParseIPv4

func ParseIPv4(pkg []byte, start int, end int) (net.IP, error)

*

  • 从字符数组中解析ipv4 start初始位置下标索引 end是最后位置下标索引+1
  • 后续需要完善判断pkg长度是否大于20

func ParseIPv4Dst

func ParseIPv4Dst(pkg []byte) (net.IP, error)

*

  • 从pkg报文中获取ipv4目标地址

func ParseIPv4Src

func ParseIPv4Src(pkg []byte) (net.IP, error)

*

  • 从pkg报文中获取ipv4源地址

func SumIP

func SumIP(ip net.IP, offset int) net.IP

SumIP 根据偏移量计算IP地址

func Uint32toIP

func Uint32toIP(uint32Value uint32) net.IP

Uint32toIP uint32转IP 不用考虑字节序,已经处理了

func Version

func Version(pkg []byte) int

*

  • 获取IP的版本

Types

type Nat

type Nat struct {
	Cidr       string // 内网地址
	DeviceName string // 出口网卡
}

func CreateNat

func CreateNat(cidr string, deviceName string) (*Nat, error)

func (*Nat) Close

func (nat *Nat) Close() error

Jump to

Keyboard shortcuts

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