FreeCalypso > hg > freecalypso-sw
comparison rvinterf/old/etmsend.c @ 173:f42854da4563
rvinterf: beginning of refactoring
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 22 Nov 2013 05:56:07 +0000 |
parents | rvinterf/etmsend.c@019120585a1c |
children |
comparison
equal
deleted
inserted
replaced
172:019120585a1c | 173:f42854da4563 |
---|---|
1 /* | |
2 * This program is a hack that sends a hand-crafted ETM packet | |
3 * to the UNIX-local dgram socket established by rvtdump with -s option. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <sys/socket.h> | |
8 #include <sys/un.h> | |
9 #include <stdio.h> | |
10 #include <string.h> | |
11 #include <strings.h> | |
12 #include <stdlib.h> | |
13 #include <unistd.h> | |
14 #include "pktmux.h" | |
15 #include "txpkt.h" | |
16 | |
17 char sockpath[] = "/tmp/rvt_send_socket"; | |
18 | |
19 u_char packet[MAX_PKT_TO_TARGET]; | |
20 int payload_len; | |
21 | |
22 main(argc, argv) | |
23 char **argv; | |
24 { | |
25 int i, c, s; | |
26 struct sockaddr_un local; | |
27 unsigned int namelen; | |
28 | |
29 if (argc < 2) { | |
30 fprintf(stderr, "usage: %s hexbytes...\n", argv[0]); | |
31 exit(1); | |
32 } | |
33 payload_len = argc - 1; | |
34 if (payload_len > MAX_PKT_TO_TARGET-2) { | |
35 fprintf(stderr, | |
36 "%s: too many bytes (packet length limit exceeded)\n", | |
37 argv[0]); | |
38 exit(1); | |
39 } | |
40 | |
41 packet[0] = RVT_TM_HEADER; | |
42 for (i = 1; i <= payload_len; i++) | |
43 packet[i] = strtoul(argv[i], 0, 16); | |
44 c = 0; | |
45 for (i = 1; i <= payload_len; i++) | |
46 c ^= packet[i]; | |
47 packet[payload_len+1] = c; | |
48 | |
49 s = socket(AF_UNIX, SOCK_DGRAM, 0); | |
50 if (s < 0) { | |
51 perror("socket(AF_UNIX, SOCK_DGRAM, 0)"); | |
52 exit(1); | |
53 } | |
54 | |
55 local.sun_family = AF_UNIX; | |
56 strncpy(local.sun_path, sockpath, sizeof(local.sun_path)); | |
57 local.sun_path[sizeof(local.sun_path) - 1] = '\0'; | |
58 | |
59 /* we use the same magic that X11 uses in Xtranssock.c for | |
60 * calculating the proper length of the sockaddr */ | |
61 #if defined(BSD44SOCKETS) || defined(__UNIXWARE__) | |
62 local.sun_len = strlen(local.sun_path); | |
63 #endif | |
64 #if defined(BSD44SOCKETS) || defined(SUN_LEN) | |
65 namelen = SUN_LEN(&local); | |
66 #else | |
67 namelen = strlen(local.sun_path) + | |
68 offsetof(struct sockaddr_un, sun_path); | |
69 #endif | |
70 | |
71 i = sendto(s, packet, payload_len+2, 0, | |
72 (struct sockaddr *) &local, namelen); | |
73 if (i < 0) { | |
74 perror("sendto"); | |
75 exit(1); | |
76 } | |
77 | |
78 exit(0); | |
79 } |