반응형
Ping 예제 프로그램
wince / WM 에서 ping 관련 프로그램을 작성할때 간단히 쓸수있는 예제
예제 함수
void Ping()
{
// create handle
HANDLE hICMP = IcmpCreateFile();
if ( hICMP == INVALID_HANDLE_VALUE )
{
return;
}
// set option
IP_OPTION_INFORMATION option;
memset( &option, 0, sizeof( option ) );
option.Ttl = 32;
option.Tos = 0;
option.Flags = IP_FLAG_DF;
// prepare buffer
char* bufOut = new char[ m_nDataSize ];
memset( bufOut, 0, m_nDataSize );
char* bufIn = new char[ m_nDataSize * 32 ];
// send echo
DWORD dwRet = IcmpSendEcho( hICMP, m_dwHostAddr, bufOut, m_nDataSize, &option, bufIn, m_nDataSize * 32, 1000 );
bool bSuccess = false;
if ( dwRet > 0 )
{// received reply
PICMP_ECHO_REPLY pReply = (PICMP_ECHO_REPLY) bufIn;
for ( unsigned int i = 0; i < dwRet; ++i )
{
RETAILMSG(1, (_T("SUCCESS\r\n")));
}
}
else
RETAILMSG(1, (_T("FAILED\r\n")));
// close handle
IcmpCloseHandle( hICMP );
}
DWORD dwRet = IcmpSendEcho( hICMP, m_dwHostAddr, bufOut, m_nDataSize, &option, bufIn, m_nDataSize * 32, 1000 );
- 위의 부분을 적당히 수정하여 ping 프로그램을 작성할수있다.
반응형