I suppose some of my friends are not yet convinced with my question's legitimacy. Here is one more attempt.
Linux kernel (Or any OS) do not require user to know the outgoing interface leading to destination machine. All he needs to know the destination ip address to send the pkt to. OS take care to route the packet and egress out of the correct OIF. Agreed.
In the industry, we dont use kernel/OS for real traffic routing. There is hardware (ASICs) which has abilities to forward the traffic with much great speeds which is not feasible by software based forwarding.
Now, In hardware when pkt arrives, all it knows the following rule :
if Src_addr = x, dest_addr = y, then send out the pkt out of ethz
. It do not do ARP resolve Or lookup some routing table etc to decide which interface the pkt is supposed to forward to, like kernel.
Now, eventually, your application needs to install such rules in hardware, hence, it needs to know the triplet to install in hardware. Here, intf is calculated by processing the control pkts arrived on the interface. Read PIM, you will see everywhere is maintain the (,G) database which says, if pkt arrives for any source (), for multicast group G, then egress out the packet to 'n' local interfaces and not 'n' ip-addresses (receivers).
Coming to the Answer
I am able to receive ingress interface information in my application along with the packet. More precisely saying, Ancillary Data is the solution here.
copy paste my own answer here from a different related Question:
For Unix Domain sockets, Ancillary data is used to send Or receive file descriptors between processes to share or load balance the tasks. Note : Unix Domain sockets transfer the information between processes running on same machine and not between processes running on different machines.
Ancillary data is used to receive the EXTRA packet related services/information from the kernel to user space application, which is not available otherwise. For example, say machine B receives some packet on wire and you want to know the ingress interface the packet arrived from ? How would you know this ? Ancillary Data come to the rescue.
Ancillary data are kind of flags set in ancillary control buffer and passed to kernel when sendmsg()/recvmsg() is called, which tells the kernel that when packet is send or arrive, what extra services/information is to be provided to application invoking the calls.
Ancillary Data is the means Communication between kernel and user space application Or between processes on same machine in case of UNIX sockets. It is not something the packet on wire has.