문제

I use QTcpServer from the Qt-Framework with C++.

I started it with

ret = tcpServer->listen(QHostAddress::Any, 9871)

With

QHostAddress serverAddress () const

I retrieve the Address from it. Which is 0.0.0.0. In my opinion it should listen on more than one address (like 127.0.0.1 and the LAN Address).

Is there a way to retrieve more than one address from this class?

도움이 되었습니까?

해결책

I'm not sure what your question is exactly, but...

Usually, a 0.0.0.0 means that the socket listen to all interfaces that are both up and configured with a valid IPv4 address.

If you want to get all the available IP addresses on the system, you should enumerate the network interface then query their respective IPv4 address (Probably with an ioctl, specifying SIOCGIFSWADDR).

다른 팁

I agree with ereOn's answer above.

If you want to list your network interface adresses, take a look at QNetworkInterface.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top