2323# scapy.contrib.description = KNX Protocol
2424# scapy.contrib.status = loads
2525
26+ import struct
2627from scapy .fields import PacketField , MultipleTypeField , ByteField , XByteField , \
2728 ShortEnumField , ShortField , \
2829 ByteEnumField , IPField , StrFixedLenField , MACField , XBitField , \
@@ -204,7 +205,7 @@ class HPAI(Packet):
204205 ]
205206
206207 def post_build (self , p , pay ):
207- p = ( len (p )). to_bytes ( 1 , byteorder = 'big' ) + p [1 :]
208+ p = struct . pack ( "!B" , len (p )) + p [1 :]
208209 return p + pay
209210
210211
@@ -236,7 +237,7 @@ class DIBDeviceInfo(Packet):
236237 ]
237238
238239 def post_build (self , p , pay ):
239- p = ( len (p )). to_bytes ( 1 , byteorder = 'big' ) + p [1 :]
240+ p = struct . pack ( "!B" , len (p )) + p [1 :]
240241 return p + pay
241242
242243
@@ -253,7 +254,7 @@ class DIBSuppSvcFamilies(Packet):
253254 ]
254255
255256 def post_build (self , p , pay ):
256- p = ( len (p )). to_bytes ( 1 , byteorder = 'big' ) + p [1 :]
257+ p = struct . pack ( "!B" , len (p )) + p [1 :]
257258 return p + pay
258259
259260
@@ -285,7 +286,7 @@ class CRI(Packet):
285286 ]
286287
287288 def post_build (self , p , pay ):
288- p = ( len (p )). to_bytes ( 1 , byteorder = 'big' ) + p [1 :]
289+ p = struct . pack ( "!B" , len (p )) + p [1 :]
289290 return p + pay
290291
291292
@@ -300,7 +301,7 @@ class CRD(Packet):
300301 ]
301302
302303 def post_build (self , p , pay ):
303- p = ( len (p )). to_bytes ( 1 , byteorder = 'big' ) + p [1 :]
304+ p = struct . pack ( "!B" , len (p )) + p [1 :]
304305 return p + pay
305306
306307
@@ -513,7 +514,7 @@ class KNXConfigurationRequest(Packet):
513514 ]
514515
515516 def post_build (self , p , pay ):
516- p = ( len (p [:4 ])). to_bytes ( 1 , byteorder = 'big' ) + p [1 :]
517+ p = struct . pack ( "!B" , len (p [:4 ])) + p [1 :]
517518 return p + pay
518519
519520
@@ -528,7 +529,7 @@ class KNXConfigurationACK(Packet):
528529 ]
529530
530531 def post_build (self , p , pay ):
531- p = ( len (p )). to_bytes ( 1 , byteorder = 'big' ) + p [1 :]
532+ p = struct . pack ( "!B" , len (p )) + p [1 :]
532533 return p + pay
533534
534535
@@ -544,7 +545,7 @@ class KNXTunnelingRequest(Packet):
544545 ]
545546
546547 def post_build (self , p , pay ):
547- p = ( len (p [:4 ])). to_bytes ( 1 , byteorder = 'big' ) + p [1 :]
548+ p = struct . pack ( "!B" , len (p [:4 ])) + p [1 :]
548549 return p + pay
549550
550551
@@ -559,7 +560,7 @@ class KNXTunnelingACK(Packet):
559560 ]
560561
561562 def post_build (self , p , pay ):
562- p = ( len (p )). to_bytes ( 1 , byteorder = 'big' ) + p [1 :]
563+ p = struct . pack ( "!B" , len (p )) + p [1 :]
563564 return p + pay
564565
565566
@@ -570,7 +571,7 @@ class KNXRoutingIndication(Packet):
570571 ]
571572
572573 def post_build (self , p , pay ):
573- p = ( len (p [:4 ])). to_bytes ( 1 , byteorder = 'big' ) + p [1 :]
574+ p = struct . pack ( "!B" , len (p [:4 ])) + p [1 :]
574575 return p + pay
575576
576577
@@ -591,9 +592,9 @@ class KNX(Packet):
591592
592593 def post_build (self , p , pay ):
593594 # computes header_length
594- p = ( len (p )). to_bytes ( 1 , byteorder = 'big' ) + p [1 :]
595+ p = struct . pack ( "!B" , len (p )) + p [1 :]
595596 # computes total_length
596- p = p [:- 2 ] + ( len (p ) + len (pay )). to_bytes ( 2 , byteorder = 'big' )
597+ p = p [:- 2 ] + struct . pack ( "!H" , len (p ) + len (pay ))
597598 return p + pay
598599
599600
0 commit comments