Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

Tcp header length calculation may be wrong #3

Closed
0xn0ne opened this issue Dec 26, 2018 · 2 comments
Closed

Tcp header length calculation may be wrong #3

0xn0ne opened this issue Dec 26, 2018 · 2 comments
Assignees

Comments

@0xn0ne
Copy link

0xn0ne commented Dec 26, 2018

When I was using binding. I got this

goroutine 20 [running]:
github.com/williamfhe/godivert/header.NewTCPHeader(...)
        C:/Users/Blueshark-JF/go/src/github.com/williamfhe/godivert/header/tcp.go:16
github.com/williamfhe/godivert.(*Packet).ParseHeaders(0xc000099b60)
        C:/Users/Blueshark-JF/go/src/github.com/williamfhe/godivert/packet.go:42 +0x5a2
github.com/williamfhe/godivert.(*Packet).VerifyParsed(0xc000099b60)
        C:/Users/Blueshark-JF/go/src/github.com/williamfhe/godivert/packet.go:187 +0x47
github.com/williamfhe/godivert.(*Packet).DstIP(0xc000099b60, 0x2, 0x2, 0x7)
        C:/Users/Blueshark-JF/go/src/github.com/williamfhe/godivert/packet.go:102 +0x32
main.checkPacket(0xc000052610, 0xc0000980c0)
        C:/Users/Blueshark-JF/go/src/vtap/old2.go:75 +0x25f
created by main.NewProxy
        C:/Users/Blueshark-JF/go/src/vtap/old2.go:319 +0xff
exit status 2

I found out when I was following the mistake, in github.com\williamfhe\godivert\header

func NewTCPHeader(raw []byte) *TCPHeader {
	hdrLen := raw[12] >> 2
	return &TCPHeader{
		Raw: raw[:hdrLen],
	}
}

I think maybe the following code will be more accurate

(packet.Raw[ipHeaderLenght+12]&0xF>>4) * 5
@williamfhe williamfhe self-assigned this Dec 28, 2018
@williamfhe
Copy link
Owner

You were right, the calculation was wrong.
It's been fixed with commit 2ec00c2

@0xn0ne
Copy link
Author

0xn0ne commented Dec 30, 2018

Ooh, finally updated, works well on my code. I like this binding very much. QwQ

@0xn0ne 0xn0ne closed this as completed Dec 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants