#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
-#include "canethgw.h"
+#include <linux/can/canethgw.h>
unsigned int cegw_errno = 0;
perr("not enough arguments");
printf(help_msg, argv[0], argv[0]);
/* ToDo: print usage */
- return -1;
+ return 1;
}
dstcnt = argc-3;
if (tmpi == 0) {
perr("given can interface not found");
free(gwctl);
- return -1;
+ return 1;
}
can_addr.can_ifindex = tmpi;
break;
if (read_addrport(argv[i], &udp_addr.sin_addr, &port) != 0) {
perr("listening address mismatch");
free(gwctl);
- return -1;
+ return 1;
}
udp_addr.sin_port = htons(port);
break;
if (read_addrport(argv[i], &dst->sin_addr, &port) != 0) {
perr("udp destination mismatch");
free(gwctl);
- return -1;
+ return 1;
}
dst->sin_port = htons(port);
break;
if (udp_sock == -1) {
perror("udp socket()");
free(gwctl);
- return -1;
+ return 1;
}
if (bind(udp_sock, (struct sockaddr *)&udp_addr, sizeof(struct sockaddr_in)) != 0) {
perror("bind(udp)");
free(gwctl);
- return -1;
+ return 1;
}
/* prepare can socket */
if (can_sock == -1) {
perror("can socket()");
free(gwctl);
- return -1;
+ return 1;
}
if (bind(can_sock, (struct sockaddr *)&can_addr, sizeof(struct sockaddr_can)) != 0) {
perror("bind(can)");
free(gwctl);
- return -1;
+ return 1;
}
/* send it to kernel gateway */
if (fd == -1) {
perror("/dev/canethgw");
free(gwctl);
- return -1;
+ return 1;
}
gwctl->can_sock = can_sock;
gwctl->udp_addrlen = sizeof(struct sockaddr_in);
if (ioctl(fd, CEGW_IOCTL_START, gwctl) != 0) {
- perror(NULL);
+ perror("ioctl");
free(gwctl);
- return -1;
+ return 1;
}
printf("gateway successfully set and running\n");
free(gwctl);
/* sleep until someone kills me */
- while (1) {
- sleep(UINT_MAX);
- }
+ pause();
return 0;
}