下面这段程序在W2k下面没是么反应,为何,请大家指点
         int numberOfHost = 1;
struct hostent *remoteHostent;
WSADATA wsaData;
int iRet = WSAStartup(MAKEWORD(2,1), &wsaData);
if ( iRet != 0 )
{
exit( 1 );
}
int nRemoteAddr  = inet_addr("10.150.17.93");
int localAddr  =inet_addr("10.150.16.154");
remoteHostent= (struct hostent*)malloc( sizeof(struct hostent ));
struct in_addr sa;
sa.s_addr = nRemoteAddr;
remoteHostent = gethostbyaddr( (char*)&nRemoteAddr,4, AF_INET );
if (!remoteHostent )
       exit(1);
unsigned char macAddress[6];
ULONG macAddLen = 6;
iRet=SendARP(nRemoteAddr, localAddr,(PULONG)&macAddress, &macAddLen);
// MessageBox((char*)macAddress,NULL,MB_OK);
m_remotemac.SetWindowText((char*)macAddress);

解决方案 »

  1.   

    //use IpHlpapi
    // Note: Win2000 only
    //   NOT NT 4.0, Win9x, WinME#pragma comment( lib, "Iphlpapi" )
    #pragma comment( lib, "Ws2_32" )#include <windows.h>
    #include <Iphlpapi.h>int main( ) {IPAddr ip = 0;
    ULONG  mac = 0;
    DWORD  error = 0;    DWORD dwSize = sizeof( ULONG) ;
        ip = inet_addr("192.168.0.100");
        //ip = inet_addr("xxx.xxx.xxx.xxx");
        error = SendARP(ip,0,&mac,&dwSize);    return 0;
    }
      

  2.   

    把你的程序在2K下重新编译一次应该可以。在98下面编译的程序可能有Ascii和Unicode编码转换问题
      

  3.   

    kingzai() 大哥你的程序我编译运行通过,可是取到的MAC地址并不正确,利用不同的主机IP他也返回相同的MAC,是什么原因呢
      

  4.   

    跟你具体的网络环境有关系,注意DNS的配置是否正确
      

  5.   

    取到的MAC地址不正确是不是“大头”“小头”的原因?
    一个MAC上可以帮定多个IP地址,所以不同的IP他也返回相同的MAC。
    个人观点
      

  6.   

    是DNS的配置吧
    是什么原因呢
      

  7.   

    How about the assignation of IP address in ur network ?
      

  8.   

    在公司网段内自动得到IP地址与自动得到DNS服务器地址
      

  9.   

    So the IP is dynamic ...it's changeable ...
      

  10.   

    原因找到了,是代码有点小问题,谢谢大家,源码如下
            int ip = 0; //here
            unsigned char   mac[6];
            DWORD  error = 0;
            ULONG dwSize = 6;
    m_szRemoteIP.GetWindowText(m_szremoteip);
            ip = inet_addr(m_szremoteip);
            error = SendARP(ip,0,(PULONG)&mac,&dwSize);
            if (error == NO_ERROR )
    {
    // printf( "MacAddress: " );
    // printf( "%d\n", mac );
    m_szRemoteMAC.Format("%02X-%02X-%02X-%02X-%02X-%02X",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);//here
    }
    else
    // printf( "SendARP Error:%d\n", GetLastError());
    return;
          m_remotemac.SetWindowText(m_szRemoteMAC);