Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future request : print returned TOS value #68

Open
GBert opened this issue Sep 11, 2014 · 0 comments
Open

Future request : print returned TOS value #68

GBert opened this issue Sep 11, 2014 · 0 comments

Comments

@GBert
Copy link

GBert commented Sep 11, 2014

Ping with TOS field is already in the code, but printing the result is missing. I know that you don't like to change the output so I have added tos_flag which is set by the -O flag
(GBert@32e266e)

--- a/src/fping.c
+++ b/src/fping.c
@@ -230,6 +230,7 @@ typedef struct host_entry
      int                  min_reply_i;        /* shortest response time */
      int                  total_time_i;       /* sum of response times */
      int                  *resp_times;        /* individual response times */
+     int                  tos;                /* individual tos field */
 #if defined( DEBUG ) || defined( _DEBUG )
      int                  *sent_times;        /* per-sent-ping timestamp */
 #endif /* DEBUG || _DEBUG */
@@ -295,6 +296,7 @@ struct timezone tz;

 /* switches */
 int generate_flag = 0;              /* flag for IP list generation */
+int tos_flag = 0;                        /* flag if tos should be printed */
 int verbose_flag, quiet_flag, stats_flag, unreachable_flag, alive_flag;
 int elapsed_flag, version_flag, count_flag, loop_flag;
 int per_recv_flag, report_all_rtts_flag, name_flag, addr_flag, backoff_flag;
@@ -363,7 +365,7 @@ int main( int argc, char **argv )
     int c, i, n;
     char *buf;
     uid_t uid;
-    int tos = 0;
+    int tos = 0;
     HOST_ENTRY *cursor;

     s = open_ping_socket();
@@ -548,6 +550,7 @@ int main( int argc, char **argv )
                 if ( setsockopt(s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) {
                     perror("setting type of service octet IP_TOS");
                 }
+               tos_flag = 1;
             }
             else {
                 usage(1);
@@ -1605,6 +1608,7 @@ int wait_for_reply(long wait_time)
         sum_replies += this_reply;
         h->total_time += this_reply;
         h->total_time_i += this_reply;
+        h->tos = ip->ip_tos;
         total_replies++;
     }

@@ -1664,7 +1668,10 @@ int wait_for_reply(long wait_time)
             printf( "%s", h->host );

             if( verbose_flag )
-                printf( " is alive" );
+                if ( tos_flag )
+                    printf( " is alive (TOS %d)", h->tos );
+                else
+                    printf( " is alive" );

             if( elapsed_flag )
                 printf( " (%s ms)", sprint_tm( this_reply ) );

Here is the output:

% ./fping -A -n server
server (192.168.100.10) is alive

% ./fping -A -n -O 0 server
server (192.168.100.10) is alive (TOS 0)

% ./fping -A -n -O 184 server
server (192.168.100.10) is alive (TOS 184)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants