#include "gnunet-vpn-helper-p.h"
#include "gnunet-vpn-packet.h"
#include "gnunet-vpn-pretty-print.h"
+#include "gnunet_common.h"
+#include "gnunet_protocols.h"
/* #include "gnunet_template_service.h" */
/**
static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) {
struct vpn_cls* mycls = (struct vpn_cls*) cls;
- struct suid_packet_header hdr = { .size = 0 };
+ struct GNUNET_MessageHeader hdr = { .size = 0, .type = 0 };
int r = 0;
if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)
return;
- while (r < sizeof(struct suid_packet_header)) {
- int t = GNUNET_DISK_file_read(mycls->fh_from_helper, &hdr, sizeof(struct suid_packet_header));
+ while (r < sizeof(struct GNUNET_MessageHeader)) {
+ int t = GNUNET_DISK_file_read(mycls->fh_from_helper, &hdr, sizeof(struct GNUNET_MessageHeader));
if (t<=0) {
fprintf(stderr, "Read error for header: %m\n");
GNUNET_SCHEDULER_add_now(mycls->sched, restart_helper, cls);
r += t;
}
- struct suid_packet *pkt = (struct suid_packet*) GNUNET_malloc(ntohl(hdr.size));
+ struct suid_packet *pkt = (struct suid_packet*) GNUNET_malloc(ntohs(hdr.size));
- memcpy(pkt, &hdr, sizeof(struct suid_packet_header));
+ memcpy(pkt, &hdr, sizeof(struct GNUNET_MessageHeader));
- while (r < ntohl(pkt->hdr.size)) {
- int t = GNUNET_DISK_file_read(mycls->fh_from_helper, (unsigned char*)pkt + r, ntohl(pkt->hdr.size) - r);
+ while (r < ntohs(pkt->hdr.size)) {
+ int t = GNUNET_DISK_file_read(mycls->fh_from_helper, (unsigned char*)pkt + r, ntohs(pkt->hdr.size) - r);
if (t<=0) {
fprintf(stderr, "Read error for data: %m\n");
GNUNET_SCHEDULER_add_now(mycls->sched, restart_helper, cls);
#include <stdio.h>
#include <unistd.h>
-#include "gnunet-vpn-helper-p.h"
#include "gnunet-vpn-tun.h"
+#include "gnunet_common.h"
+#include "gnunet_protocols.h"
+#include "gnunet-vpn-helper-p.h"
#ifndef _LINUX_IN6_H
// This is in linux/include/net/ipv6.h.
if (FD_ISSET(0, &fds_r) && write_fd_possible) {
write_fd_possible = 0;
struct suid_packet *pkt = (struct suid_packet*) buf;
- r = read(0, buf, sizeof(struct suid_packet_header));
+ r = read(0, buf, sizeof(struct GNUNET_MessageHeader));
if (r <= 0) {
fprintf(stderr, "read-error: %m\n");
shutdown(fd_tun, SHUT_WR);
wri=0;
goto outer;
}
- while (r < ntohl(pkt->hdr.size)) {
- int t = read(0, buf + r, ntohl(pkt->hdr.size) - r);
+ while (r < ntohs(pkt->hdr.size)) {
+ int t = read(0, buf + r, ntohs(pkt->hdr.size) - r);
if (r < 0) {
fprintf(stderr, "read-error: %m\n");
shutdown(fd_tun, SHUT_WR);
r += t;
}
r = 0;
- while (r < ntohl(pkt->hdr.size) - sizeof(struct suid_packet_header)) {
- int t = write(fd_tun, pkt->data, ntohl(pkt->hdr.size) - sizeof(struct suid_packet_header) - r);
+ while (r < ntohs(pkt->hdr.size) - sizeof(struct GNUNET_MessageHeader)) {
+ int t = write(fd_tun, pkt->data, ntohs(pkt->hdr.size) - sizeof(struct GNUNET_MessageHeader) - r);
if (t < 0) {
fprintf(stderr, "write-error 3: %m\n");
shutdown(fd_tun, SHUT_WR);
rea = 0;
goto outer;
}
- struct suid_packet_header hdr = { .size = htonl(r + sizeof(struct suid_packet_header))};
+ struct GNUNET_MessageHeader hdr = { .size = htons(r + sizeof(struct GNUNET_MessageHeader)), .type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER) };
r = 0;
- while(r < sizeof(struct suid_packet_header)) {
- int t = write(1, &hdr, sizeof(struct suid_packet_header) - r);
+ while(r < sizeof(struct GNUNET_MessageHeader)) {
+ int t = write(1, &hdr, sizeof(struct GNUNET_MessageHeader) - r);
if (t < 0) {
fprintf(stderr, "write-error 2: %m\n");
shutdown(fd_tun, SHUT_RD);
}
r += t;
}
- while(r < ntohl(hdr.size)) {
- int t = write(1, buf, ntohl(hdr.size) - r);
+ while(r < ntohs(hdr.size)) {
+ int t = write(1, buf, ntohs(hdr.size) - r);
if (t < 0) {
- fprintf(stderr, "write-error 1: %m, written %d/%d\n", r, ntohl(hdr.size));
+ fprintf(stderr, "write-error 1: %m, written %d/%d\n", r, ntohs(hdr.size));
shutdown(fd_tun, SHUT_RD);
shutdown(1, SHUT_WR);
rea = 0;