Can't obtain local IP using gethostbyname()

前端 未结 2 1787
终归单人心
终归单人心 2021-01-22 06:22

A friend used the following snippet of code to retrieve the local IP address of the host in his LAN.

int buffersize = 512;
char name[buffersize];

if(gethostname         


        
2条回答
  •  礼貌的吻别
    2021-01-22 06:51

    If you really use Qt, you can use this code

    foreach (const QHostAddress& address, QNetworkInterface::allAddresses() ) {
            qDebug() << address.toString();
        }
    

    If you are not using Qt, you can study, how it is made there.

提交回复
热议问题