]> rtime.felk.cvut.cz Git - sojka/can-utils.git/blobdiff - cansend.c
slcan_attach: 'close' the slcan adapter before setting a bitrate
[sojka/can-utils.git] / cansend.c
index dc22364aa6fc22b54938c5f9ee9a22b3673f7080..a2fefc2e279696ccfd56e632af1eac1f133dd542 100644 (file)
--- a/cansend.c
+++ b/cansend.c
@@ -12,8 +12,7 @@
  * modification, are permitted provided that the following conditions
  * are met:
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, the following disclaimer and
- *    the referenced file 'COPYING'.
+ *    notice, this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
@@ -23,8 +22,8 @@
  *
  * Alternatively, provided that this notice is retained in full, this
  * software may be distributed under the terms of the GNU General
- * Public License ("GPL") version 2 as distributed in the 'COPYING'
- * file from the main directory of the linux kernel source.
+ * Public License ("GPL") version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
  *
  * The provided data structures and external interfaces from this code
  * are not restricted to be used by modules with a GPL compatible license.
 
 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;
 }