]> rtime.felk.cvut.cz Git - socketcan-devel.git/blobdiff - can-utils/cangw.c
Rework of help text.
[socketcan-devel.git] / can-utils / cangw.c
index c03535c658e84a51a943e6758fb9daf48eb90750..a3681cf13e8246f9ed67c5ca639550a20ecfcf27 100644 (file)
@@ -99,7 +99,7 @@ void printfilter(const void *data)
 {
        struct can_filter *filter = (struct can_filter *)data;
 
-       printf("-f %X:%X ", filter->can_id, filter->can_mask);
+       printf("-f %03X:%X ", filter->can_id, filter->can_mask);
 }
 
 void printmod(const char *type, const void *data)
@@ -120,7 +120,7 @@ void printmod(const char *type, const void *data)
        if (mod.modtype & CGW_MOD_DATA)
                printf("D");
 
-       printf(":%X.%X.", mod.cf.can_id, mod.cf.can_dlc);
+       printf(":%03X.%X.", mod.cf.can_id, mod.cf.can_dlc);
 
        for (i = 0; i < 8; i++)
                printf("%02X", mod.cf.data[i]);
@@ -134,7 +134,7 @@ void print_usage(char *prg)
        fprintf(stderr, "\nUsage: %s [options]\n\n", prg);
        fprintf(stderr, "Commands:  -A (add a new rule)\n");
        fprintf(stderr, "           -D (delete a rule)\n");
-       fprintf(stderr, "           -F (flush - delete all rules)  [not yet implemented]\n");
+       fprintf(stderr, "           -F (flush / delete all rules)\n");
        fprintf(stderr, "           -L (list all rules)\n");
        fprintf(stderr, "Mandatory: -s <src_dev>  (source netdevice)\n");
        fprintf(stderr, "           -d <dst_dev>  (destination netdevice)\n");
@@ -153,10 +153,10 @@ void print_usage(char *prg)
        fprintf(stderr, " - <can_id> is an u32 value containing the CAN Identifier\n");
        fprintf(stderr, " - <can_dlc> is an u8 value containing the data length code (0 .. 8)\n");
        fprintf(stderr, " - <can_data> is always eight(!) u8 values containing the CAN frames data\n");
-       fprintf(stderr, "The instructions are performed in the order 'AND' -> 'OR' -> 'XOR' -> 'SET'\n");
+       fprintf(stderr, "The max. four modifications are performed in the order AND -> OR -> XOR -> SET\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "Example:\n");
-       fprintf(stderr, "%s -A -s can0 -d vcan3 -f 123:C00007FF -m SET:IL:80000333.4.1122334455667788\n", prg);
+       fprintf(stderr, "%s -A -s can0 -d vcan3 -e -f 123:C00007FF -m SET:IL:333.4.1122334455667788\n", prg);
        fprintf(stderr, "\n");
 }
 
@@ -365,6 +365,14 @@ int main(int argc, char **argv)
                req.nh.nlmsg_type  = RTM_DELROUTE;
                break;
 
+       case FLUSH:
+               req.nh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
+               req.nh.nlmsg_type  = RTM_DELROUTE;
+               /* if_index set to 0 => remove all entries */
+               req.rtcan.src_ifindex  = 0;
+               req.rtcan.dst_ifindex  = 0;
+               break;
+
        case LIST:
                req.nh.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
                req.nh.nlmsg_type  = RTM_GETROUTE;
@@ -411,7 +419,13 @@ int main(int argc, char **argv)
        /* clean netlink receive buffer */
        bzero(rxbuf, sizeof(rxbuf));
 
-       if (cmd == ADD || cmd == DEL) {
+       if (cmd != LIST) {
+
+               /*
+                * cmd == ADD || cmd == DEL || cmd == FLUSH
+                *
+                * Parse the requested netlink acknowledge return values.
+                */
 
                err = recv(s, &rxbuf, sizeof(rxbuf), 0);
                if (err < 0) {
@@ -430,7 +444,7 @@ int main(int argc, char **argv)
 
        } else {
 
-               /* cmd == LIST (for now) */
+               /* cmd == LIST */
 
                while (1) {
                        len = recv(s, &rxbuf, sizeof(rxbuf), 0);