Exemplo n.º 1
0
 def decode(self):
     # Decode the data
     nla.decode(self)
     # Extract the encap mode
     self['mode'] = (self.r_encapmodes.get(self['encapmode'],
                                           "encap"))
     # Calculate offset of the segs
     offset = self.offset + 16
     # Point the addresses
     addresses = self.data[offset:]
     # Extract the number of segs
     n_segs = self['segments_left'] + 1
     # Init segs
     segs = []
     # Move 128 bit in each step
     for i in range(n_segs):
         # Save the segment
         segs.append(
             inet_ntop(AF_INET6, addresses[i * 16:i * 16 + 16]))
     # Save segs
     self['segs'] = segs
     # Init tlvs
     self['tlvs'] = ''
     # If hmac is used
     if self.has_hmac():
         # Point to the start of hmac
         hmac = addresses[n_segs * 16:n_segs * 16 + 40]
         # Save tlvs section
         self['tlvs'] = hexdump(hmac)
         # Show also the hmac key
         self['hmac'] = hexdump(hmac[4:8])
Exemplo n.º 2
0
 def decode(self):
     nla_string.decode(self)
     family = struct.unpack('H', self['value'][:2])[0]
     addr = self['value'][2:]
     if addr:
         if (family == AF_INET and len(addr) == 4) or \
                 (family == AF_INET6 and len(addr) == 16):
             addr = inet_ntop(family, addr)
         else:
             addr = hexdump(addr)
     self.value = {'family': family, 'addr': addr}
Exemplo n.º 3
0
 def decode(self):
     rt_slot.decode(self)
     length = self['header']['length']
     self['value'] = hexdump(self.data[self.offset + 2:self.offset +
                                       length])