当前位置: 技术问答>linux和unix
UNIX下哪个函数/系统调用(不要命令)可以取得本地IP地址?
来源: 互联网 发布时间:2015-10-09
本文导语: 如题 | char buffer[32]={''}; struct hostent* host; memset(buffer, 0, 32); gethostname(buffer, 32); host=gethostbyname(buffer); if(host->h_addr) sprintf(buffer,"%s",inet_ntoa(*((struct in_addr*)host->h_addr))); | gethost...
如题
|
char buffer[32]={''};
struct hostent* host;
memset(buffer, 0, 32);
gethostname(buffer, 32);
host=gethostbyname(buffer);
if(host->h_addr)
sprintf(buffer,"%s",inet_ntoa(*((struct in_addr*)host->h_addr)));
struct hostent* host;
memset(buffer, 0, 32);
gethostname(buffer, 32);
host=gethostbyname(buffer);
if(host->h_addr)
sprintf(buffer,"%s",inet_ntoa(*((struct in_addr*)host->h_addr)));
|
gethostbyname
|
ioctl()