#include "gnunet_program_lib.h"
#include "gnunet_os_lib.h"
#include "gnunet-vpn-helper-p.h"
+#include "gnunet-vpn-packet.h"
+#include "gnunet-vpn-pretty-print.h"
/* #include "gnunet_template_service.h" */
/**
r += t;
}
- fprintf(stderr, "Read %d bytes for the header. The 'size' is %x, that is %d\n", r, hdr.size, ntohl(hdr.size));
-
struct suid_packet *pkt = (struct suid_packet*) GNUNET_malloc(ntohl(hdr.size));
if (memcpy(pkt, &hdr, sizeof(struct suid_packet_header)) < 0) {
r += t;
}
- printf("read %d bytes. The first 87 are:\n\t", r);
-
- for (r = 0; r < 87; r++)
- printf("%02x ", pkt->data[r]);
- printf("\n");
+ struct ip6_pkt *pkt6 = (struct ip6_pkt*) pkt;
+ struct ip6_tcp *pkt6_tcp;
+ struct ip6_udp *pkt6_udp;
+
+ pkt_printf(pkt6);
+ switch(pkt6->ip6_hdr.nxthdr) {
+ case 0x06:
+ pkt6_tcp = (struct ip6_tcp*)pkt6;
+ pkt_printf_ip6tcp(pkt6_tcp);
+ break;
+ case 0x11:
+ pkt6_udp = (struct ip6_udp*)pkt6;
+ pkt_printf_ip6udp(pkt6_udp);
+ if (ntohs(pkt6_udp->udp_hdr.dpt) == 53) {
+ pkt_printf_ip6dns((struct ip6_udp_dns*)pkt6_udp);
+ }
+ break;
+ }
GNUNET_free(pkt);
#ifndef _GNTUN_PACKET_H_
#define _GNTUN_PACKET_H_
+#include "gnunet-vpn-helper-p.h"
+
+// Headers
struct pkt_tun {
unsigned flags:16;
unsigned type:16;
unsigned wsz:16;
unsigned crc:16;
unsigned urg:16;
- unsigned char data[1];
};
struct udp_pkt {
unsigned crc:16;
};
+// DNS-Stuff
struct dns_pkt {
unsigned short id;
unsigned char* data;
};
+// Complete Packets
struct ip6_pkt {
+ struct suid_packet_header shdr;
struct pkt_tun tun;
- struct ip6_hdr hdr;
+ struct ip6_hdr ip6_hdr;
unsigned char data[1];
};
struct ip6_tcp {
+ struct suid_packet_header shdr;
struct pkt_tun tun;
- struct ip6_hdr hdr;
- struct tcp_pkt data;
+ struct ip6_hdr ip6_hdr;
+ struct tcp_pkt tcp_hdr;
+ unsigned char data[1];
};
struct ip6_udp {
+ struct suid_packet_header shdr;
struct pkt_tun tun;
- struct ip6_hdr hdr;
- struct udp_pkt data;
+ struct ip6_hdr ip6_hdr;
+ struct udp_pkt udp_hdr;
+ unsigned char data[1];
};
-void send_pkt(int fd, struct ip6_pkt* pkt);
-int recv_ipv6pkt(int fd, struct pkt_tun** pkt);
-int recv_pkt(int fd, struct pkt_tun** pkt);
-struct ip6_pkt* parse_ip6(struct pkt_tun* pkt);
-
struct ip6_udp_dns {
- struct ip6_udp hdr;
+ struct suid_packet_header shdr;
+ struct pkt_tun tun;
+ struct ip6_hdr ip6_hdr;
+ struct udp_pkt udp_hdr;
struct dns_pkt data;
};
-struct ip6_tcp* parse_ip6_tcp(struct ip6_pkt*);
-struct ip6_udp* parse_ip6_udp(struct ip6_pkt*);
-
-short payload(struct ip6_hdr* pkt);
-
#endif
#include <ctype.h>
#include <arpa/inet.h>
-#include "packet.h"
+#include "gnunet-vpn-packet.h"
static char* pretty = /*{{{*/
/* 0 1 2 3 4 5 6
}}}
void pp_write_header(char* dest, struct ip6_pkt* pkt) {{{
- switch (pkt->hdr.nxthdr) {
+ switch (pkt->ip6_hdr.nxthdr) {
case 0x3a:
memcpy(dest, "ICMPv6)", 7);
break;
memcpy(buf, pretty, strlen(pretty)+1);
- pp_ip6adr(pkt->hdr.sadr, buf+16);
- pp_ip6adr(pkt->hdr.dadr, buf+76);
+ pp_ip6adr(pkt->ip6_hdr.sadr, buf+16);
+ pp_ip6adr(pkt->ip6_hdr.dadr, buf+76);
- int flow = (ntohl(pkt->hdr.flowlbl));
+ int flow = (ntohl(pkt->ip6_hdr.flowlbl));
sprintf(tmp, "%03x", flow);
memcpy(buf+138, tmp, 3);
sprintf(tmp, "%-8d", flow);
memcpy(buf+143, tmp, 8);
- int length = ntohs(pkt->hdr.paylgth);
+ int length = ntohs(pkt->ip6_hdr.paylgth);
sprintf(tmp, "%02x", length);
memcpy(buf+198, tmp, 2);
sprintf(tmp, "%-3d", length);
memcpy(buf+203, tmp, 3);
- sprintf(tmp, "%02x", pkt->hdr.nxthdr);
+ sprintf(tmp, "%02x", pkt->ip6_hdr.nxthdr);
memcpy(buf+258, tmp, 2);
pp_write_header(buf+263, pkt);
- sprintf(tmp, "%02x", pkt->hdr.hoplmt);
+ sprintf(tmp, "%02x", pkt->ip6_hdr.hoplmt);
memcpy(buf+318, tmp, 2);
- sprintf(tmp, "%-3d", pkt->hdr.hoplmt);
+ sprintf(tmp, "%-3d", pkt->ip6_hdr.hoplmt);
memcpy(buf+323, tmp, 3);
- int size = payload(&pkt->hdr);
- int i;
+ int size = ntohs(pkt->ip6_hdr.paylgth);
+ int i;
for(i = 0; i < 8; i++) {
if (16*i > size) break;
pp_hexdump(pkt->data + (16*i), buf + 420 + (i*70), size - 16*i);
}}}
void pkt_printf_ip6tcp(struct ip6_tcp* pkt) {{{
- printf("spt: %u\n", ntohs(pkt->data.spt));
- printf("dpt: %u\n", ntohs(pkt->data.dpt));
- printf("seq: %u\n", ntohs(pkt->data.seq));
- printf("ack: %u\n", ntohs(pkt->data.ack));
- printf("off: %u\n", ntohs(pkt->data.off));
- printf("wsz: %u\n", ntohs(pkt->data.wsz));
- printf("crc: 0x%x\n", ntohs(pkt->data.crc));
- printf("urg: %u\n", ntohs(pkt->data.urg));
+ printf("spt: %u\n", ntohs(pkt->tcp_hdr.spt));
+ printf("dpt: %u\n", ntohs(pkt->tcp_hdr.dpt));
+ printf("seq: %u\n", ntohs(pkt->tcp_hdr.seq));
+ printf("ack: %u\n", ntohs(pkt->tcp_hdr.ack));
+ printf("off: %u\n", ntohs(pkt->tcp_hdr.off));
+ printf("wsz: %u\n", ntohs(pkt->tcp_hdr.wsz));
+ printf("crc: 0x%x\n", ntohs(pkt->tcp_hdr.crc));
+ printf("urg: %u\n", ntohs(pkt->tcp_hdr.urg));
printf("flags: %c%c%c%c%c%c%c%c\n",
- pkt->data.flg & 0x80 ? 'C' : '.',
- pkt->data.flg & 0x40 ? 'E' : '.',
- pkt->data.flg & 0x20 ? 'U' : '.',
- pkt->data.flg & 0x10 ? 'A' : '.',
- pkt->data.flg & 0x08 ? 'P' : '.',
- pkt->data.flg & 0x04 ? 'R' : '.',
- pkt->data.flg & 0x02 ? 'S' : '.',
- pkt->data.flg & 0x01 ? 'F' : '.'
+ pkt->tcp_hdr.flg & 0x80 ? 'C' : '.',
+ pkt->tcp_hdr.flg & 0x40 ? 'E' : '.',
+ pkt->tcp_hdr.flg & 0x20 ? 'U' : '.',
+ pkt->tcp_hdr.flg & 0x10 ? 'A' : '.',
+ pkt->tcp_hdr.flg & 0x08 ? 'P' : '.',
+ pkt->tcp_hdr.flg & 0x04 ? 'R' : '.',
+ pkt->tcp_hdr.flg & 0x02 ? 'S' : '.',
+ pkt->tcp_hdr.flg & 0x01 ? 'F' : '.'
);
}}}
void pkt_printf_ip6udp(struct ip6_udp* pkt) {{{
- printf("spt: %u\n", ntohs(pkt->data.spt));
- printf("dpt: %u\n", ntohs(pkt->data.dpt));
- printf("len: %u\n", ntohs(pkt->data.len));
- printf("crc: 0x%x\n", ntohs(pkt->data.crc));
+ printf("spt: %u\n", ntohs(pkt->udp_hdr.spt));
+ printf("dpt: %u\n", ntohs(pkt->udp_hdr.dpt));
+ printf("len: %u\n", ntohs(pkt->udp_hdr.len));
+ printf("crc: 0x%x\n", ntohs(pkt->udp_hdr.crc));
}}}
static char* dns_types(unsigned short type) {{{