A mapping technique allows a forwarding engine of an intermediate node to efficiently
compute a starting address within an internal packet memory (IPM) configured to
hold a packet received at the node. The starting address is used by direct memory
access logic to merge a trailer of the packet stored in the IPM with a modified
packet header generated by the forwarding engine. However, the size of the IPM
is preferably not a binary number that can be easily manipulated by the forwarding
engine when computing the starting address of the packet within the IPM. Therefore,
the technique automatically adjusts the starting address to map to a correct location
if the address exceeds the size of the IPM, while obviating the need for the forwarding
engine to consider a wrap-around condition when computing the starting address.