最好带注解的要全文件.不只要主要的文件.我大体上原理都明白.好象总是有错误.
谢谢.
谢谢.
解决方案 »
- 关于xp如何模仿win7的桌面渐变效果。
- 不同文件结构体调用
- CFormView中用Picture控件显示BitMAP图片问题
- 高手求教 VC程序如何获取IE网页加载是否已完毕
- bmp转换jpg
- vc里怎么调用delphi 的dll
- workspace的 classview, resourceview, fileview三个的区别?
- 在线等待,急!~!~!~!~为什么我的点运算符不支持了,变量定义没有错误。
- 怪问题:可不可以 *.OBJ 把文件直接连接到项目当中去?
- 关于StretchBlt函数,不支持打印。
- 关于用VC6做串口通信,接收大量数据
- 江湖救急呀!从CRichEditView派生的类怎么实现C/C++语言的关键字高亮显示
缓冲区szIp是调用者分配的,用来返回本地的IPbool GetLocHostIp(char *szIp)
{
char szHostName[128];
if(gethostname(szHostName, 128) == 0) //计算机名, 变量szHostName就是本机名
{
struct hostent * pHost;
int i;
pHost = gethostbyname(szHostName);
for(i = 0; pHost != NULL && pHost->h_addr_list[i]!=NULL; i++)
{
char strHostIp[25];
memset(strHostIp, 0, 25);
int j;
for(j = 0; j < pHost->h_length; j++)
{
char addr[10];
if(j > 0)
strcat(strHostIp, ".");
sprintf(addr, "%u",(unsigned int)((unsigned char*)pHost->h_addr_list[i])[j]);
strcat(strHostIp, addr);
}
strcpy(szIp, strHostIp);
}
}
return true;
}
CString LocalIP;
hostent *name;
char Name[255];
memset(Name,0,255);
gethostname(Name,255);
name=gethostbyname(Name);
LocalIP=inet_ntoa(*(in_addr *)name->h_addr_list[0]);
最好去 MSDN 查查相关函数及其用法,养成好习惯...
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);/*打印*/
}
}
}
// 得到本机的IP地址
char szHost[256];
::gethostname(szHost, 256);
hostent* pHost = ::gethostbyname(szHost);