FreeCalypso > hg > freecalypso-sw
annotate rvinterf/etmsync/connect.c @ 360:f9d78057d766
tfc139 hack works!
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Thu, 15 May 2014 11:09:45 +0000 |
parents | 909f00c15f27 |
children | 7b805007dcfc |
rev | line source |
---|---|
275
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * Connecting to an already running rvinterf process |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <sys/socket.h> |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <sys/un.h> |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdio.h> |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <string.h> |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <strings.h> |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <stdlib.h> |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include <unistd.h> |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "pktmux.h" |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "localsock.h" |
276
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
15 #include "exitcodes.h" |
275
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 extern char *socket_pathname; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 extern int sock; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 connect_local_socket() |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 { |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 /* local socket binding voodoo copied from osmocon */ |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 struct sockaddr_un local; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 unsigned int namelen; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 int rc; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 sock = socket(AF_UNIX, SOCK_STREAM, 0); |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 if (sock < 0) { |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 perror("socket(AF_UNIX, SOCK_STREAM, 0)"); |
276
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
30 exit(ERROR_UNIX); |
275
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 } |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 local.sun_family = AF_UNIX; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 strncpy(local.sun_path, socket_pathname, sizeof(local.sun_path)); |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 local.sun_path[sizeof(local.sun_path) - 1] = '\0'; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 /* we use the same magic that X11 uses in Xtranssock.c for |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 * calculating the proper length of the sockaddr */ |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 #if defined(BSD44SOCKETS) || defined(__UNIXWARE__) |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 local.sun_len = strlen(local.sun_path); |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 #endif |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 #if defined(BSD44SOCKETS) || defined(SUN_LEN) |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 namelen = SUN_LEN(&local); |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 #else |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 namelen = strlen(local.sun_path) + |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 offsetof(struct sockaddr_un, sun_path) + 1; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 #endif |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 rc = connect(sock, (struct sockaddr *) &local, namelen); |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 if (rc != 0) { |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 perror(socket_pathname); |
276
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
52 exit(ERROR_RVINTERF); |
275
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 } |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 return(0); |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 } |