|
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. |
Answered by
wiresock
Aug 15, 2024
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; |
1 reply
Answer selected by
cavivie
|
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. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assuming that
packetis a pointer to a raw IPv4 packet andlengthrepresents its size, the following code snippet accomplishes the task: