228
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <sys/socket.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <sys/un.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <stdio.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <string.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <strings.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <unistd.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <rvinterf/pktmux.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <rvinterf/localsock.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <rvinterf/exitcodes.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern char *socket_pathname;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern int sock;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 connect_local_socket()
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 /* local socket binding voodoo copied from osmocon */
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 struct sockaddr_un local;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 unsigned int namelen;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 int rc;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (sock < 0) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 perror("socket(AF_UNIX, SOCK_STREAM, 0)");
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 exit(ERROR_UNIX);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 local.sun_family = AF_UNIX;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 strncpy(local.sun_path, socket_pathname, sizeof(local.sun_path));
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 local.sun_path[sizeof(local.sun_path) - 1] = '\0';
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 /* we use the same magic that X11 uses in Xtranssock.c for
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 * calculating the proper length of the sockaddr */
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 #if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 local.sun_len = strlen(local.sun_path);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 #endif
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 #if defined(BSD44SOCKETS) || defined(SUN_LEN)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 namelen = SUN_LEN(&local);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 #else
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 namelen = strlen(local.sun_path) +
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 offsetof(struct sockaddr_un, sun_path) + 1;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 #endif
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 rc = connect(sock, (struct sockaddr *) &local, namelen);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (rc != 0) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 perror(socket_pathname);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 exit(ERROR_RVINTERF);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 return(0);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 send_init_command(cmdpkt, cmdlen)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 u_char *cmdpkt;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 u_char lenbuf[2];
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 lenbuf[0] = 0;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 lenbuf[1] = cmdlen;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 write(sock, lenbuf, 2);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 write(sock, cmdpkt, cmdlen);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 init()
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 static u_char want_rvt_lost[9] = {CLI2RVI_WANT_RVTRACE,
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 0xFF, 0xFF, 0xFF, 0xFF,
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 0x00, 0x00, 0x00, 0x00};
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 static u_char want_rvt_drv[9] = {CLI2RVI_WANT_RVTRACE,
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 0xFF, 0xFF, 0xFF, 0xC7,
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 0x00, 0x0A, 0x00, 0x00};
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 static u_char want_rvt_lls[9] = {CLI2RVI_WANT_RVTRACE,
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 0xFF, 0xFF, 0xFF, 0xFF,
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 0x00, 0x1E, 0x00, 0x40};
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 static u_char want_etm_mux[2] = {CLI2RVI_WANT_MUXPROTO, RVT_TM_HEADER};
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 localsock_prep_for_length_rx();
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 send_init_command(want_rvt_lost, 9);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 send_init_command(want_rvt_drv, 9);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 send_init_command(want_rvt_lls, 9);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 send_init_command(want_etm_mux, 2);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 }
|