comparison rvinterf/libasync/init.c @ 422:c1aadfcd185f

rvinterf client refactoring: libasync clients converted to use libinterf
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 28 Oct 2018 00:00:51 +0000
parents 09b4fd9b3827
children
comparison
equal deleted inserted replaced
421:ab8fb95a28da 422:c1aadfcd185f
1 /* 1 /*
2 * This module contains the common initialization code for fc-shell and fc-tmsh. 2 * This module contains some common initialization code
3 * for fc-shell and fc-tmsh.
3 */ 4 */
4 5
5 #include <sys/types.h> 6 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <sys/un.h>
8 #include <stdio.h> 7 #include <stdio.h>
9 #include <string.h>
10 #include <strings.h>
11 #include <stdlib.h> 8 #include <stdlib.h>
12 #include <unistd.h> 9 #include <unistd.h>
13 #include "pktmux.h"
14 #include "localsock.h"
15 #include "exitcodes.h"
16 10
17 extern char *socket_pathname;
18 extern int sock; 11 extern int sock;
19
20 connect_local_socket()
21 {
22 /* local socket binding voodoo copied from osmocon */
23 struct sockaddr_un local;
24 unsigned int namelen;
25 int rc;
26
27 sock = socket(AF_UNIX, SOCK_STREAM, 0);
28 if (sock < 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, 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(sock, (struct sockaddr *) &local, namelen);
50 if (rc != 0) {
51 perror(socket_pathname);
52 exit(ERROR_RVINTERF);
53 }
54
55 return(0);
56 }
57 12
58 send_init_command(cmdpkt, cmdlen) 13 send_init_command(cmdpkt, cmdlen)
59 u_char *cmdpkt; 14 u_char *cmdpkt;
60 { 15 {
61 u_char lenbuf[2]; 16 u_char lenbuf[2];