Abhishek Sagar Abhishek Sagar - 5 months ago 10
Linux Question

Ancillary data : ‘IP_RECVIF’ undeclared (first use in this function)

i want to receive the ifindex of the interface on which the data is arrived. I am using the ancillary data for this purpose.
When i compile my program, i get

src/igmp_pkt_reciever.c:49:21: error: ‘IP_RECVIF’ undeclared (first use in this function)


As explained here , the constant should be defined in
sys/socket.h
. I have included this header file, yet i am seeing the compilation error. Can anyone please help.

Answer

IP_RECVIF is not a Linux socket option; the documentation you linked to is Oracle's Solaris documentation. From Linux socket(7)

Some other BSD sockets implementations provide IP_RCVDSTADDR and IP_RECVIF socket options to get the destination address and the interface of received datagrams. Linux has the more general IP_PKTINFO for the same task.

So you need to use IP_PKTINFO instead. The above web page provides the details of how to use it.