comparison rvinterf/old/before-rvinterf/rvtdump_tx.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 contains the implementation of the Tx extension to rvtdump
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 "txpkt.h"
14
15 static char sockpath[] = "/tmp/rvt_send_socket";
16
17 int sendsock_fd;
18 u_char sendsock_pkt[MAX_PKT_TO_TARGET];
19 int sendsock_pktlen;
20
21 create_send_socket()
22 {
23 /* local socket binding voodoo copied from osmocon */
24 struct sockaddr_un local;
25 unsigned int namelen;
26 int rc;
27
28 sendsock_fd = socket(AF_UNIX, SOCK_DGRAM, 0);
29 if (sendsock_fd < 0) {
30 perror("socket(AF_UNIX, SOCK_DGRAM, 0)");
31 exit(1);
32 }
33
34 local.sun_family = AF_UNIX;
35 strncpy(local.sun_path, sockpath, sizeof(local.sun_path));
36 local.sun_path[sizeof(local.sun_path) - 1] = '\0';
37 unlink(local.sun_path);
38
39 /* we use the same magic that X11 uses in Xtranssock.c for
40 * calculating the proper length of the sockaddr */
41 #if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
42 local.sun_len = strlen(local.sun_path);
43 #endif
44 #if defined(BSD44SOCKETS) || defined(SUN_LEN)
45 namelen = SUN_LEN(&local);
46 #else
47 namelen = strlen(local.sun_path) +
48 offsetof(struct sockaddr_un, sun_path);
49 #endif
50
51 rc = bind(sendsock_fd, (struct sockaddr *) &local, namelen);
52 if (rc != 0) {
53 perror("bind on local dgram socket");
54 exit(1);
55 }
56
57 return(0);
58 }
59
60 handle_sendsock()
61 {
62 sendsock_pktlen = recv(sendsock_fd, sendsock_pkt, MAX_PKT_TO_TARGET, 0);
63 if (sendsock_pktlen <= 0) {
64 fprintf(stderr, "return value from recv on socket: %d\n",
65 sendsock_pktlen);
66 exit(1);
67 }
68 send_pkt_to_target(sendsock_pkt, sendsock_pktlen);
69 log_sent_packet(sendsock_pkt, sendsock_pktlen);
70 }