質問

I have some code that works with my local IP but when I try to listen a non-local IP (from the same network) this code doesn't works. Apparently, my "select" clause is not working any more.

    while(IsReading() && IsConnected())
    {
            FD_ZERO(&lReader);
            FD_SET(GetConnection(), &lReader);

            int lHasData = select(GetConnection()+1, &lReader, NULL, NULL, NULL);

            if (lHasData > 0)
            {
                    //Accept and read socket...
            }
    }

As I said, that's working perfectly for my own Ip but when I try to listen other IP/Port from my newtwork (It's Asterisk server, I want to listen it to recive the responses for my actions and calls), the "select" is staying like if no data arrives.

Is something wrong in my code for non-local IP?

Thanks for advance

役に立ちましたか?

解決

Generally it's not possible. By design, packets targeted to an IP are routed only to the machine with that IP. Just because you have started listening on that IP will not make routers magically change their mind and start sending someone else's packet to your machine.

Sometimes it may be possible, for example, when your and the other machine are connected through dumb hub that retranslates everyone's transmissions to everyone, and your interface is put into promiscuous mode (i.e. it is configured not to throw away packets targeted to non-local IPs). If this is what you're trying to achieve, you need to make sure both machines are connected to the hub, not to a switch, and consult your OS documentation about how to switch a network interface to promiscuous mode.

他のヒント

You can't 'listen [to] a non-local IP',whether 'from the same network' or not. A socket can only be bound to a local address. You must have ignored some previous error. Or else your question has been badly phrased.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top