Take the 2-minute tour ×  In C I bind a datagram socket
(AF_INET, SOCK_DGRAM) to INADDR_ANY. I then periodically use
this socket to send and receive datagrams, and monitor the flow
of packets with pcap. The problem is, I can't tell whether a
packet is incoming or outgoing using pcap.  The
transmission/receiving and the pcap monitoring are running in
separate threads, and for synchronisation reasons they can't
communicate. I only want to track the incoming packets, not the
ones being sent, so does anyone have an idea as to how I can do
that?  I thought already of testing the destination ip address,
but I can't figure out any way to get my local ip. the machine
this is running on doesn't have a static ip, much less an
assigned domain name, and it seems that getsockname doesn't work
on sockets bound to INADDR_ANY. Also tried using ioctl(sockfd,
SIOCGIFCONF, &buffer), which didn't work either - sets
buffer.ifc_len=0.  share|improve this question Also, the
function pcap_setdirection returns success but has no effe