aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2010-07-20 05:45:30 +0000
committerPhilipp Tölke <toelke@in.tum.de>2010-07-20 05:45:30 +0000
commit0395351ad94b6209b27c0ab45aad00c90b7ff60f (patch)
tree6d714d9ef91fc2f9d2f8cd64751f5b3798c17650 /src/vpn
parentdd29458d6f7cbedb11088882913d4657aa6a90d0 (diff)
downloadgnunet-0395351ad94b6209b27c0ab45aad00c90b7ff60f.tar.gz
gnunet-0395351ad94b6209b27c0ab45aad00c90b7ff60f.zip
read the output of the helper
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-daemon-vpn.c59
1 files changed, 53 insertions, 6 deletions
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c
index 299e60e19..875ebf018 100644
--- a/src/vpn/gnunet-daemon-vpn.c
+++ b/src/vpn/gnunet-daemon-vpn.c
@@ -27,6 +27,7 @@
27#include "gnunet_getopt_lib.h" 27#include "gnunet_getopt_lib.h"
28#include "gnunet_program_lib.h" 28#include "gnunet_program_lib.h"
29#include "gnunet_os_lib.h" 29#include "gnunet_os_lib.h"
30#include "gnunet-vpn-helper-p.h"
30/* #include "gnunet_template_service.h" */ 31/* #include "gnunet_template_service.h" */
31 32
32/** 33/**
@@ -37,6 +38,9 @@ static int ret;
37struct vpn_cls { 38struct vpn_cls {
38 struct GNUNET_DISK_PipeHandle* helper_in; 39 struct GNUNET_DISK_PipeHandle* helper_in;
39 struct GNUNET_DISK_PipeHandle* helper_out; 40 struct GNUNET_DISK_PipeHandle* helper_out;
41 const struct GNUNET_DISK_FileHandle* fh_from_helper;
42
43 struct GNUNET_SCHEDULER_Handle *sched; // TODO CG: is that right? Do I have to carry it around myself?
40 44
41 pid_t helper_pid; 45 pid_t helper_pid;
42}; 46};
@@ -50,6 +54,47 @@ static void cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx
50} 54}
51 55
52static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) { 56static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) {
57 struct vpn_cls* mycls = (struct vpn_cls*) cls;
58 struct suid_packet_header hdr = { .size = 0 };
59
60 int r = 0;
61
62 while (r < sizeof(struct suid_packet_header)) {
63 int t = GNUNET_DISK_file_read(mycls->fh_from_helper, &hdr, sizeof(struct suid_packet_header));
64 if (t< 0) {
65 fprintf(stderr, "Read error for header: %m\n");
66 return;
67 }
68 r += t;
69 }
70
71 fprintf(stderr, "Read %d bytes for the header. The 'size' is %x, that is %d\n", r, hdr.size, ntohl(hdr.size));
72
73 struct suid_packet *pkt = (struct suid_packet*) GNUNET_malloc(ntohl(hdr.size));
74
75 if (memcpy(pkt, &hdr, sizeof(struct suid_packet_header)) < 0) {
76 fprintf(stderr, "Memcpy: %m\n");
77 return;
78 }
79
80 while (r < ntohl(pkt->hdr.size)) {
81 int t = GNUNET_DISK_file_read(mycls->fh_from_helper, (unsigned char*)pkt + r, ntohl(pkt->hdr.size) - r);
82 if (t< 0) {
83 fprintf(stderr, "Read error for data: %m\n");
84 return;
85 }
86 r += t;
87 }
88
89 printf("read %d bytes. The first 87 are:\n\t", r);
90
91 for (r = 0; r < 87; r++)
92 printf("%02x ", pkt->data[r]);
93 printf("\n");
94
95 GNUNET_free(pkt);
96
97 GNUNET_SCHEDULER_add_read_file (mycls->sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls->fh_from_helper, &helper_read, mycls);
53} 98}
54 99
55/** 100/**
@@ -63,13 +108,15 @@ static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* ts
63 */ 108 */
64static void 109static void
65run (void *cls, 110run (void *cls,
66 struct GNUNET_SCHEDULER_Handle *sched, 111 struct GNUNET_SCHEDULER_Handle *sched,
67 char *const *args, 112 char *const *args,
68 const char *cfgfile, 113 const char *cfgfile,
69 const struct GNUNET_CONFIGURATION_Handle *cfg) { 114 const struct GNUNET_CONFIGURATION_Handle *cfg) {
70 115
71 struct vpn_cls* mycls = (struct vpn_cls*) cls; 116 struct vpn_cls* mycls = (struct vpn_cls*) cls;
72 117
118 mycls->sched = sched;
119
73 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); 120 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
74 121
75 mycls->helper_in = GNUNET_DISK_pipe(1); 122 mycls->helper_in = GNUNET_DISK_pipe(1);
@@ -77,9 +124,9 @@ run (void *cls,
77 124
78 mycls->helper_pid = GNUNET_OS_start_process(mycls->helper_in, mycls->helper_out, "gnunet-vpn-helper", "gnunet-vpn-helper", NULL); 125 mycls->helper_pid = GNUNET_OS_start_process(mycls->helper_in, mycls->helper_out, "gnunet-vpn-helper", "gnunet-vpn-helper", NULL);
79 126
80 const struct GNUNET_DISK_FileHandle* fh = GNUNET_DISK_pipe_handle (mycls->helper_out, GNUNET_DISK_PIPE_END_READ); 127 mycls->fh_from_helper = GNUNET_DISK_pipe_handle (mycls->helper_out, GNUNET_DISK_PIPE_END_READ);
81 128
82 GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, fh, &helper_read, mycls); 129 GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls->fh_from_helper, &helper_read, mycls);
83} 130}
84 131
85 132