'Function to retrieve the header destination address from a packet in windows XP

I am interested in retrieving the destination address that an inbound packet is sent to. For example on Linux you can utilize recvmsg:

res = recvmsg(socket, &msghdr, 0);
get_cmsg = CMSG_FIRSTHDR(msghdr);   
struct in_pktinfo *get_pktinfo = (struct in_pktinfo *)CMSG_DATA(get_cmsg);
printf(" - Header destination address (get_pktinfo.ipi_addr)=%s\n", inet_ntoa(pktinfo.ipi_addr));

Steps have been skipped to save many many lines

The key here is that recvmsg is easy to use. Similar functions are implemented for Windows XP like recvfrom but Windows does not seem to implement the recvmsg function.

Similarly named functions exist, like the WSARevcMsg function, but according to the linked documentation it is only included in Windows Vista and above.

Is there a way I can get the header destination address from a packet in Windows XP?


I know that using XP is bad and old, unfortunately we are attempting to fix a bug on a legacy product, so at this time we are unable to simply upgrade.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source