comparison rvinterf/old/sendsp/rvifsend.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * This module is currently linked by fc-sendsp, and may be used by
3 * other similar hack-utilities in the future. Here we connect to
4 * rvinterf, send one packet to the target, and call it done.
5 */
6
7 #include <sys/types.h>
8 #include <sys/socket.h>
9 #include <sys/un.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <strings.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include "localsock.h"
16
17 extern char *socket_pathname;
18
19 send_pkt_to_target(pkt, pktlen)
20 u_char *pkt;
21 unsigned pktlen;
22 {
23 /* local socket binding voodoo copied from osmocon */
24 struct sockaddr_un local;
25 unsigned int namelen;
26 int sock, rc;
27 u_char hdrbuf[3];
28 int len1;
29
30 sock = socket(AF_UNIX, SOCK_STREAM, 0);
31 if (sock < 0) {
32 perror("socket(AF_UNIX, SOCK_STREAM, 0)");
33 exit(1);
34 }
35
36 local.sun_family = AF_UNIX;
37 strncpy(local.sun_path, socket_pathname, sizeof(local.sun_path));
38 local.sun_path[sizeof(local.sun_path) - 1] = '\0';
39
40 /* we use the same magic that X11 uses in Xtranssock.c for
41 * calculating the proper length of the sockaddr */
42 #if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
43 local.sun_len = strlen(local.sun_path);
44 #endif
45 #if defined(BSD44SOCKETS) || defined(SUN_LEN)
46 namelen = SUN_LEN(&local);
47 #else
48 namelen = strlen(local.sun_path) +
49 offsetof(struct sockaddr_un, sun_path) + 1;
50 #endif
51
52 rc = connect(sock, (struct sockaddr *) &local, namelen);
53 if (rc != 0) {
54 perror(socket_pathname);
55 exit(1);
56 }
57
58 len1 = pktlen + 1;
59 hdrbuf[0] = len1 >> 8;
60 hdrbuf[1] = len1 & 0xFF;
61 hdrbuf[2] = CLI2RVI_PKT_TO_TARGET;
62 write(sock, hdrbuf, 3);
63 write(sock, pkt, pktlen);
64 close(sock);
65 return(0);
66 }