-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
47 lines (35 loc) · 814 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include"control.h"
#include"run.c"
#include<net/if.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<sys/ioctl.h>
#include<linux/can.h>
#include<linux/can/raw.h>
char o, s;
struct sockaddr_can addr;
struct ifreq ifr;
char dct(dct_ _d)
{
if (!*(long *)_d) return 1;
struct can_frame frame;
frame.can_id = 0x123;
frame.can_dlc = sizeof(_d);
strncpy(frame.data, _d, sizeof(_d));
return write(s, &frame, sizeof(frame));
}
int main()
{
if (s = socket(PF_CAN, SOCK_RAW, CAN_RAW > 0)
return s;
strcpy(ifr.ifr_name, "can0");
ioctl(s, SIOCGIFINDEX, &ifr);
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
if (o = bind(s, (struct sockaddr *)&addr, sizeof(addr)) > 0)
return 256 + o;
if (o = start()) return 512 + o;
while (!(o = run()))
usleep(r_fq);
return o - 1;
}