/*
- * $Id: tst-raw-sendto.c,v 2.0 2006/04/13 10:37:21 ethuerm Exp $
+ * $Id$
*/
/*
* tst-raw-sendto.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.
*
* 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.
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
- * Send feedback to <llcf@volkswagen.de>
+ * Send feedback to <socketcan-users@lists.berlios.de>
*
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <net/if.h>
-#include "af_can.h"
-#include "raw.h"
+#include <linux/can.h>
+#include <linux/can/raw.h>
int main(int argc, char **argv)
{
- int s;
- struct sockaddr_can addr;
- struct can_frame frame;
- int nbytes;
- struct ifreq ifr;
- char *ifname = "vcan2";
- int ifindex;
- int opt;
+ int s;
+ struct sockaddr_can addr;
+ struct can_frame frame;
+ struct ifreq ifr;
+ char *ifname = "vcan2";
+ int ifindex;
+ int opt;
- while ((opt = getopt(argc, argv, "i:")) != -1) {
- switch (opt) {
- case 'i':
- ifname = optarg;
- break;
- default:
- fprintf(stderr, "Unknown option %c\n", opt);
- break;
- }
- }
+ while ((opt = getopt(argc, argv, "i:")) != -1) {
+ switch (opt) {
+ case 'i':
+ ifname = optarg;
+ break;
+ default:
+ fprintf(stderr, "Unknown option %c\n", opt);
+ break;
+ }
+ }
- if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
- perror("socket");
- return 1;
- }
+ if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
+ perror("socket");
+ return 1;
+ }
- strcpy(ifr.ifr_name, ifname);
- ioctl(s, SIOCGIFINDEX, &ifr);
- ifindex = ifr.ifr_ifindex;
+ strcpy(ifr.ifr_name, ifname);
+ ioctl(s, SIOCGIFINDEX, &ifr);
+ ifindex = ifr.ifr_ifindex;
- addr.can_family = AF_CAN;
- addr.can_ifindex = 0; /* bind to all interfaces */
+ addr.can_family = AF_CAN;
+ addr.can_ifindex = 0; /* bind to all interfaces */
- if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
- perror("bind");
- return 1;
- }
+ if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ perror("bind");
+ return 1;
+ }
- /* fill CAN frame */
- frame.can_id = 0x123;
- frame.can_dlc = 3;
- frame.data[0] = 0x11;
- frame.data[1] = 0x22;
- frame.data[2] = 0x33;
+ /* fill CAN frame */
+ frame.can_id = 0x123;
+ frame.can_dlc = 3;
+ frame.data[0] = 0x11;
+ frame.data[1] = 0x22;
+ frame.data[2] = 0x33;
- addr.can_family = AF_CAN;
- addr.can_ifindex = ifindex; /* send via this interface */
+ addr.can_family = AF_CAN;
+ addr.can_ifindex = ifindex; /* send via this interface */
- nbytes = sendto(s, &frame, sizeof(struct can_frame), 0, (struct sockaddr*)&addr, sizeof(addr));
+ sendto(s, &frame, sizeof(struct can_frame), 0, (struct sockaddr*)&addr, sizeof(addr));
- close(s);
+ close(s);
- return 0;
+ return 0;
}