Skip to content

Commit

Permalink
net/linklayer: Implement loop back to own IP address
Browse files Browse the repository at this point in the history
IP packets, sent to the own IP address, will be looped back
to the receiver.

Issue #488
  • Loading branch information
rsta2 committed Oct 15, 2024
1 parent 30fd33a commit ab4fc91
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/net/linklayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 ()
Expand Down

0 comments on commit ab4fc91

Please sign in to comment.