"I've used IP_PKTINFO for this. There is also an IP6_PKTINFO which I have not personally used, but looks similar. You set IP_PKTINFO in the flags passed to recvmsg. The control block will contain an ip_pktinfo structure indicating the ingress interface. This is from memory, but some searching should turn up more specific information."
- DGentry