FreeCalypso > hg > fc-rfcal-tools
comparison autocal/tsidsock.c @ 14:93e5194e5511
autocal/tsidsock.c written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 21 May 2017 23:00:32 +0000 |
parents | |
children | f67f46e56355 |
comparison
equal
deleted
inserted
replaced
13:d7e436bf4876 | 14:93e5194e5511 |
---|---|
1 /* | |
2 * TSID local socket interface | |
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 <rvinterf/exitcodes.h> | |
14 | |
15 char *tsid_socket_pathname = "/tmp/fc_rftest_socket"; | |
16 int tsid_socket; | |
17 | |
18 connect_tsid_socket() | |
19 { | |
20 /* local socket binding voodoo copied from osmocon */ | |
21 struct sockaddr_un local; | |
22 unsigned int namelen; | |
23 int rc; | |
24 | |
25 tsid_socket = socket(AF_UNIX, SOCK_STREAM, 0); | |
26 if (tsid_socket < 0) { | |
27 perror("socket(AF_UNIX, SOCK_STREAM, 0)"); | |
28 exit(ERROR_UNIX); | |
29 } | |
30 | |
31 local.sun_family = AF_UNIX; | |
32 strncpy(local.sun_path, tsid_socket_pathname, sizeof(local.sun_path)); | |
33 local.sun_path[sizeof(local.sun_path) - 1] = '\0'; | |
34 | |
35 /* we use the same magic that X11 uses in Xtranssock.c for | |
36 * calculating the proper length of the sockaddr */ | |
37 #if defined(BSD44SOCKETS) || defined(__UNIXWARE__) | |
38 local.sun_len = strlen(local.sun_path); | |
39 #endif | |
40 #if defined(BSD44SOCKETS) || defined(SUN_LEN) | |
41 namelen = SUN_LEN(&local); | |
42 #else | |
43 namelen = strlen(local.sun_path) + | |
44 offsetof(struct sockaddr_un, sun_path) + 1; | |
45 #endif | |
46 | |
47 rc = connect(tsid_socket, (struct sockaddr *) &local, namelen); | |
48 if (rc != 0) { | |
49 perror(tsid_socket_pathname); | |
50 exit(ERROR_RFTEST); | |
51 } | |
52 | |
53 return(0); | |
54 } |