#include "stdafx.h"
#include "ping.h"
#include "stdio.h"
void _tmain(int argc, TCHAR *argv[])
{
FILE *fil; FILE fil=fopen("d:\result.txt","w");
if (argc != 2)
{
printf("You must specify who you want to ping on the command line\n");
return;
}
char name[80];
if(gethostname(name,80)==SOCKET_ERROR)
printf("shit");
#ifdef CPING_USE_ICMP
{ printf("shit111"); CPing p1;
CPingReply pr1;
if (p1.Ping1(argv[1], pr1))
{
hostent* phostent = gethostbyaddr((char *)&pr1.Address.S_un.S_addr, 4, PF_INET);
printf("%d.%d.%d.%d [%s], replied in RTT:%dms\n",
pr1.Address.S_un.S_un_b.s_b1, pr1.Address.S_un.S_un_b.s_b2, pr1.Address.S_un.S_un_b.s_b3,
pr1.Address.S_un.S_un_b.s_b4, phostent->h_name, pr1.RTT);
fprintf(fil,"d.%d.%d.%d [%s], replied in RTT:%dms\n",
pr1.Address.S_un.S_un_b.s_b1, pr1.Address.S_un.S_un_b.s_b2, pr1.Address.S_un.S_un_b.s_b3,
pr1.Address.S_un.S_un_b.s_b4, phostent->h_name, pr1.RTT);
}
else
printf("Failed in call to ping, GetLastError returns: %d", GetLastError());
}
#endif#ifdef CPING_USE_WINSOCK2
{ printf("shit2222"); CPing p2;
CPingReply pr2;
if (p2.Ping2(argv[1], pr2))
{
hostent* phostent = gethostbyaddr((char *)&pr2.Address.S_un.S_addr, 4, PF_INET);
printf("%d.%d.%d.%d [%s], replied in RTT:%dms\n",
pr2.Address.S_un.S_un_b.s_b1, pr2.Address.S_un.S_un_b.s_b2, pr2.Address.S_un.S_un_b.s_b3,
pr2.Address.S_un.S_un_b.s_b4, phostent->h_name, pr2.RTT);
fprintf(fil,"d.%d.%d.%d [%s], replied in RTT:%dms\n",
pr1.Address.S_un.S_un_b.s_b1, pr1.Address.S_un.S_un_b.s_b2, pr1.Address.S_un.S_un_b.s_b3,
pr1.Address.S_un.S_un_b.s_b4, phostent->h_name, pr1.RTT);
}
else
printf("Failed in call to ping, GetLastError returns: %d", GetLastError());
}
#endiffclose(fil);}
这个是主程序,还有个ping.c的,,原来是能运行的, 我就加了文件那几条,运行的时候就
说是DEBUG ASSERT FAILED ,str !=NULL.这是怎么回事啊???
#include "ping.h"
#include "stdio.h"
void _tmain(int argc, TCHAR *argv[])
{
FILE *fil; FILE fil=fopen("d:\result.txt","w");
if (argc != 2)
{
printf("You must specify who you want to ping on the command line\n");
return;
}
char name[80];
if(gethostname(name,80)==SOCKET_ERROR)
printf("shit");
#ifdef CPING_USE_ICMP
{ printf("shit111"); CPing p1;
CPingReply pr1;
if (p1.Ping1(argv[1], pr1))
{
hostent* phostent = gethostbyaddr((char *)&pr1.Address.S_un.S_addr, 4, PF_INET);
printf("%d.%d.%d.%d [%s], replied in RTT:%dms\n",
pr1.Address.S_un.S_un_b.s_b1, pr1.Address.S_un.S_un_b.s_b2, pr1.Address.S_un.S_un_b.s_b3,
pr1.Address.S_un.S_un_b.s_b4, phostent->h_name, pr1.RTT);
fprintf(fil,"d.%d.%d.%d [%s], replied in RTT:%dms\n",
pr1.Address.S_un.S_un_b.s_b1, pr1.Address.S_un.S_un_b.s_b2, pr1.Address.S_un.S_un_b.s_b3,
pr1.Address.S_un.S_un_b.s_b4, phostent->h_name, pr1.RTT);
}
else
printf("Failed in call to ping, GetLastError returns: %d", GetLastError());
}
#endif#ifdef CPING_USE_WINSOCK2
{ printf("shit2222"); CPing p2;
CPingReply pr2;
if (p2.Ping2(argv[1], pr2))
{
hostent* phostent = gethostbyaddr((char *)&pr2.Address.S_un.S_addr, 4, PF_INET);
printf("%d.%d.%d.%d [%s], replied in RTT:%dms\n",
pr2.Address.S_un.S_un_b.s_b1, pr2.Address.S_un.S_un_b.s_b2, pr2.Address.S_un.S_un_b.s_b3,
pr2.Address.S_un.S_un_b.s_b4, phostent->h_name, pr2.RTT);
fprintf(fil,"d.%d.%d.%d [%s], replied in RTT:%dms\n",
pr1.Address.S_un.S_un_b.s_b1, pr1.Address.S_un.S_un_b.s_b2, pr1.Address.S_un.S_un_b.s_b3,
pr1.Address.S_un.S_un_b.s_b4, phostent->h_name, pr1.RTT);
}
else
printf("Failed in call to ping, GetLastError returns: %d", GetLastError());
}
#endiffclose(fil);}
这个是主程序,还有个ping.c的,,原来是能运行的, 我就加了文件那几条,运行的时候就
说是DEBUG ASSERT FAILED ,str !=NULL.这是怎么回事啊???
FILE *fil;
首先在没有进行argc判断的时候不应该打开文件
FILE fil=fopen("d:\result.txt","w");
这句话应该放在后面,其次应该是打开d:\\result.txt,而不是d:\result.txt。
再次打开文件应该判断是否打开成功,前几行应该这样写
FILE *fil = NULL;
if( 2 != argc )
{
...;
return;
}
fil = fopen( "......", "..." );
if( !fil )
{
...;
return;
}....其他的没看,两点了,睡觉。