Skip to content

Commit 45de3db

Browse files
authored
Fix #4547: Change hashret of DoIP (#4586)
* Fix #4547: Change hashret of DoIP * debug * update timeout
1 parent 680107d commit 45de3db

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

scapy/contrib/automotive/doip.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,7 @@ def answers(self, other):
239239

240240
def hashret(self):
241241
# type: () -> bytes
242-
if self.payload_type in [0x8001, 0x8002, 0x8003]:
243-
return bytes(self)[:2] + struct.pack(
244-
"H", self.target_address ^ self.source_address)
245-
return bytes(self)[:2]
242+
return bytes(self)[:3]
246243

247244
def post_build(self, pkt, pay):
248245
# type: (bytes, bytes) -> bytes

test/contrib/automotive/doip.uts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
= Load Contrib Layer
1212

13+
from test.testsocket import TestSocket, cleanup_testsockets, UnstableSocket
14+
1315
load_contrib("automotive.doip", globals_dict=globals())
1416
load_contrib("automotive.uds", globals_dict=globals())
1517

@@ -406,6 +408,30 @@ assert pkts[0][DoIP].payload_length == 2
406408
assert pkts[0][DoIP:2].payload_length == 7
407409
assert pkts[1][DoIP].payload_length == 103
408410

411+
= Doip logical addressing
412+
413+
filename = scapy_path("/test/pcaps/doip_functional_request.pcap.gz")
414+
tx_sock = TestSocket(DoIP)
415+
rx_sock = TestSocket(DoIP)
416+
tx_sock.pair(rx_sock)
417+
418+
for pkt in PcapReader(filename):
419+
if pkt.haslayer(DoIP):
420+
tx_sock.send(pkt[DoIP])
421+
422+
ans, unans = rx_sock.sr(DoIP(bytes(DoIP(payload_type=0x8001, source_address=0xe80, target_address=0xe400) / UDS() / UDS_TP())), multi=True, timeout=0.1, verbose=False)
423+
424+
cleanup_testsockets()
425+
426+
ans.summary()
427+
if unans:
428+
unans.summary()
429+
430+
assert len(ans) == 8
431+
ans.summary()
432+
assert len(unans) == 0
433+
434+
409435
+ DoIP Communication tests
410436

411437
= Load libraries
818 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)