This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Can NDK bind to multiple IP addresses on a single interface?

Other Parts Discussed in Thread: SYSBIOS

Hi,

I'm trying to build a SYSBIOS 6+NDK 2.20 application which will replace 3 existing boards.  Ideally I would like to have a "drop in" replacement that can pretend to be all three.  Say they have IP addresses 192.168.5.16, 192.168.5.17, 192.168.5.18 - I'd like to be able to listen on all three addresses using the same physical interface, and bind separate sockets to listen on each.

In principle, the NDK seems to support having multiple addresses per interface.  In practice, it regards them as duplicate if they have the same subnet modulo the subnet mask, except for PPP interfaces.  The relevant test is in bind.c:

    // Search for duplicate bindings
    if( (pbtmp = (BIND *)BindFindByHost(0, IPHost) ) ||
        ((IPNet!=0xffffffff) && (pbtmp = (BIND *)BindFindByNet(0, IPNet))) )
    {
        // Duplicate bindings allowed on PPP links
        if( type != HTYPE_PPP && IFGetType(pbtmp->hIF) != HTYPE_PPP )
        {
            DbgPrintf(DBG_WARN,"BindNew: Duplicate bindings ignored");
            return(0);
        }
    }

I realise there is a potential routing ambiguity if the subnet is the same, but Windows is quite happy to bind to 3 addresses in this way so I had hoped there would be a way to do it.  I do need the packets outbound from the device to appear to come from the address matching the socket, but I would have thought binding the socket to the address would do that.

Is there any way to do what I'm after?  Or do I need to change the client code, which I'd prefer to avoid?

Thanks in advance,

Gordon

  • Hi Gordon,

    Have you looked at the NAT module with the NDK?

    Todd

  • Todd,

    Perhaps you could explain what you had in mind?  As far as I can see, NAT would let me have 3 physical DSPs and pretend to the outside world that there was one, whereas what I want to do is have one physical DSP and pretend to the outside world that I have 3 IP addresses on the same subnet.

    My current work around is to bind IP addresses on different subnets (192.168.5.16, 192.168.6.16, 192.168.7.16) which seems to work.  I then need to configure the client PCs to be able to address that range and change the IP addresses in the client apps, but it's still easier than modifying the clients to ask for distinct ports.  It's not a "drop in" replacement, though.

    Gordon

  • Hi Gordon,

    Sorry, I misunderstood the question.

    The cleanest solution, which unfortunately does not sound like an option, is to simply use different ports.

    Your work-around should work.

    Todd