示例#1
0
 def encode(self):
     data = struct.pack('!HHBBH', self.hw_type, self.proto_type, self.hw_size, self.proto_size, self.opcode)
     data += struct.pack('!IH', *encode_mac(self.sender_mac))
     data += struct.pack('!I', self.sender_ip)
     data += struct.pack('!IH', *encode_mac(self.target_mac))
     data += struct.pack('!I', self.target_ip)
     return data
示例#2
0
 def encode(self):
     data = struct.pack('!IH', *encode_mac(self.destination))
     data += struct.pack('!IH', *encode_mac(self.source))
     data += struct.pack('!H', self.protocol)
     data += self.payload
     if len(data) < 60: # add trailer if packet to short
         data += '\0' * (60 - len(data))
     return data