0
votes

In the setup I'm working with I have multiple interfaces and some of them have exact same IPs. i.e: ifconfig returns

eno1: ... inet 192.168.2.1  netmask 255.255.255.0 ...
eno2: ... inet 192.168.2.1  netmask 255.255.255.0 ...

Yes, I know it's crazy but unfortunately I can not change the IPs. So when I am binding the sockets, in this specific case they are UDP sockets to receive data, I have to bind the socket to the interface with something like this:

// if interface is provided, bind to the interface
if (szIfr != 0)
{
    struct ifreq ifr;
    memset(&ifr, 0, sizeof(ifr));
    snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), szIfr);
    if (setsockopt(m_sSocket, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) < 0)
    {
        printf("OPEN(): error binding to %s. Error returned: %s\n", szIfr, strerror(errno));
        return CUDP_BIND;
    }
}

and it works perfectly. But I'm having problem with binding the socket with a virtual interface. This is my actual setup

...
eno1:   ... inet 192.168.2.1    netmask 255.255.255.0 ...
eno1:0: ... inet 10.24.6.1      netmask 255.255.255.0 ...
eno1:1: ... inet 10.8.6.4       netmask 255.255.255.0 ...
eno2:   ... inet 192.168.2.1    netmask 255.255.255.0 ...
...

So, when I try to bind to eno1:0 I get this error: No such device and it also makes sense. Because the interface is virtual and it doesn't exist. But If I try to bind to the real interface eno1 with the IP of the virtual interface I don't receive any packet on that socket. If I just bind it to the IP without specifying the name of the interface I don't get any error but I still don't receive the data.

What am I doing wrong here? Is it something to do with the interface settings or I have to modify my code?

I'm testing this code on RedHat 7.1 with kernel redhat kernel 4.1.5.

1

1 Answers

1
votes

eno1:0 is not virtual interface, it is just an alias for eno1. Binding to eno1 with IP 0.0.0.0 (INADDR_ANY) should work for the virtual interfaces aswell. A bigger problem when you have the same network address on multiple devices is the routing table, that is used to decide which interface to use when sending data