Reputation: 111
I receive a UDP packet using recvmsg(2). I would like to know if it is from the local machine or not.
I can use IP_PKTINFO with recvmsg to get the interface the packet was received on. When the packet was sent to a loopback address this is the loopback interface, which is great. When the packet was sent to an address of some other network interface, it comes back as that interface whether the packet was locally generated or not, which is not so great.
I can check if the source address of the packet is an address of the local machine, but if reverse path filtering is disabled then it could have that address and still be from another machine, and I can't assume that it isn't. Also, this would be a race between when I receive the packet and when I check what the local addresses are.
The system is Linux. C or C++. The process doing this has CAP_NET_ADMIN. How do I determine if the received packet is from the local machine or not?
Upvotes: 1
Views: 499