]> rtime.felk.cvut.cz Git - socketcan-devel.git/blobdiff - test/tst-bcm-cycle.c
Add kernel version depency for Kernel 3.1.x which extended __rtnl_register().
[socketcan-devel.git] / test / tst-bcm-cycle.c
index 4871b031f4da83ae06b2664689cabc0427bb7377..3d2a352f415a9e63865ba18787a07b35bae575d1 100644 (file)
@@ -5,15 +5,14 @@
 /*
  * tst-bcm-cycle.c
  *
- * Copyright (c) 2002-2005 Volkswagen Group Electronic Research
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * 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.
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <sys/uio.h>
+#include <net/if.h>
 
-#include "af_can.h"
-#include "bcm.h"
+#include <linux/can.h>
+#include <linux/can/bcm.h>
 
 #define U64_DATA(p) (*(unsigned long long*)(p)->data)
 
 int main(int argc, char **argv)
 {
-    int s;
-    struct sockaddr_can addr;
-    struct ifreq ifr;
-
-    struct {
-      struct bcm_msg_head msg_head;
-      struct can_frame frame[4];
-    } msg;
-
-    if ((s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM)) < 0) {
-       perror("socket");
-       return 1;
-    }
-
-    addr.can_family = PF_CAN;
-    strcpy(ifr.ifr_name, "vcan2");
-    ioctl(s, SIOCGIFINDEX, &ifr);
-    addr.can_ifindex = ifr.ifr_ifindex;
-
-    if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
-       perror("connect");
-       return 1;
-    }
-
-    msg.msg_head.opcode  = TX_SETUP;
-    msg.msg_head.can_id  = 0x42;
-    msg.msg_head.flags   = SETTIMER|STARTTIMER;
-    msg.msg_head.nframes = 1;
-    msg.msg_head.count = 10;
-    msg.msg_head.ival1.tv_sec = 1;
-    msg.msg_head.ival1.tv_usec = 0;
-    msg.msg_head.ival2.tv_sec = 0;
-    msg.msg_head.ival2.tv_usec = 0;
-    msg.frame[0].can_id    = 0x42;
-    msg.frame[0].can_dlc   = 8;
-    U64_DATA(&msg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL;
-
-    if (write(s, &msg, sizeof(msg)) < 0)
-      perror("write");
-
-    printf("Press any key to stop the cycle ...\n");
-
-    getchar();
-
-    msg.msg_head.opcode  = TX_SETUP;
-    msg.msg_head.can_id  = 0x42;
-    msg.msg_head.flags   = SETTIMER|STARTTIMER;
-    msg.msg_head.nframes = 1;
-    msg.msg_head.count = 0;
-    msg.msg_head.ival1.tv_sec = 0;
-    msg.msg_head.ival1.tv_usec = 0;
-    msg.msg_head.ival2.tv_sec = 0;
-    msg.msg_head.ival2.tv_usec = 0;
-    msg.frame[0].can_id    = 0x42;
-    msg.frame[0].can_dlc   = 8;
-    U64_DATA(&msg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL;
-
-    if (write(s, &msg, sizeof(msg)) < 0)
-      perror("write");
-
-    printf("Press any key to close the socket ...\n");
-
-    getchar();
-
-    close(s);
-
-    printf("Press any key to end the program ...\n");
-
-    getchar();
-
-    return 0;
+       int s;
+       struct sockaddr_can addr;
+       struct ifreq ifr;
+
+       struct {
+               struct bcm_msg_head msg_head;
+               struct can_frame frame[4];
+       } msg;
+
+       if ((s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM)) < 0) {
+               perror("socket");
+               return 1;
+       }
+
+       addr.can_family = PF_CAN;
+       strcpy(ifr.ifr_name, "vcan2");
+       ioctl(s, SIOCGIFINDEX, &ifr);
+       addr.can_ifindex = ifr.ifr_ifindex;
+
+       if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+               perror("connect");
+               return 1;
+       }
+
+       msg.msg_head.opcode  = TX_SETUP;
+       msg.msg_head.can_id  = 0x42;
+       msg.msg_head.flags   = SETTIMER|STARTTIMER;
+       msg.msg_head.nframes = 1;
+       msg.msg_head.count = 10;
+       msg.msg_head.ival1.tv_sec = 1;
+       msg.msg_head.ival1.tv_usec = 0;
+       msg.msg_head.ival2.tv_sec = 0;
+       msg.msg_head.ival2.tv_usec = 0;
+       msg.frame[0].can_id    = 0x42;
+       msg.frame[0].can_dlc   = 8;
+       U64_DATA(&msg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL;
+
+       if (write(s, &msg, sizeof(msg)) < 0)
+               perror("write");
+
+       printf("Press any key to stop the cycle ...\n");
+
+       getchar();
+
+       msg.msg_head.opcode  = TX_SETUP;
+       msg.msg_head.can_id  = 0x42;
+       msg.msg_head.flags   = SETTIMER|STARTTIMER;
+       msg.msg_head.nframes = 1;
+       msg.msg_head.count = 0;
+       msg.msg_head.ival1.tv_sec = 0;
+       msg.msg_head.ival1.tv_usec = 0;
+       msg.msg_head.ival2.tv_sec = 0;
+       msg.msg_head.ival2.tv_usec = 0;
+       msg.frame[0].can_id    = 0x42;
+       msg.frame[0].can_dlc   = 8;
+       U64_DATA(&msg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL;
+
+       if (write(s, &msg, sizeof(msg)) < 0)
+               perror("write");
+
+       printf("Press any key to close the socket ...\n");
+
+       getchar();
+
+       close(s);
+
+       printf("Press any key to end the program ...\n");
+
+       getchar();
+
+       return 0;
 }