예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
 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
예제 #4
0
 def skip(self, length):
     if self.offset + length > self.length:
         raise lowpan.ProtocolError("Buffer too short")
     self.offset += length
예제 #5
0
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))
예제 #6
0
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
예제 #7
0
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