def read(self, fmt): st = struct.Struct(fmt) if self.offset + st.size > self.length: raise lowpan.ProtocolError("Buffer too short") result = st.unpack_from(self.buf, self.start+self.offset) self.offset += st.size return result
def slice(self, length, rewind=0): if self.offset + length - rewind > self.length: raise lowpan.ProtocolError("Buffer too short") reader = BufReader(self.buf, self.start + self.offset - rewind, length) reader.skip(rewind) self.offset += length - rewind return reader
def skip_align(self): new_offset = (self.offset + 7) / 8 * 8 if new_offset > self.length: raise lowpan.ProtocolError("Buffer too short") self.offset = new_offset
def skip(self, length): if self.offset + length > self.length: raise lowpan.ProtocolError("Buffer too short") self.offset += length
def parse_pkt(buf): if len(buf) < 64: raise lowpan.ProtocolError("too short to be an l2 ethernet packet") return PACKET.unpack(lowpan.util.BufReader(buf))
def parse_802_15_4_header(buf): if len(buf) < 8: raise lowpan.ProtocolError("too short to be an 802.15.4 packet") data = IEEE_802_15_4_DATA.unpack(lowpan.util.BufReader(buf)) return data.mhr_len, (len(buf) - 2), data.pattern
def parse_header(buf): if len(buf) < 8: raise lowpan.ProtocolError("too short to be an 802.15.4 packet") l_sniffer = NXP_802_15_4_Sniffer.unpack(lowpan.util.BufReader(buf)) return l_sniffer.hdr_len, l_sniffer.len, l_sniffer.subtype, l_sniffer