标题:linux c 通过hostname获得ip地址 出处:向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除 时间:Sat, 24 Jun 2017 12:45:32 +0000 作者:jackxiang 地址:http://jackxiang.com/post/9257/ 内容: #include #include int main() {         struct hostent *he;         char hostname[40]={0} ;         char ipaddr[40]={0};         strcpy(hostname,"www.baidu.com");                                                       gethostname(hostname,sizeof(hostname));         he = gethostbyname(hostname);         printf("%d-handle-gethostbyname\n",he);         printf("hostname=%s\n",hostname);         //printf("%s\n",inet_ntoa(*(struct in_addr*)(he->h_addr)));     char destIP[128];     char **phe = NULL;     for( phe=he->h_addr_list ; NULL != *phe ; ++phe)     {           inet_ntop(he->h_addrtype,*phe,destIP,sizeof(destIP));         printf("addr:%s\n",destIP);     }   } ./gh 529960480-handle-gethostbyname hostname=justwinit-php-mysql_bj_sjs_10_44_202_177 addr:127.0.0.1 来自:http://blog.csdn.net/zzz_781111/article/details/7372024 Generated by Jackxiang's Bo-blog 2.1.1 Release