On Tuesday, April 21, 2020 at 6:08:22 PM UTC+2, Rakesh K R wrote:
>
> Hi,
> I am new to Go and I am trying to parse the network packets received.
> In C, we used to typecast this array of uint8_t to predefined structure. 
> Is there a way I can do this similarly in Go? or any better approach to do 
> this in Go?
> i.e. I need to parse the packet to store them to respective l2/l3/l4 and 
> mdns header structures
>

See https://github.com/golang/net/blob/master/ipv4/header.go#L109 for an 
example.

Note that https://golang.org/pkg/encoding/binary/ only support big endian 
and little endian, but not native endian.
This blog post may be useful:
https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html

If you need to support bad written protocols using native endian, see 
https://github.com/golang/net/blob/master/internal/socket/sys.go.

Manlio

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/07cf681a-3ed9-4f3d-bb34-64529ae07869%40googlegroups.com.

Reply via email to