comparison pircharge/init.c @ 228:fec90990f613

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