Implemented "ros_system_resource", a high-level interface for /system/resource/print.
[routeros-api.git] / src / ros.c
index cf65a61..6afc65c 100644 (file)
--- a/src/ros.c
+++ b/src/ros.c
 
 #include "routeros_api.h"
 
+#if !__GNUC__
+# define __attribute__(x) /**/
+#endif
+
 static const char *opt_username = "admin";
 
 static int result_handler (ros_connection_t *c, const ros_reply_t *r, /* {{{ */
@@ -78,7 +82,9 @@ static void regtable_dump (const ros_registration_table_t *r) /* {{{ */
        if (r == NULL)
                return;
 
-       printf ("=== %s ===\n", r->interface);
+       printf ("=== %s / %s ===\n", r->interface, r->radio_name);
+       printf ("Mode:           %12s\n",
+                       r->ap ? (r->wds ? "AP with WDS" : "Access point") : "Station");
        printf ("Rate:           %7g Mbps / %7g Mbps\n", r->rx_rate, r->tx_rate);
        printf ("Packets:        %12"PRIu64" / %12"PRIu64"\n",
                        r->rx_packets, r->tx_packets);
@@ -102,13 +108,53 @@ static void regtable_dump (const ros_registration_table_t *r) /* {{{ */
        regtable_dump (r->next);
 } /* }}} void regtable_dump */
 
-static int regtable_handler (ros_connection_t *c, /* {{{ */
-               const ros_registration_table_t *r, void *user_data)
+static int regtable_handler (__attribute__((unused)) ros_connection_t *c, /* {{{ */
+               const ros_registration_table_t *r,
+               __attribute__((unused)) void *user_data)
 {
        regtable_dump (r);
        return (0);
 } /* }}} int regtable_handler */
 
+static void interface_dump (const ros_interface_t *i) /* {{{ */
+{
+       if (i == NULL)
+               return;
+
+       printf ("=== %s ===\n"
+                       "Type:    %12s\n"
+                       "Comment: %12s\n"
+                       "Bytes:   %12"PRIu64" / %12"PRIu64"\n"
+                       "Packets: %12"PRIu64" / %12"PRIu64"\n"
+                       "Errors:  %12"PRIu64" / %12"PRIu64"\n"
+                       "Drops:   %12"PRIu64" / %12"PRIu64"\n"
+                       "MTU:     %12u\n"
+                       "L2 MTU:  %12u\n"
+                       "Running: %12s\n"
+                       "Dynamic: %12s\n"
+                       "Enabled: %12s\n"
+                       "==========\n",
+                       i->name, i->type, i->comment,
+                       i->rx_bytes, i->tx_bytes,
+                       i->rx_packets, i->tx_packets,
+                       i->rx_errors, i->tx_errors,
+                       i->rx_drops, i->tx_drops,
+                       i->mtu, i->l2mtu,
+                       i->running ? "true" : "false",
+                       i->dynamic ? "true" : "false",
+                       i->enabled ? "true" : "false");
+
+       interface_dump (i->next);
+} /* }}} void interface_dump */
+
+static int interface_handler (__attribute__((unused)) ros_connection_t *c, /* {{{ */
+               const ros_interface_t *i,
+               __attribute__((unused)) void *user_data)
+{
+       interface_dump (i);
+       return (0);
+} /* }}} int interface_handler */
+
 static char *read_password (void) /* {{{ */
 {
        FILE *tty;
@@ -230,6 +276,10 @@ int main (int argc, char **argv) /* {{{ */
                                (size_t) (argc - (optind + 2)), (const char * const *) (argv + optind + 2),
                                result_handler, /* user data = */ NULL);
        }
+       else if (strcmp ("interface", command) == 0)
+       {
+               ros_interface (c, interface_handler, /* user data = */ NULL);
+       }
        else if (strcmp ("registration-table", command) == 0)
        {
                ros_registration_table (c, regtable_handler, /* user data = */ NULL);