MCPcopy
hub / github.com/evilsocket/opensnitch / deserialize

Method deserialize

daemon/netlink/socket_packet.go:79–112  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

77}
78
79func (pm *PacketDiagMsg) deserialize(b []byte) error {
80 rb := readBuffer{Bytes: b}
81
82 // 1st message: PacketDiagMsg
83 pm.Family = rb.Read()
84 pm.Type = rb.Read()
85 pm.Num = native.Uint16(rb.Next(2))
86 pm.Inode = native.Uint32(rb.Next(4))
87 pm.Cookie[0] = native.Uint32(rb.Next(4))
88 pm.Cookie[1] = native.Uint32(rb.Next(4))
89
90 nextMsg := rb.Read() // next msg size
91 if nextMsg == sizePktDiagMclist {
92 pm.Mclist = PacketDiagMclist{
93 // XXX: wrong values with native.Uint32()
94 Index: binary.BigEndian.Uint32(rb.Next(4)),
95 Count: binary.BigEndian.Uint32(rb.Next(4)),
96 Type: binary.BigEndian.Uint16(rb.Next(2)),
97 Alen: binary.BigEndian.Uint16(rb.Next(2)),
98 }
99 copy(pm.Mclist.Addr[:], rb.Next(16))
100 }
101
102 // {nla_len=8, nla_type=PACKET_DIAG_UID}, 1000}
103 nextMsg = rb.Read() // 8, size of next msg
104 nextMsg = rb.Read() // pad?
105 if nextMsg == PACKET_DIAG_UID {
106 rb.Read() // pad?
107 pm.UID = native.Uint32(rb.Next(4))
108 }
109 log.Trace("PktDiagMsg.deserialize (size: %d, sizeOf(PacketDiagMsg): %d): %+v", len(b), unsafe.Sizeof(b), pm)
110
111 return nil
112}
113
114// PacketDiagReq struct to request data from the kernel
115// https://github.com/torvalds/linux/blob/master/include/uapi/linux/packet_diag.h#L7

Callers 1

SocketDiagPacketFunction · 0.95

Calls 2

ReadMethod · 0.95
NextMethod · 0.95

Tested by

no test coverage detected