本站首页    管理页面    写新日志    退出


«December 2025»
123456
78910111213
14151617181920
21222324252627
28293031


公告

☆★☆★☆★☆★☆★☆
生活的点点记录,以及一些体会...........

喜欢是淡淡的爱,爱是深深的喜欢.

时间会见证一切.......................

欢迎大家指出错误,共同进步..........

期待中..............................

☆★☆★☆★☆★☆★☆


我的分类(专题)

日志更新

最新评论

留言板

链接

世纪音频

 

 


Blog信息
blog名称:
日志总数:162
评论数量:312
留言数量:0
访问次数:953119
建立时间:2005年5月17日




[读书笔记]获取IP地址
读书笔记

oceanblue 发表于 2006/11/21 16:07:13

////////////////////////////////////////////////////////////////// VCKBASE Online Journal//// getip1.cpp//// This program reports the IP address for each adapter in your machine.// To compile from command-line type://// cl getip1.cpp wsock32.lib//// Make sure your INCLUDE and LIB environment variables are set up properly;// you can run vcvars32.bat//#include <winsock.h>#include <wsipx.h>#include <wsnwlink.h>#include <stdio.h> int main(){ //////////////// // Initialize windows sockets API. Ask for version 1.1 // WORD wVersionRequested = MAKEWORD(1, 1); WSADATA wsaData; if (WSAStartup(wVersionRequested, &wsaData)) {  printf("WSAStartup failed %s\n", WSAGetLastError());  return -1; }  ////////////////// // Get host name. // char hostname[256]; int res = gethostname(hostname, sizeof(hostname)); if (res != 0) {  printf("Error: %u\n", WSAGetLastError());  return -1; } printf("hostname=%s\n", hostname);  //////////////// // Get host info for hostname.  // hostent* pHostent = gethostbyname(hostname); if (pHostent==NULL) {  printf("Error: %u\n", WSAGetLastError());  return -1; }  ////////////////// // Parse the hostent information returned // hostent& he = *pHostent; printf("name=%s\naliases=%s\naddrtype=%d\nlength=%d\n",  he.h_name, he.h_aliases, he.h_addrtype, he.h_length);  sockaddr_in sa; for (int nAdapter=0; he.h_addr_list[nAdapter]; nAdapter++) {  memcpy ( &sa.sin_addr.s_addr, he.h_addr_list[nAdapter],he.h_length);      // Output the machines IP Address.      printf("Address: %s\n", inet_ntoa(sa.sin_addr)); // display as string }  ////////////////// // Terminate windows sockets API // WSACleanup();  return 0;}


阅读全文(3270) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.531 second(s), page refreshed 144822384 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号