-
I'm currently working on a project where I need to reconstruct the original immediate buffer from pure IP data packets. However, I'm encountering difficulties in understanding the correct procedure or methodology to achieve this. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Assuming that memset(buffer.get(), 0, offsetof(INTERMEDIATE_BUFFER, m_IBuffer));
memmove(&buffer->m_IBuffer[ETHER_HEADER_LENGTH], packet, length);
auto* const eth_header = reinterpret_cast<ether_header_ptr>(buffer->m_IBuffer);
memmove(eth_header->h_source, source_mac, ETH_ALEN);
memmove(eth_header->h_dest, dest_mac, ETH_ALEN);
eth_header->h_proto = ETH_P_IP_NET;
buffer->m_Length = gsl::narrow_cast<uint32_t>(length) + ETHER_HEADER_LENGTH; |
Beta Was this translation helpful? Give feedback.
-
There are several methods to obtain a MAC address. You can use ARP to retrieve it, extract and store it from the original network packet, or send a similar packet through Winsock, intercept it on NDIS level, and extract the destination MAC address. |
Beta Was this translation helpful? Give feedback.
Assuming that
packet
is a pointer to a raw IPv4 packet andlength
represents its size, the following code snippet accomplishes the task: