scroot / gopacket

Automatically exported from code.google.com/p/gopacket
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

newPortEndpoint does not convert uint16 to []byte correctly #39

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. ep = NewTCPPortEndpoint(layers.TCPPort(1010))
2. fmt.Println(hex.Dump(ep.Raw))

What is the expected output? What do you see instead?
expect 0x0a 0x0a 0x00....
see  0x00 0x0a 0x00...

What version of the product are you using? On what operating system?
git put from head on 9/23/14. On Ubuntu 12.04 / linux 3.8

Please provide any additional information below.

suggest this patch :

diff --git a/layers/endpoints.go b/layers/endpoints.go
index 03793a8..193eef1 100644
--- a/layers/endpoints.go
+++ b/layers/endpoints.go
@@ -64,7 +64,7 @@ func NewMACEndpoint(a net.HardwareAddr) gopacket.Endpoint {
        return gopacket.NewEndpoint(EndpointMAC, []byte(a))
 }
 func newPortEndpoint(t gopacket.EndpointType, p uint16) gopacket.Endpoint {
-       return gopacket.NewEndpoint(t, []byte{byte(p >> 16), byte(p)})
+       return gopacket.NewEndpoint(t, []byte{byte(p >> 8), byte(p)})
 }

 // NewTCPPortEndpoint returns an endpoint based on a TCP port.

Original issue reported on code.google.com by ricky.ch...@gmail.com on 23 Sep 2014 at 11:53

GoogleCodeExporter commented 9 years ago
Sorry I missed this report, fixed and rolling out to master now.

Original comment by gconnell@google.com on 14 Oct 2014 at 3:02