//一些定義:
// hostent declare
/*struct hostent ;
struct in_addr s_un_b;
struct s_un_w;
u_long s_addr;
} s_un;
#define s_addr s_un.s_addr // can be used for most tcp & ip code
#define s_host s_un.s_un_b.s_b2 // host on imp
#define s_net s_un.s_un_b.s_b1 // network
#define s_imp s_un.s_un_w.s_w2 // imp
#define s_impno s_un.s_un_b.s_b4 // imp #
#define s_lh s_un.s_un_b.s_b3 // logical host
};
//sockaddr delcare
struct sockaddr ;
//sockaddr_in declare
struct sockaddr_in ;*/
#include
#include "cinitsock.h"
#include
#include
using namespace std;
#pragma comment(lib, "ws2_32")
int const max_size = 256;
class cinitsock}
~cinitsock()};
cinitsock initsock(1, 1);
int main();
int i = 0;
::gethostname(szhost, max_size);
phost = ::gethostbyname(szhost);
for (i = 0; ; i++)
memcpy(&addr.s_un.s_addr, p, phost->h_length);
char* szip = ::inet_ntoa(addr);
cout << "local ip address: " << szip << endl;}
}
用ioctl獲得本地ip位址
用ioctl獲得本地ip位址時要用到兩個結構體ifconf和ifreq,它們對於大多數人 來說都是比較陌生的,這裡給大家一種比較簡單的理解方法,當然只一種幫助 理解的方法,在描述中可能會有一些地方與真實定義有所出入,僅供參考.首先先認識一下ifconf和ifreq ifconf通常是用來儲存所有介面...
用ioctl獲得本地ip位址
用ioctl獲得本地ip位址時要用到兩個結構體ifconf和ifreq,它們對於大多數人 來說都是比較陌生的,這裡給大家一種比較簡單的理解方法,當然只一種幫助 理解的方法,在描述中可能會有一些地方與真實定義有所出入,僅供參考.首先先認識一下ifconf和ifreq ifconf通常是用來儲存所有介面...
qt獲得本地IP的方法
環境 ubuntu10.04 qt4.7.0 linux獲得本地ip的方法,我嘗試了兩種 1.用qhostinfo類解析 qhostinfo類可以解析網域名稱,理論上也可以解析本地ip,可是經過嘗試,我發現解析出來的ip是127.0.0.1是本地回環位址,不符合我的需求。獲取本地ip qhostin...