網絡地址兼容域名和點分十進制IP地址

char*   strHost = www.baidu.com;

struct  in_addr iaDestAddr;  // Internet address structure

LPHOSTENT  pHost;             // Pointer to host entry structure

DWORD* dwAddress;           // IP Address

 

iaDestAddr.s_addr  =  inet_addr(strHost);

if (INADDR_NONE == iaDestAddr.s_addr)   // dealing with a name

{

     pHost = gethostbyname(strHost);

}

else           // dealing with an address

{

    pHost = gethostbyaddr((const char*)&iaDestAddr, sizeof(struct in_addr),AF_INET);

}

if (NULL == pHost)

{

    return FALSE;

}

dwAddress = (DWORD*)(*pHost->h_addr_list);

發佈了35 篇原創文章 · 獲贊 5 · 訪問量 18萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章