why is this crashing?

Post questions regarding programming in C/C++ in Linux/Unix.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

why is this crashing?

Postby Red Squirrel » Fri Sep 30, 2005 2:34 pm

I have this loop that for some reason it just decides to crash. No error, no nothing, the program just terminates. And it's not normal termination as normal termination involves much more output at the end, but this just stops completely, right in the middle of the transfer. This program does the same transfer over and over (it's sort of a DoS tool to test server stability etc) so sometimes it will send it about 500 times then crash, sometimes it will crash at the 1st try etc... it's completely random.


Code: Select all
fstream file2send(file.c_str(),ios::in);

int bytes=0;
char data;
while(!file2send.eof())
{
cout<<"\rSending "<<bytes<<" bytes...";

file2send.get(data);
send(sockfd,&data,1,0);

bytes++;
}
cout<<"done.";
file2send.close();



If needed the full source code is here:
http://www.iceteks.com/misc/socksend.cpp
Red Squirrel
 
Posts: 75
Joined: Thu Jan 01, 2004 7:31 pm

Postby Dante Shamest » Fri Sep 30, 2005 3:10 pm

Completely random you say? Hmm, that's indeed strange. I wonder if it's the send function that failing.

Try replacing the code you posted with the following code.

Code: Select all
ifstream file2send( file.c_str() );
file2send.get(data);
while( file2send ) {
  cout<<"\rSending "<<bytes<<" bytes...";
  if ( send(sockfd,&data,1,0) == -1 ) {
    cout << "send function failed\n" ;
  }
  file2send.get(data);
  bytes++;
}
cout<<"done.";
file2send.close();
User avatar
Dante Shamest
Moderator
 
Posts: 3131
Joined: Wed Oct 22, 2003 10:29 pm
Location: Malaysia

Postby Red Squirrel » Sun Oct 02, 2005 7:11 pm

Nope, it does not fail. I even added the send return value in the output and it stays at 1 all the time even after it just stops for no reason.

This is basically what my output looks like, 3 times trying it.

try 1:
Code: Select all
-------------------------------------------------------------------------------
Connection 1 of 1000000.
Connecting...ok
Sending(1borg:/data/samba/shared/ryan/applications/socksend#


try 2:

Code: Select all
-------------------------------------------------------------------------------
Connection 1 of 1000000.
Connecting...ok
Sending(1) 15432 byteborg:/data/samba/shared/ryan/applications/socksend#


try 3:

Code: Select all
-------------------------------------------------------------------------------
Connection 1 of 1000000.
Connecting...ok
Senborg:/data/samba/shared/ryan/applications/socksend#



Also, it depends on the host, which is really weird.... it should not matter. For example I tried it on my online site and google, and it will last a bit longer then if I use it on my local experimental IIS server, on my apache server it also lasts a bit longer. Also, I tried it on a different port (139) of the test server and it goes in ok. It's almost as if it depends what the server response is and how it's formatted or something but that can't be as most of the time I ingore the response, unless it still goes in some buffer somewhere which I have no control over.
Red Squirrel
 
Posts: 75
Joined: Thu Jan 01, 2004 7:31 pm


Return to Unix/Linux

Who is online

Users browsing this forum: No registered users and 1 guest