annotate rvinterf/old/etmsend.c @ 229:24ed817dd25d

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