我的程序大体如下:
HOSTENT *tmpHostent ;
unsigned long ip2 = *( unsigned long * )( "192.168.3.201" ) ;
in_addr tmp ;
tmp = *( in_addr * )&ip2 ;
ip2 = inet_addr( inet_ntoa( tmp ) ) ;
tmpHostent = gethostbyaddr( (char*)&ip2 , 16 , AF_INET ) ;
CString ss=tmpHostent->h_name;
AfxMessageBox(ss);为什么执行后,内存报错?
HOSTENT *tmpHostent ;
unsigned long ip2 = *( unsigned long * )( "192.168.3.201" ) ;
in_addr tmp ;
tmp = *( in_addr * )&ip2 ;
ip2 = inet_addr( inet_ntoa( tmp ) ) ;
tmpHostent = gethostbyaddr( (char*)&ip2 , 16 , AF_INET ) ;
CString ss=tmpHostent->h_name;
AfxMessageBox(ss);为什么执行后,内存报错?
解决方案 »
- 跟大家分享一下directUI的心得。
- vs能开发纯dos程序吗
- 怎样得到当前exe文件的路径
- rtp包还原成语音
- 求助! 关于动态在对话框中添加编辑框控件?
- API函数:SQLManageDataSources在XP mainfest问题!
- 能否在自定义类中使用message_map??我用socket api写了一个类,但是不知道如何响应用户非常退出。
- ★★★急呀,很简单的一个问题,忘了怎么做的?怎么把一个16进制的字符串以二进制的形式写倒文件中★★★★★
- 怎样把工作区内不用的类或者建错的对话框删掉?
- 一个对语法敏感的文本编辑器...
- 怎样使用installshield定制自己的安装对话框呢?是用script,还是在提供对话框的dll里做,具体怎么做才能实现用图片代替
- 如何在com中定义多维数组的属性?get和set如何写??
{
int numberOfHost = 1;
struct hostent *remoteHostent; //处理命令行参数
if ( argc == 3 )
numberOfHost = atoi( argv[2] );
if ( ( argc >3 ) || ( argc < 2 ) )
{
printf( "RmtHost v0.2 - Get remote HostName /MacAddress\n" );
printf( "by ShotgunLabs ( [email protected] )\n\n" );
printf( "Usage :\n\tRmtHost.exe [RemoteIP] \n\n" );
printf( "Example:\n\tRmtHost.exe 192.168.0.3\n" );
printf( "\tRmtHost.exe 192.168.0.3 255\n\n" );
exit( 0 );
} //初始化SOCKET
WSADATA wsaData;
int iRet = WSAStartup(MAKEWORD(2,1), &wsaData);
if ( iRet != 0 )
{
printf( "WSAStartup Error:%d\n", GetLastError() );
exit( 0 );
}
int nRemoteAddr = inet_addr( argv[1] );
remoteHostent= (struct hostent*)malloc( sizeof(struct hostent ));
struct in_addr sa;
for ( int i = 0; i < numberOfHost; i ++ )
{
//获取远程机器名
sa.s_addr = nRemoteAddr;
printf( "\nIpAddress : %s\n", inet_ntoa( sa ) );
remoteHostent = gethostbyaddr( (char*)&nRemoteAddr,4, AF_INET );
if ( remoteHostent )
printf( "HostName : %s\n",remoteHostent->h_name );
else
printf( "gethostbyaddr Error:%d\n",GetLastError() );
//发送ARP查询包获得远程MAC地址 unsigned char macAddress[6];
ULONG macAddLen = 6;
iRet=SendARP(nRemoteAddr, (unsigned long)NULL,(PULONG)&macAddress, &macAddLen);
if ( iRet == NO_ERROR )
{
printf( "MacAddress: " );
for( int i =0; i<6; i++ )
{
printf( "%.2x", macAddress[i] );
if ( i<5 ) printf( "-" );
}
printf( "\n" );
}
else
printf( "SendARP Error:%d\n", GetLastError());
nRemoteAddr = htonl( ntohl( nRemoteAddr ) + 1 );
}
}
unsigned long ip2 = *( unsigned long * )( "192.168.3.201" ) ;
//why? i think is this
//unsigned long ip2 = inet_addr( "192.168.3.201" );
in_addr tmp ;
tmp = *( in_addr * )&ip2 ;
ip2 = inet_addr( inet_ntoa( tmp ) ) ;
tmpHostent = gethostbyaddr( (char*)&ip2 , 16 , AF_INET ) ;
HOSTENT *tmpHostent ;
unsigned long ip2 = *( unsigned long * )( "192.168.3.201" ) ;
in_addr tmp ;
tmp = *( in_addr * )&ip2 ;
ip2 = inet_addr( inet_ntoa( tmp ) ) ;
tmpHostent = gethostbyaddr( (char*)&ip2 , 16 , AF_INET ) ;你这个应该判断一下 tmpHosten == NULL 的情况
CString ss=tmpHostent->h_name;
AfxMessageBox(ss);