Jelajahi Sumber

Comments updated for PacketGenerator.py

Comments updated for PacketGenerator.py
Marcel Juschak 7 tahun lalu
induk
melakukan
a293c1a89f
1 mengubah file dengan 12 tambahan dan 14 penghapusan
  1. 12 14
      code/ID2TLib/PacketGenerator.py

+ 12 - 14
code/ID2TLib/PacketGenerator.py

@@ -23,19 +23,18 @@ class PacketGenerator():
 	    :param mac_dst: the destination MAC address of the MAC header
 	    :param port_src: the source port of the header
 	    :param port_dst: the destination port of the header
+	    :param ttl: the ttl Value of the packet
 	    :param tcpflags: the TCP flags of the TCP header
 	    :param payload: the payload of the packet
 	    :return: the corresponding packet
 	    """
 
-	    #directly generate packet with the current protocol
 		if(self.protocol == "udp"):
 			packet = generate_udp_packet(ip_src=ip_src, ip_dst=ip_dst, mac_src=mac_src, mac_dst=mac_dst, ttl=ttl,
 				port_src=port_src, port_dst=port_dst, payload=payload)
 		elif(self.protocol == "tcp"):
 			packet = generate_tcp_packet(ip_src=ip_src, ip_dst=ip_dst, mac_src=mac_src, mac_dst=mac_dst, ttl=ttl,
 				port_src=port_src, port_dst=port_dst, tcpflags=tcpflags, payload=payload)
-		#else raise exception?
 		return packet
 		
 
@@ -51,9 +50,10 @@ class PacketGenerator():
 	    :param mac_dst: the destination MAC address of the MAC header
 	    :param port_src: the source port of the header
 	    :param port_dst: the destination port of the header
-	    :param tcpflags: the TCP flags of the TCP header
+	    :param tcpflags: the TCP flags of the TCP header, if tcp is selected as protocol
+	    :param ttl: the ttl Value of the packet
 	    :param message_type: affects the size of the payload
-	    :param neighborlist_entries: Number of entries for the payload
+	    :param neighborlist_entries: number of entries of a Neighbourlist-reply, affects the size of the payload
 	    :return: the corresponding packet
 	    """
 
@@ -69,35 +69,35 @@ class PacketGenerator():
 		else:
 			payload_len = 0
 
-		#generate payload
 		payload = PayloadGenerator.generate_payload(payload_len)
 
-		#generate the packet
 		if(self.protocol == "udp"):
 			packet = generate_udp_packet(ip_src=ip_src, ip_dst=ip_dst, mac_src=mac_src, mac_dst=mac_dst, ttl=ttl,
 				port_src=port_src, port_dst=port_dst, payload=payload)
 		elif(self.protocol == "tcp"):
 			packet = generate_tcp_packet(ip_src=ip_src, ip_dst=ip_dst, mac_src=mac_src, mac_dst=mac_dst, ttl=ttl,
 				port_src=port_src, port_dst=port_dst, tcpflags=tcpflags, payload=payload)
-		#else raise exception?
+		else:
+			print("Error: unsupported protocol for generating Packets")
+
 		return packet
 
 
 def generate_tcp_packet(ip_src:str="192.168.64.32", ip_dst:str="192.168.64.48", mac_src:str="56:6D:D9:BC:70:1C", ttl: int=64,
 					   mac_dst:str="F4:2B:95:B3:0E:1A", port_src:int=1337, port_dst:int=6442, tcpflags:str="S", payload:str=""):
 	"""
-    Builds an TCP packet with the values specified by the caller. If a parameter was not specified by the caller, 
-    it is set to a default value.
+    Builds a TCP packet with the values specified by the caller.
     
     :param ip_src: the source IP address of the IP header
     :param ip_dst the destination IP address of the IP header
     :param mac_src: the source MAC address of the MAC header
+    :param ttl: the ttl value of the packet
     :param mac_dst: the destination MAC address of the MAC header
     :param port_src: the source port of the TCP header
     :param port_dst: the destination port of the TCP header
     :param tcpflags: the TCP flags of the TCP header
     :param payload: the payload of the packet
-    :return: the corresponding IP packet
+    :return: the corresponding TCP packet
     """
 
 	ether = Ether(src=mac_src, dst=mac_dst)
@@ -110,17 +110,15 @@ def generate_tcp_packet(ip_src:str="192.168.64.32", ip_dst:str="192.168.64.48",
 def generate_udp_packet(ip_src:str="192.168.64.32", ip_dst:str="192.168.64.48", mac_src:str="56:6D:D9:BC:70:1C", ttl: int=64,
 					   mac_dst:str="F4:2B:95:B3:0E:1A", port_src:int=1337, port_dst:int=6442, payload:str=""):
 	"""
-    Builds an UDP packet with the values specified by the caller. If a parameter was not specified by the caller, 
-    it is set to a default value.
+    Builds an UDP packet with the values specified by the caller.
     
     :param ip_src: the source IP address of the IP header
     :param ip_dst the destination IP address of the IP header
     :param mac_src: the source MAC address of the MAC header
+    :param ttl: the ttl value of the packet
     :param mac_dst: the destination MAC address of the MAC header
     :param port_src: the source port of the UDP header
     :param port_dst: the destination port of the UDP header
-    :param udp_len: length of the UDP packet, 8Byte header + payload
-    :param udp_chksum: checksum of the UDP packet
     :param payload: the payload of the packet
     :return: the corresponding UDP packet
     """