comparison rvinterf/libasync/init.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 09b4fd9b3827
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * This module contains the common initialization code for fc-tmsh and g23sh.
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 }