]> rtime.felk.cvut.cz Git - socketcan-devel.git/blobdiff - can-utils/cansend.c
Whitespace fixes. Indented the code following Linux styleguide to fix
[socketcan-devel.git] / can-utils / cansend.c
index 10d24c72745017fbb23a5fe56404b9a83a4b8817..a2fefc2e279696ccfd56e632af1eac1f133dd542 100644 (file)
 
 int main(int argc, char **argv)
 {
-    int s; /* can raw socket */ 
-    int nbytes;
-    struct sockaddr_can addr;
-    struct can_frame frame;
-    struct ifreq ifr;
-
-    /* check command line options */
-    if (argc != 3) {
-        fprintf(stderr, "Usage: %s <device> <can_frame>.\n", argv[0]);
-        return 1;
-    }
-
-    /* parse CAN frame */
-    if (parse_canframe(argv[2], &frame)){
-       fprintf(stderr, "\nWrong CAN-frame format!\n\n");
-       fprintf(stderr, "Try: <can_id>#{R|data}\n");
-       fprintf(stderr, "can_id can have 3 (SFF) or 8 (EFF) hex chars\n");
-       fprintf(stderr, "data has 0 to 8 hex-values that can (optionally)");
-       fprintf(stderr, " be seperated by '.'\n\n");
-       fprintf(stderr, "e.g. 5A1#11.2233.44556677.88 / 123#DEADBEEF / ");
-       fprintf(stderr, "5AA# /\n     1F334455#1122334455667788 / 123#R ");
-       fprintf(stderr, "for remote transmission request.\n\n");
-       return 1;
-    }
-
-    /* open socket */
-    if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
-      perror("socket");
-      return 1;
-    }
-
-    addr.can_family = AF_CAN;
-
-    strcpy(ifr.ifr_name, argv[1]);
-    if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
-      perror("SIOCGIFINDEX");
-      return 1;
-    }
-    addr.can_ifindex = ifr.ifr_ifindex;
-
-    /* disable default receive filter on this RAW socket */
-    /* This is obsolete as we do not read from the socket at all, but for */
-    /* this reason we can remove the receive list in the Kernel to save a */
-    /* little (really a very little!) CPU usage.                          */
-    setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
-
-    if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
-      perror("bind");
-      return 1;
-    }
-
-    /* send frame */
-    if ((nbytes = write(s, &frame, sizeof(frame))) != sizeof(frame)) {
-      perror("write");
-      return 1;
-    }
-
-    //fprint_long_canframe(stdout, &frame, "\n", 0);
-
-    close(s);
-
-    return 0;
+       int s; /* can raw socket */ 
+       int nbytes;
+       struct sockaddr_can addr;
+       struct can_frame frame;
+       struct ifreq ifr;
+
+       /* check command line options */
+       if (argc != 3) {
+               fprintf(stderr, "Usage: %s <device> <can_frame>.\n", argv[0]);
+               return 1;
+       }
+
+       /* parse CAN frame */
+       if (parse_canframe(argv[2], &frame)){
+               fprintf(stderr, "\nWrong CAN-frame format!\n\n");
+               fprintf(stderr, "Try: <can_id>#{R|data}\n");
+               fprintf(stderr, "can_id can have 3 (SFF) or 8 (EFF) hex chars\n");
+               fprintf(stderr, "data has 0 to 8 hex-values that can (optionally)");
+               fprintf(stderr, " be seperated by '.'\n\n");
+               fprintf(stderr, "e.g. 5A1#11.2233.44556677.88 / 123#DEADBEEF / ");
+               fprintf(stderr, "5AA# /\n     1F334455#1122334455667788 / 123#R ");
+               fprintf(stderr, "for remote transmission request.\n\n");
+               return 1;
+       }
+
+       /* open socket */
+       if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
+               perror("socket");
+               return 1;
+       }
+
+       addr.can_family = AF_CAN;
+
+       strcpy(ifr.ifr_name, argv[1]);
+       if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
+               perror("SIOCGIFINDEX");
+               return 1;
+       }
+       addr.can_ifindex = ifr.ifr_ifindex;
+
+       /* disable default receive filter on this RAW socket */
+       /* This is obsolete as we do not read from the socket at all, but for */
+       /* this reason we can remove the receive list in the Kernel to save a */
+       /* little (really a very little!) CPU usage.                          */
+       setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
+
+       if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+               perror("bind");
+               return 1;
+       }
+
+       /* send frame */
+       if ((nbytes = write(s, &frame, sizeof(frame))) != sizeof(frame)) {
+               perror("write");
+               return 1;
+       }
+
+       //fprint_long_canframe(stdout, &frame, "\n", 0);
+
+       close(s);
+
+       return 0;
 }