Skip to content

Commit

Permalink
Merge pull request #77 from runderwo/unmalloc
Browse files Browse the repository at this point in the history
Remove heap manipulation from fast path.
  • Loading branch information
schweikert committed May 27, 2015
2 parents 0706f68 + 3d74b33 commit 8fc9fa3
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ unsigned int perhost_interval = DEFAULT_PERHOST_INTERVAL * 100;
float backoff = DEFAULT_BACKOFF_FACTOR;
unsigned int ping_data_size = DEFAULT_PING_DATA_SIZE;
unsigned int ping_pkt_size;
char *ping_buffer;
unsigned int count = 1;
unsigned int trials;
unsigned int report_interval = 0;
Expand Down Expand Up @@ -822,7 +823,10 @@ int main( int argc, char **argv )
}/* FOR */

ping_pkt_size = ping_data_size + SIZE_ICMP_HDR;

ping_buffer = ( char* )malloc( ( size_t )ping_pkt_size );
if( !ping_buffer )
crash_and_burn( "can't malloc ping packet" );

signal( SIGINT, finish );

gettimeofday( &start_time, &tz );
Expand Down Expand Up @@ -1398,24 +1402,19 @@ void print_global_stats( void )

int send_ping( int s, HOST_ENTRY *h )
{
char *buffer;
FPING_ICMPHDR *icp;
int n;
int myseq;
int ret = 1;

buffer = ( char* )malloc( ( size_t )ping_pkt_size );
if( !buffer )
crash_and_burn( "can't malloc ping packet" );

if (random_data_flag) {
for (n = 0; n < ping_pkt_size; ++n) {
buffer[n] = random() & 0xFF;
ping_buffer[n] = random() & 0xFF;
}
} else {
memset( buffer, 0, ping_pkt_size * sizeof( char ) );
memset( ping_buffer, 0, ping_pkt_size * sizeof( char ) );
}
icp = ( FPING_ICMPHDR* )buffer;
icp = ( FPING_ICMPHDR* )ping_buffer;

gettimeofday( &h->last_send_time, &tz );
myseq = seqmap_add(h->i, h->num_sent, &h->last_send_time);
Expand All @@ -1441,7 +1440,7 @@ int send_ping( int s, HOST_ENTRY *h )
printf( "sending [%d] to %s\n", h->num_sent, h->host );
#endif /* DEBUG || _DEBUG */

n = sendto( s, buffer, ping_pkt_size, 0,
n = sendto( s, ping_buffer, ping_pkt_size, 0,
( struct sockaddr* )&h->saddr, sizeof( FPING_SOCKADDR ) );

if(
Expand Down Expand Up @@ -1475,7 +1474,6 @@ int send_ping( int s, HOST_ENTRY *h )
h->waiting++;
num_pingsent++;
last_send_time = h->last_send_time;
free( buffer );

return(ret);
}
Expand Down

0 comments on commit 8fc9fa3

Please sign in to comment.