可以用下面的代码根据计算机名称得到IP地址:
void print_all_ip(void)
{
  char szHostName[128];
  const char* pszAddr;
  struct hostent * pHost;
  int i,j; 
  if( gethostname(szHostName, 128) == 0 )
  {
    pHost = gethostbyname(szHostName); 
    for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ ) 
    {/*对每一个IP地址进行处理*/
      pszAddr=inet_ntoa (*(struct in_addr *)pHost->h_addr_list[i]);
      printf("%s\n",pszAddr);/*打印*/
    }
  }
}