请强人指点
#include " stdio.h"
#include " stdlib.h"
#include "Winsock2.h"
#include " iphelpapi.h"
Typedef DWORD (CALLBACK*PSARP) (
IPAddr DestIP, / /目的主机IP地址
IPAddr SrcIP, / / 源主机IP地址
PULONG pMacAddr, / / 返回的MAC地址
PULONG PhyAddrLen, / / 返回MAC地址的长度
addr) ; / /定义结构体
void main ( int argc, char**argv )
{
PSARP pSARP ;
HINSTANCE hInst; / /实例句柄
hInst =LoadLibrary( " iphelpapi.dll" ) ; / /加载IP Helper API所需的库文件
pSARP = ( PSARP) GetProcAddress ( hInst, " SendARP" ) ; / /获取SendARP函数的地址
/ /处理命令行参数
if ( argc ! = 2 )
{
printf ( " Get aMacAddress from host in a segment! \n" ) ;
printf ( "Usage: \n \GetMac. exe [Host IP] \n \n" ) ;
printf ( " Example: \n \GetMac. exe 192. 168. 0. 1 \n \n" ) ;
exit (0) ;
}
printf ( " \n IpAddress: % s\n" , argv[ 1 ] ) ;
int nRemoteAddr = inet_addr( argv[ 1 ] ) ; / /发送ARP查询包获得远程MAC地址
unsigned charmacAddress[ 6 ];
PULONG macAddLen = 6;
int iRet = pSARP ( nRemoteAddr,NULL, ( PULONG) &macAddress, &macAddLen) ;
if ( iRet = =NO_ERROR)
{
printf ( "MacAddress: " ) ;
for ( int i = 0; i < 6; i + + ) / /格式化输出获取的MAC地址
{
printf ( " %. 2x" ,macAddress[ i ] ) ;
if ( i < 5) p rintf ( " - " ) ;
}
}
else
printf ( " SendARP Error: % d \n" , GetLastError( ) ) ;
printf ( " \n" ) ;
}