I'm working with Linux(Debian) and C.
I have opened a socket to the interfaces - eth0 and eth1 with the following function:
// Opening the socket
mSocket = socket(device->ifa_addr->sa_family, SOCK_RAW | SOCK_NONBLOCK,
htons(ETH_P_ALL));
if (mSocket == -1)
{
throw CException("socket is bad");
}
// Adding flag to the socket to work only on a specific interface
if (setsockopt(mSocket, SOL_SOCKET, SO_BINDTODEVICE,
(void *) &mIfreq, sizeof(mIfreq)) < 0)
{
throw CException(
"Failed to add binding to specific interface flag");
}
while ifreq holds the interface name:
strncpy(mIfreq.ifr_ifrn.ifrn_name,device->ifa_name, IF_NAMESIZE);
The next thing I do is receiving packets using the following code:
recvSize = recvfrom(mSocket, buffer, ETH_FRAME_LEN, 0, NULL,
NULL);
questions:
1) why if both interfaces aren't connected to anything non of the sockets can be opened
2*) why (WLOG) if eth0 is connected and eth1 isn't I can open sockets to each of them
2.1*) why by reading from eth1 socket I get all packets received in eth0
(wireshark on eth1 isn't showing any packet as it should be)
[my guess - is it linux fault?(doing stuff behind my back?)]
Thanks in advance,
Despair