comparison rvinterf/old/rvtdump_tx.c @ 173:f42854da4563

rvinterf: beginning of refactoring
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 22 Nov 2013 05:56:07 +0000
parents rvinterf/rvtdump_tx.c@4d8e4c58df71
children
comparison
equal deleted inserted replaced
172:019120585a1c 173:f42854da4563
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 }