Commit 0be60162 authored by Olav Kvittem's avatar Olav Kvittem

fixed reading too short records from stdin

parent d5109756
......@@ -705,9 +705,13 @@ static int decode_file(void)
memset(str1,0,INET6_ADDRSTRLEN);
memset(str2,0,INET6_ADDRSTRLEN);
while(read(main_file,buffer,buf_len) > 0)
char *buffer_p=buffer;
int ngot = 0, nleft=buf_len;
while( (ngot=read(main_file,buffer_p, nleft)) > 0)
{
if ( (nleft -= ngot) == 0){ // got full buffer
// if (ngot < buf_len) fprintf( stderr, "Got %d bytes\n", ngot);
pkt_count++;
ptr1 = (struct udp_data*)buffer;
ptr2 = (struct crude_struct*)(buffer + sizeof(struct udp_data));
......@@ -729,6 +733,19 @@ static int decode_file(void)
(unsigned long)ntohl(ptr2->rx_time_seconds),
(unsigned long)ntohl(ptr2->rx_time_useconds),
(long)ntohl(ptr2->pkt_size));
int tx=(unsigned long)ntohl(ptr1->tx_time_seconds);
if ( tx < 1440000000 || tx > 1600000000 )
fprintf( stderr, "Tx is odd %ld - Got %d bytes\n", tx, ngot);
nleft=buf_len;
buffer_p=buffer;
} else if (nleft < 0) { // never occurs I hope
fprintf( stderr, "Got %d bytes, left %d\n", ngot, nleft);
} else { // get data to fill buffer
buffer_p+=ngot;
// fprintf( stderr, "Got only %d bytes\n", ngot);
}
}
if(errno){ RUDEBUG1("crude: read failed: %s\n", strerror(errno)); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment