Documentation
¶
Index ¶
- func IPChecksum(b []byte) uint16
- func InitRecvSocket() (int, error)
- func InitSendSocket() (int, error)
- func SetTimeout(fd int, duration time.Duration) error
- func TCPChecksum(tcpBytes []byte, ip *IPHeader) uint16
- func Unwrap(packet []byte) (*IPHeader, *TCPHeader, error)
- func Wrap(ip *IPHeader, tcp *TCPHeader) []byte
- type IPFlags
- type IPHeader
- type TCPFlags
- type TCPHeader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IPChecksum ¶
IPChecksum computes the checksum for IPv4 Wiki: https://en.wikipedia.org/wiki/IPv4_header_checksum Explanation: https://gist.github.com/david-hoze/0c7021434796997a4ca42d7731a7073a
func InitRecvSocket ¶
InitRecvSocket creates a raw socket for receiving packets.
func InitSendSocket ¶
InitSendSocket creates a raw socket for sending packets.
func SetTimeout ¶
SetTimeout sets a receive timeout on the socket file descriptor.
func TCPChecksum ¶
TCPChecksum computes the TCP checksum for IPv4 Wiki: https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Checksum_computation Explanation: https://gist.github.com/david-hoze/0c7021434796997a4ca42d7731a7073a
Types ¶
type IPHeader ¶
type IPHeader struct {
Version uint8 // Always 4
Ihl uint8 // Always 5 since we have no options
Tos uint8 // Always 0 when we send out, can be 8 when receiving from server
TotLen uint16
Id uint16
Flags IPFlags // 3 bits, part of uint16
FragOffset uint16 // 13 bits, part of uint16
Ttl uint8 // Always 64 when we send out
Protocol uint8 // Always 6 for TCP
Checksum uint16
SrcIp [4]byte
DstIp [4]byte
}
IPHeader struct size is 20 bytes for IPv4 https://en.wikipedia.org/wiki/IPv4#Header
func NewIPHeader ¶
NewIPHeader converts a byte array into an IPv4 header
type TCPFlags ¶
type TCPFlags uint8
type TCPHeader ¶
type TCPHeader struct {
SrcPort uint16
DstPort uint16
SeqNum uint32
AckNum uint32
DataOffset uint8 // 4 bits, part of uint8
Reserved uint8 // 4 bits of 0's, part of uint8
Flags TCPFlags
Window uint16
Checksum uint16
Urgent uint16
Options []byte
Payload []byte
}
TCPHeader size is between 20 and 60 bytes https://en.wikipedia.org/wiki/Transmission_Control_Protocol
func NewTCPHeader ¶
NewTCPHeader converts a byte array into a TCP header