[Interest] QNetworkInterface working differently on Qt5?

Tom Isaacson Tom.Isaacson at navico.com
Wed Dec 2 09:09:26 CET 2015


>Can you show me your code?
    // loop through and find the network interface that matches the mac we used...
    QList<QNetworkInterface> ifList = QNetworkInterface::allInterfaces();
    for (QList<QNetworkInterface>::const_iterator i = ifList.constBegin(); i != ifList.constEnd(); ++i)
    {
        if(i->hardwareAddress() == mac)
        {
            QList<QNetworkAddressEntry> addresses = i->addressEntries();

            for (QList<QNetworkAddressEntry>::const_iterator j = addresses.constBegin(); j != addresses.constEnd(); ++j)
            {
                // check IP address here
            }
        }
    }

>ifconfig has been deprecated for 10 years. Please show me the output of ip addr
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0e:c2:26:82:76 brd ff:ff:ff:ff:ff:ff
    inet 169.254.142.146/16 brd 169.254.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 192.168.0.11/16 brd 192.168.255.255 scope global eth0:dhcp
       valid_lft forever preferred_lft forever






More information about the Interest mailing list