FreeCalypso > hg > freecalypso-hwlab
annotate lcdtest/connect.c @ 112:87d459d9797a
fc-simtool: pb-erase command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 26 Jan 2021 03:32:20 +0000 |
parents | de3d3cfcbb35 |
children |
rev | line source |
---|---|
28
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Connecting to an already running rvinterf process |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/socket.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/un.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <unistd.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <rvinterf/localsock.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "exitcodes.h" |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char *socket_pathname = "/tmp/rvinterf_socket"; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int sock; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 connect_local_socket() |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 /* local socket binding voodoo copied from osmocon */ |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 struct sockaddr_un local; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 unsigned int namelen; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 int rc; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 sock = socket(AF_UNIX, SOCK_STREAM, 0); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (sock < 0) { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 perror("socket(AF_UNIX, SOCK_STREAM, 0)"); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 exit(ERROR_UNIX); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 local.sun_family = AF_UNIX; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 strncpy(local.sun_path, socket_pathname, sizeof(local.sun_path)); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 local.sun_path[sizeof(local.sun_path) - 1] = '\0'; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 /* we use the same magic that X11 uses in Xtranssock.c for |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 * calculating the proper length of the sockaddr */ |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 #if defined(BSD44SOCKETS) || defined(__UNIXWARE__) |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 local.sun_len = strlen(local.sun_path); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 #endif |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 #if defined(BSD44SOCKETS) || defined(SUN_LEN) |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 namelen = SUN_LEN(&local); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 #else |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 namelen = strlen(local.sun_path) + |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 offsetof(struct sockaddr_un, sun_path) + 1; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 #endif |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 rc = connect(sock, (struct sockaddr *) &local, namelen); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 if (rc != 0) { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 perror(socket_pathname); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 exit(ERROR_RVINTERF); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 return(0); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |