扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:魏云华 来源:《csdn开发高手》杂志 2007年10月28日
关键字: Linux
int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData); |
int PASCAL FAR WSACleanup(void); |
int PASCAL FAR gethostname (char FAR * name, int namelen); |
struct hostent FAR * PASCAL FAR gethostbyname(const char FAR * name); |
Struct hostent { char FAR * h_name; char FAR FAR ** h_aliases; short h_addrtype; char FAR FAR ** h_addr_list; } |
#include<winsock.h> int WSA_return; WSADATA WSAData; HOSTENT *host_entry; char host_name[256]; char host_address[256]; int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow) { WSA_return=WSAStartup(0x0101,&WSAData); if(WSA_return==0) { gethostname(host_name,256); host_entry=gethostbyname(host_name); if(host_entry!=0) { wsprintf(host_address,"%d.%d.%d.%d", (host_entry->h_addr_list[0][0]&0x00ff), (host_entry->h_addr_list[0][1]&0x00ff), (host_entry->h_addr_list[0][2]&0x00ff), (host_entry->h_addr_list[0][3]&0x00ff)); MessageBox(NULL,host_address,host_name,MB_OK); } } WSACleanup(); return 0; } |
BOOL APIENTRY Hostname_ipDlgPro(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam); |
#include<winsock2.h> #include"Get_IP.h" #include"resource.h" //这个头文件在创建资源的时候会自动生成, //并会在插入资源时自动生成控件标识号. int WSA_return; WSADATA WSAData; HOSTENT *host_entry; char host_name[256]; char host_address[256]; int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow) { WSA_return=WSAStartup(0x0101,&WSAData); if(WSA_return==0) { gethostname(host_name,256); host_entry=gethostbyname(host_name); if(host_entry!=0) { wsprintf(host_address,"%d.%d.%d.%d", (host_entry->h_addr_list[0][0]&0x00ff), (host_entry->h_addr_list[0][1]&0x00ff), (host_entry->h_addr_list[0][2]&0x00ff), (host_entry->h_addr_list[0][3]&0x00ff)); } } WSACleanup(); DialogBox(hInstance,"DIALOG1",NULL,(DLGPROC)Hostname_ipDlgPro); return 0; } BOOL APIENTRY Hostname_ipDlgPro(HWND hDlg,UINT message, WPARAM wParam,LPARAM lParam) { switch(message) { case WM_INITDIALOG: return(TRUE); case WM_COMMAND: if(LOWORD(wParam)==IDOK) { SetDlgItemText(hDlg,IDC_EDIT1,host_name); SetDlgItemText(hDlg,IDC_EDIT2,host_address); SetDlgItemText(hDlg,IDCANCEL,"确定"); } if(LOWORD(wParam)==IDCANCEL) EndDialog(hDlg,TRUE); return(TRUE); break; } return(FALSE); } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者