得到本机和其它机器的IP地址和网卡MAC地址,是不是必须用PLATFORM?还有别的方法吗?
解决方案 »
- 这样的struct定义怎么解释?
- 一个关于利用keybd_event模拟按键的恼怒问题
- 求教,,请问 类大小 问题,是个嵌入式面试问题?
- 我的VC6.0 为什么显示.cpp文件时编辑器突然失效,比如 “void”,都不变颜色了,重新安装后还是不行,是中毒了吗?
- Output窗口中出现Access violation writing location 是什么错误!急!
- 请问你们的分是怎么来的呢?
- 如何序列化COleClientItem??
- 谁有CAD?版本不限,帮忙做几个DXF文件。
- 如何访问CMOS里而的地址
- 有没有工具,可以分析出当前工程的类层次组织关系
- 那位讲联众的界面如何实现的?
- 如何创建目录
char szHostName[128];
if( gethostname(szHostName, 128) == 0 )
{
// Get host adresses
struct hostent * pHost;
int i;
pHost = gethostbyname(szHostName);
for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
{
CString str;
int j;
for( j = 0; j < pHost->h_length; j++ )
{
CString addr;
if( j > 0 )
str += ".";
addr.Format("%u", (unsigned int)((unsigned
char*)pHost->h_addr_list[i])[j]);
str += addr;
}
// str now contains one local IP address - do whatever you want to do with it (probably add it to a list)
}
}
void main(argc, argv)
int argc;
char **argv;
{ struct hostent *hp;
struct in_addr *ptr; /* get the server name */
if ((hp = gethostbyname("skinner")) == NULL)
{
fprintf(stderr, "%s: server unknown.\n", *argv);
exit (1);
} /* get the address */
if(hp->h_addrtype = AF_INET)
{
while((ptr=(struct in_addr *) *hp->h_addr_list++) != NULL)
fprintf(stderr, "address: %s \n", inet_ntoa(*ptr));
} exit(0);
}