comparison rvinterf/etm/init.c @ 182:13a0348ffce4

rvinterf/etm: checkpointing not-yet-compilable code
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 24 Nov 2013 06:59:09 +0000
parents
children fa7174faa9aa
comparison
equal deleted inserted replaced
181:6800c2cc8c51 182:13a0348ffce4
1 /*
2 * This module contains the initialization code for fc-tmsh.
3 */
4
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <sys/un.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <strings.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include "../pktmux.h"
14 #include "../localsock.h"
15
16 extern char *socket_pathname;
17 extern int sock;
18
19 connect_local_socket()
20 {
21 /* local socket binding voodoo copied from osmocon */
22 struct sockaddr_un local;
23 unsigned int namelen;
24 int rc;
25
26 sock = socket(AF_UNIX, SOCK_STREAM, 0);
27 if (sock < 0) {
28 perror("socket(AF_UNIX, SOCK_STREAM, 0)");
29 exit(1);
30 }
31
32 local.sun_family = AF_UNIX;
33 strncpy(local.sun_path, socket_pathname, sizeof(local.sun_path));
34 local.sun_path[sizeof(local.sun_path) - 1] = '\0';
35
36 /* we use the same magic that X11 uses in Xtranssock.c for
37 * calculating the proper length of the sockaddr */
38 #if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
39 local.sun_len = strlen(local.sun_path);
40 #endif
41 #if defined(BSD44SOCKETS) || defined(SUN_LEN)
42 namelen = SUN_LEN(&local);
43 #else
44 namelen = strlen(local.sun_path) +
45 offsetof(struct sockaddr_un, sun_path) + 1;
46 #endif
47
48 rc = connect(sock, (struct sockaddr *) &local, namelen);
49 if (rc != 0) {
50 perror(socket_pathname);
51 exit(1);
52 }
53
54 return(0);
55 }
56
57 send_init_command(cmdpkt, cmdlen)
58 u_char *cmdpkt;
59 {
60 u_char lenbuf[2];
61
62 lenbuf[0] = 0;
63 lenbuf[1] = cmdlen;
64 write(sock, lenbuf, 2);
65 write(sock, cmdpkt, cmdlen);
66 }
67
68 init()
69 {
70 static u_char want_rvt_lost[9] = {CLI2RVI_WANT_RVTRACE,
71 0xFF, 0xFF, 0xFF, 0xFF,
72 0x00, 0x00, 0x00, 0x00};
73 static u_char want_rvt_etm[9] = {CLI2RVI_WANT_RVTRACE,
74 0xFF, 0xFF, 0xFF, 0xFF,
75 0x00, 0x1E, 0x00, 0x04};
76 static u_char want_etm_mux[2] = {CLI2RVI_WANT_MUXPROTO, RVT_TM_HEADER};
77
78 connect_local_socket();
79 localsock_prep_for_length_rx();
80 send_init_command(want_rvt_lost, 9);
81 send_init_command(want_rvt_etm, 9);
82 send_init_command(want_etm_mux, 2);
83 }