From ab4fc91d450931c1839597e59b5a1f0c5714fa54 Mon Sep 17 00:00:00 2001 From: Rene Stange Date: Tue, 15 Oct 2024 12:21:29 +0200 Subject: [PATCH] net/linklayer: Implement loop back to own IP address IP packets, sent to the own IP address, will be looped back to the receiver. Issue #488 --- lib/net/linklayer.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/net/linklayer.cpp b/lib/net/linklayer.cpp index d7f49c6e0..455cbf158 100644 --- a/lib/net/linklayer.cpp +++ b/lib/net/linklayer.cpp @@ -132,6 +132,17 @@ boolean CLinkLayer::Send (const CIPAddress &rReceiver, const void *pIPPacket, un return FALSE; } + assert (pIPPacket != 0); + assert (nLength > 0); + assert (m_pNetConfig != 0); + if ( !rReceiver.IsNull () + && rReceiver == *m_pNetConfig->GetIPAddress ()) + { + m_IPRxQueue.Enqueue (pIPPacket, nLength); // loop back to own address + + return TRUE; + } + u8 FrameBuffer[nFrameLength]; TEthernetHeader *pHeader = (TEthernetHeader *) FrameBuffer; @@ -142,11 +153,8 @@ boolean CLinkLayer::Send (const CIPAddress &rReceiver, const void *pIPPacket, un pHeader->nProtocolType = BE (ETH_PROT_IP); - assert (pIPPacket != 0); - assert (nLength > 0); memcpy (FrameBuffer+sizeof (TEthernetHeader), pIPPacket, nLength); - assert (m_pNetConfig != 0); assert (m_pARPHandler != 0); CMACAddress MACAddressReceiver; if ( rReceiver.IsBroadcast ()