Package: fping
Owner: Stephan Fuhrmann <[EMAIL PROTECTED]>

Date: Fri, 17 Oct 2008 13:24:39 +0200
From: Stephan Fuhrmann <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
To: Anibal Monsalve Salazar <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]
Subject: fping bugfixes
Message-ID: <[EMAIL PROTECTED]>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=iso-8859-1
Status: RO

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Anibal,

first of all, thanks for maintaining fping!

I fixed some problems in fping and think you might be interested to
include them:

* Network byte order sensitivity was missing completely. Added hopefully
all missing calls.
* The sequence numbering scheme used led to packet drops on our network
hardware. I changed it to a more senseful numbering scheme.
* Some minor C programming mistakes ('=' instead of '==').

The fping source on Thomas' website (CC'ed, fping.com) seems to be out
of date (IPv4-only). I don't know if Thomas is planning to update the
software or website.

The diff included diffs against the latest (?) debian source
fping-2.4b2-to-ipv6.

Best regards,

Stephan
- --
Stephan Fuhrmann
Abteilung Netzwerk

1&1 Internet AG           http://www.1und1.de
Brauerstraße 48           Fon: +49 721 91374-4909
76135 Karlsruhe           Fax: +49 721 91374-212

Amtsgericht Montabaur HRB 6484

Vorstand: Henning Ahlert, Hans-Henning Doerr, Ralph Dommermuth, Matthias
Ehrlich, Oliver Mauss, Matthias Greve, Robert Hoffmann, Achim Weiss
Aufsichtsratsvorsitzender: Michael Scheeren
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFI+HX383it1PtY6p8RAk+JAKCMJTCD6Rl/Ql9BnKIqr5uQ6X2sBQCdE3fw
wOphaAEuC77C4BrfM2FSRJw=
=b7jG
-----END PGP SIGNATURE-----

--- fping.c     2008-10-17 12:19:21.000000000 +0200
+++ /home/stephan/workspace/fping/fping.c       2008-10-17 12:59:05.000000000 
+0200
@@ -24,7 +24,7 @@
  *
  * Original author:  Roland Schemers  <[EMAIL PROTECTED]>
  * IPv6 Support:     Jeroen Massar    <[EMAIL PROTECTED] / [EMAIL PROTECTED]>
- *
+ * Bugfixes, byte order & senseful seq.-numbers: Stephan Fuhrmann 
(stephan.fuhrmann AT 1und1.de)
  *
  *
  * RCS header information no longer used.  It has been moved to the
@@ -296,6 +296,7 @@
 int max_hostname_len = 0;
 int num_jobs = 0;                                      /* number of hosts 
still to do */
 int num_hosts;                                         /* total number of 
hosts */
+int max_seq_sent = 0;                          /* maximum sequence number sent 
so far */
 int num_alive = 0,                                     /* total number alive */
     num_unreachable = 0,                       /* total number unreachable */
     num_noaddress = 0;                         /* total number of addresses 
not found */
@@ -875,7 +876,7 @@
                        errno_crash_and_burn( "fopen" );
 
 
-               while( fgets( line, 132, ping_file ) )
+               while( fgets( line, sizeof(line), ping_file ) )
                {
                        if( sscanf( line, "%s", host ) != 1 )
                                continue;
@@ -1223,6 +1224,7 @@
        
        finish();
 
+       return 0;
 } /* main() */
 
 
@@ -1574,12 +1576,15 @@
        icp = ( FPING_ICMPHDR* )buffer;
 
        gettimeofday( &h->last_send_time, &tz );
+       int myseq = h->num_sent * num_hosts + h->i;
+       max_seq_sent = myseq > max_seq_sent ? myseq : max_seq_sent;
+
 #ifndef IPV6
        icp->icmp_type = ICMP_ECHO;
        icp->icmp_code = 0;
        icp->icmp_cksum = 0;
-       icp->icmp_seq = h->i;
-       icp->icmp_id = ident;
+       icp->icmp_seq = htons(myseq);
+       icp->icmp_id = htons(ident);
 
        pdp = ( PING_DATA* )( buffer + SIZE_ICMP_HDR );
        pdp->ping_ts = h->last_send_time;
@@ -1589,8 +1594,8 @@
 #else
        icp->icmp6_type = ICMP6_ECHO_REQUEST;
        icp->icmp6_code = 0;
-       icp->icmp6_seq = h->i;
-       icp->icmp6_id = ident;
+       icp->icmp6_seq = htons(myseq);
+       icp->icmp6_id = htons(ident);
 
        pdp = ( PING_DATA* )( buffer + SIZE_ICMP_HDR );
        pdp->ping_ts = h->last_send_time;
@@ -1737,25 +1742,25 @@
        }/* IF */
 
 #ifndef IPV6
-       if( icp->icmp_id != ident )
+       if( ntohs(icp->icmp_id) != ident )
 #else
-       if( icp->icmp6_id != ident )
+       if( ntohs(icp->icmp6_id) != ident )
 #endif
                return 1; /* packet received, but not the one we are looking 
for! */
 
        num_pingreceived++;
 
 #ifndef IPV6
-       if( icp->icmp_seq  >= ( n_short )num_hosts )
+       if( ntohs(icp->icmp_seq)  > max_seq_sent )
 #else
-       if( icp->icmp6_seq  >= ( n_short )num_hosts )
+       if( ntohs(icp->icmp6_seq) > max_seq_sent )
 #endif
                return( 1 ); /* packet received, don't worry about it anymore */
 
 #ifndef IPV6
-       n = icp->icmp_seq;
+       n = ntohs(icp->icmp_seq) % num_hosts;
 #else
-       n = icp->icmp6_seq;
+       n = ntohs(icp->icmp6_seq) % num_hosts;
 #endif
        h = table[n];
 
@@ -1946,11 +1951,11 @@
                sent_icmp = ( struct icmp* )( c + 28 );
                
                if( ( sent_icmp->icmp_type == ICMP_ECHO ) &&
-                       ( sent_icmp->icmp_id == ident ) &&
-                       ( sent_icmp->icmp_seq < ( n_short )num_hosts ) )
+                       ( ntohs(sent_icmp->icmp_id) == ident ) &&
+                       ( ntohs(sent_icmp->icmp_seq) <= ( n_short )max_seq_sent 
) )
                {
                        /* this is a response to a ping we sent */
-                       h = table[sent_icmp->icmp_seq];
+                       h = table[ntohs(sent_icmp->icmp_seq) % num_hosts];
                        
                        if( p->icmp_code > ICMP_UNREACH_MAXTYPE )
                        {
@@ -1959,11 +1964,11 @@
 
 #else
                if( ( sent_icmp->icmp6_type == ICMP_ECHO ) &&
-                       ( sent_icmp->icmp6_id == ident ) &&
-                       ( sent_icmp->icmp6_seq < ( n_short )num_hosts ) )
+                       ( ntohs(sent_icmp->icmp6_id) == ident ) &&
+                       ( ntohs(sent_icmp->icmp6_seq) <= ( n_short 
)max_seq_sent ) )
                {
                        /* this is a response to a ping we sent */
-                       h = table[sent_icmp->icmp6_seq];
+                       h = table[ntohs(sent_icmp->icmp6_seq) % num_hosts];
                        
                        if( p->icmp6_code > ICMP_UNREACH_MAXTYPE )
                        {
@@ -2001,24 +2006,24 @@
        case ICMP_PARAMPROB:
                sent_icmp = ( FPING_ICMPHDR* )( c + 28 );
 #ifndef IPV6
-               if( ( sent_icmp->icmp_type = ICMP_ECHO ) && 
-                       ( sent_icmp->icmp_id = ident ) &&
-                       ( sent_icmp->icmp_seq < ( n_short )num_hosts ) )
+               if( ( sent_icmp->icmp_type == ICMP_ECHO ) &&
+                       ( ntohs(sent_icmp->icmp_id) == ident ) &&
+                       ( ntohs(sent_icmp->icmp_seq) <= ( n_short )max_seq_sent 
) )
                {
                        /* this is a response to a ping we sent */
-                       h = table[sent_icmp->icmp_seq];
+                       h = table[ntohs(sent_icmp->icmp_seq) % num_hosts];
                        fprintf( stderr, "%s from %s for ICMP Echo sent to %s",
                                icmp_type_str[p->icmp_type], inet_ntoa( 
addr->sin_addr ), h->host );
       
                        if( inet_addr( h->host ) == -1 )
                                fprintf( stderr, " (%s)", inet_ntoa( 
h->saddr.sin_addr ) );
 #else
-               if( ( sent_icmp->icmp6_type = ICMP_ECHO ) && 
-                       ( sent_icmp->icmp6_id = ident ) &&
-                       ( sent_icmp->icmp6_seq < ( n_short )num_hosts ) )
+               if( ( sent_icmp->icmp6_type == ICMP_ECHO ) &&
+                       ( ntohs(sent_icmp->icmp6_id) == ident ) &&
+                       ( ntohs(sent_icmp->icmp6_seq) <= ( n_short 
)max_seq_sent ) )
                {
                        /* this is a response to a ping we sent */
-                       h = table[sent_icmp->icmp6_seq];
+                       h = table[ntohs(sent_icmp->icmp6_seq) % num_hosts];
                        fprintf( stderr, "%s from %s for ICMP Echo sent to %s",
                                icmp_type_str[p->icmp6_type], addr_ascii, 
h->host );
       



--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to