annotate rvinterf/misc/rvifsend.c @ 638:0b5f226bfdf4

gsm-fw/services/pcm: import from Leonardo source (FFS)
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 03 Sep 2014 16:26:27 +0000
parents 5d9001f0c3aa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
328
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module is currently linked by fc-sendsp, and may be used by
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * other similar hack-utilities in the future. Here we connect to
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 * rvinterf, send one packet to the target, and call it done.
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 */
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <sys/types.h>
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <sys/socket.h>
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <sys/un.h>
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <stdio.h>
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <string.h>
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include <strings.h>
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include <stdlib.h>
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include <unistd.h>
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 #include "localsock.h"
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 extern char *socket_pathname;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 send_pkt_to_target(pkt, pktlen)
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 u_char *pkt;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 unsigned pktlen;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 {
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 /* local socket binding voodoo copied from osmocon */
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 struct sockaddr_un local;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 unsigned int namelen;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 int sock, rc;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 u_char hdrbuf[3];
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 int len1;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 sock = socket(AF_UNIX, SOCK_STREAM, 0);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 if (sock < 0) {
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 perror("socket(AF_UNIX, SOCK_STREAM, 0)");
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 exit(1);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 }
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 local.sun_family = AF_UNIX;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 strncpy(local.sun_path, socket_pathname, sizeof(local.sun_path));
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 local.sun_path[sizeof(local.sun_path) - 1] = '\0';
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 /* we use the same magic that X11 uses in Xtranssock.c for
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 * calculating the proper length of the sockaddr */
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 #if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 local.sun_len = strlen(local.sun_path);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 #endif
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 #if defined(BSD44SOCKETS) || defined(SUN_LEN)
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 namelen = SUN_LEN(&local);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 #else
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 namelen = strlen(local.sun_path) +
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 offsetof(struct sockaddr_un, sun_path) + 1;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 #endif
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 rc = connect(sock, (struct sockaddr *) &local, namelen);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 if (rc != 0) {
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 perror(socket_pathname);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 exit(1);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 }
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 len1 = pktlen + 1;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 hdrbuf[0] = len1 >> 8;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 hdrbuf[1] = len1 & 0xFF;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 hdrbuf[2] = CLI2RVI_PKT_TO_TARGET;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 write(sock, hdrbuf, 3);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 write(sock, pkt, pktlen);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 close(sock);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 return(0);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 }