comparison rvinterf/etmsync/connect.c @ 275:cedf09b6b5ac

started laying the foundation for fc-fsio host utility
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 23 Feb 2014 20:27:15 +0000
parents
children 909f00c15f27
comparison
equal deleted inserted replaced
274:e3f17ff16915 275:cedf09b6b5ac
1 /*
2 * Connecting to an already running rvinterf process
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 }