環(huán)境:
版本:銀河麒麟桌面操作系統(tǒng)V10(SP1)
內(nèi)核:Linux 5.4.18-35-generic
CPU:Phytium,D2000/8
終端輸入 uname -m 查看
架構(gòu) aarch64
在windows 上 和 銀河麒麟(linux loongarch64) 使用下面的代碼獲取IP地址:
銀河麒麟(linux) gethostname 獲取不到IP地址_程序媛zcx的博客-CSDN博客_銀河麒麟查看ip地址
同樣的代碼 在銀河麒麟(linux 架構(gòu)loongarch64)可以,但是在 銀河麒麟(aarch64)上不可以,于是用讀文件的方式獲取所有ip地址列表,代碼如下:
std::vector<std::string> WHUDP:: getIpList() {
std::vector<std::string> result;
char buff[BUFSIZ];
int i=0,k=0;
char tmpbuff[1];
int ret=0;
FILE * addrFile;
addrFile = popen("ifconfig", "r");
memset(buff,0,BUFSIZ);
while(1) {
ret = fread(tmpbuff, 1, 1, addrFile);
if(ret)
{
buff[i]=tmpbuff[0];
i++;
if(buff[i - 1]=='\n')
{
string str = buff;
string::size_type idx = str.find("inet ");
// cout<< "buff111111== " << buff << " idx== " << to_string(idx) << endl;
if(idx == string::npos) {
} else {
// cout<< "buff222== " << buff << endl;
// stringstream strsplite(str);
// char c = ' ';
// vector<string> resArr;
// string ss1;
// while(getline(strsplite, ss1, c)) {
// cout<< "ss1=== " << ss1 << endl;
// resArr.push_back(ss1);
// }
// string ipstr = resArr[9];
// cout<< " ipstr11=== " << ipstr << endl;
// result.push_back(ipstr);
int start = idx+5;
for(k=start;k< strlen(buff);k++)
{
if(buff[k]==' ')
{
// cout<< "===========" << to_string(k-(start)) << endl;
string ipstr=str.substr(start,k-(start));
// cout<< " ipstr11===" << ipstr << endl;
result.push_back(ipstr);
k=0;
i=0;
memset(buff,0,BUFSIZ);
break;
}
}
}
k=0;
i=0;
memset(buff,0,BUFSIZ);
}
}
else
{
break;
}
}
fclose(addrFile);
return result;
}
文章來源:http://www.zghlxwxcb.cn/news/detail-515519.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-515519.html
到了這里,關(guān)于銀河麒麟(linux 架構(gòu)aarch64) 獲取本機(jī)所有IP地址的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!