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