diff options
author | Philipp Tölke <toelke@in.tum.de> | 2010-06-28 12:37:39 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2010-06-28 12:37:39 +0000 |
commit | abfd8251847962ccdff4d445ff2069da1dcb212a (patch) | |
tree | 6e3e676bdc8eeb7c2b59b5d9a606e3c02dac989a | |
parent | 947e2bd0312aacc2e1eb57b56c094386208c3931 (diff) | |
download | gnunet-abfd8251847962ccdff4d445ff2069da1dcb212a.tar.gz gnunet-abfd8251847962ccdff4d445ff2069da1dcb212a.zip |
vpn: prepared to implement tcp
-rw-r--r-- | src/vpn/packet.c | 40 | ||||
-rw-r--r-- | src/vpn/packet.h | 8 | ||||
-rw-r--r-- | src/vpn/test.c | 14 |
3 files changed, 38 insertions, 24 deletions
diff --git a/src/vpn/packet.c b/src/vpn/packet.c index 8125cbb0f..fc9eb7ba4 100644 --- a/src/vpn/packet.c +++ b/src/vpn/packet.c | |||
@@ -18,18 +18,18 @@ void send_pkt(int fd, struct ip6_pkt* pkt) {{{ | |||
18 | int w = 0; | 18 | int w = 0; |
19 | char* buf = (char*)malloc(sz+40); | 19 | char* buf = (char*)malloc(sz+40); |
20 | 20 | ||
21 | buf[0] = (6 << 4) | (pkt->tclass >> 4); | 21 | buf[0] = (6 << 4) | (pkt->hdr.tclass >> 4); |
22 | buf[1] = (pkt->tclass << 4) | (pkt->flowlbl[0] >> 4); | 22 | buf[1] = (pkt->hdr.tclass << 4) | (pkt->hdr.flowlbl[0] >> 4); |
23 | buf[2] = pkt->flowlbl[1]; | 23 | buf[2] = pkt->hdr.flowlbl[1]; |
24 | buf[3] = pkt->flowlbl[2]; | 24 | buf[3] = pkt->hdr.flowlbl[2]; |
25 | buf[4] = pkt->paylgth[0]; | 25 | buf[4] = pkt->hdr.paylgth[0]; |
26 | buf[5] = pkt->paylgth[1]; | 26 | buf[5] = pkt->hdr.paylgth[1]; |
27 | buf[6] = pkt->nxthdr; | 27 | buf[6] = pkt->hdr.nxthdr; |
28 | buf[7] = pkt->hoplmt; | 28 | buf[7] = pkt->hdr.hoplmt; |
29 | 29 | ||
30 | for (w = 0; w < 16; w++) { | 30 | for (w = 0; w < 16; w++) { |
31 | buf[8+w] = pkt->sadr[w]; | 31 | buf[8+w] = pkt->hdr.sadr[w]; |
32 | buf[24+w] = pkt->dadr[w]; | 32 | buf[24+w] = pkt->hdr.dadr[w]; |
33 | } | 33 | } |
34 | 34 | ||
35 | memcpy(buf+40, pkt->data, sz); | 35 | memcpy(buf+40, pkt->data, sz); |
@@ -104,20 +104,20 @@ int recv_pkt(int fd, struct pkt_tun** pkt) {{{ | |||
104 | struct ip6_pkt* parse_ip6(struct pkt_tun* pkt) {{{ | 104 | struct ip6_pkt* parse_ip6(struct pkt_tun* pkt) {{{ |
105 | struct ip6_pkt* pkt6 = (struct ip6_pkt*)malloc(sizeof(struct ip6_pkt)); | 105 | struct ip6_pkt* pkt6 = (struct ip6_pkt*)malloc(sizeof(struct ip6_pkt)); |
106 | 106 | ||
107 | pkt6->tclass = pkt->data[0] << 4 | pkt->data[1] >> 4; | 107 | pkt6->hdr.tclass = pkt->data[0] << 4 | pkt->data[1] >> 4; |
108 | pkt6->flowlbl[0] = pkt->data[1]>>4; | 108 | pkt6->hdr.flowlbl[0] = pkt->data[1]>>4; |
109 | pkt6->flowlbl[1] = pkt->data[2]; | 109 | pkt6->hdr.flowlbl[1] = pkt->data[2]; |
110 | pkt6->flowlbl[2] = pkt->data[3]; | 110 | pkt6->hdr.flowlbl[2] = pkt->data[3]; |
111 | 111 | ||
112 | pkt6->paylgth[0] = pkt->data[4]; | 112 | pkt6->hdr.paylgth[0] = pkt->data[4]; |
113 | pkt6->paylgth[1] = pkt->data[5]; | 113 | pkt6->hdr.paylgth[1] = pkt->data[5]; |
114 | 114 | ||
115 | pkt6->nxthdr = pkt->data[6]; | 115 | pkt6->hdr.nxthdr = pkt->data[6]; |
116 | pkt6->hoplmt = pkt->data[7]; | 116 | pkt6->hdr.hoplmt = pkt->data[7]; |
117 | 117 | ||
118 | for (int w = 0; w < 16; w++) { | 118 | for (int w = 0; w < 16; w++) { |
119 | pkt6->sadr[w] = pkt->data[8+w]; | 119 | pkt6->hdr.sadr[w] = pkt->data[8+w]; |
120 | pkt6->dadr[w] = pkt->data[24+w]; | 120 | pkt6->hdr.dadr[w] = pkt->data[24+w]; |
121 | } | 121 | } |
122 | 122 | ||
123 | pkt6->data = (unsigned char*)malloc(payload(pkt6)); | 123 | pkt6->data = (unsigned char*)malloc(payload(pkt6)); |
diff --git a/src/vpn/packet.h b/src/vpn/packet.h index b86f4a65c..7857bb283 100644 --- a/src/vpn/packet.h +++ b/src/vpn/packet.h | |||
@@ -8,7 +8,7 @@ struct pkt_tun { | |||
8 | unsigned char* data; | 8 | unsigned char* data; |
9 | }; | 9 | }; |
10 | 10 | ||
11 | struct ip6_pkt { | 11 | struct ip6_hdr { |
12 | unsigned char tclass; | 12 | unsigned char tclass; |
13 | unsigned char flowlbl[3]; | 13 | unsigned char flowlbl[3]; |
14 | unsigned char paylgth[2]; | 14 | unsigned char paylgth[2]; |
@@ -16,6 +16,12 @@ struct ip6_pkt { | |||
16 | unsigned char hoplmt; | 16 | unsigned char hoplmt; |
17 | unsigned char sadr[16]; | 17 | unsigned char sadr[16]; |
18 | unsigned char dadr[16]; | 18 | unsigned char dadr[16]; |
19 | }; | ||
20 | |||
21 | struct ip6_pkt { | ||
22 | struct ip6_hdr hdr; | ||
23 | unsigned char* data; | ||
24 | }; | ||
19 | 25 | ||
20 | unsigned char* data; | 26 | unsigned char* data; |
21 | }; | 27 | }; |
diff --git a/src/vpn/test.c b/src/vpn/test.c index 7f6aab860..15aad30d6 100644 --- a/src/vpn/test.c +++ b/src/vpn/test.c | |||
@@ -18,8 +18,16 @@ int main(int c, char** v) { | |||
18 | struct pkt_tun* pkt; | 18 | struct pkt_tun* pkt; |
19 | 19 | ||
20 | for(;;) { | 20 | for(;;) { |
21 | printf("read %d bytes from socket, now to parse'em\n", recv_pkt(fd, &pkt)); | 21 | printf("read %d bytes from socket, ", recv_pkt(fd, &pkt)); |
22 | struct ip6_pkt* pkt6 = parse_ip6(pkt); | 22 | switch (pkt->type[0] << 8 | pkt->type[1]) { |
23 | pkt_printf(pkt6); | 23 | case 0x86dd: |
24 | printf("parsing ipv6:\n"); | ||
25 | struct ip6_pkt* pkt6 = parse_ip6(pkt); | ||
26 | pkt_printf(pkt6); | ||
27 | break; | ||
28 | default: | ||
29 | printf("unknown/unimplemented packet-type\n"); | ||
30 | break; | ||
31 | } | ||
24 | } | 32 | } |
25 | } | 33 | } |