From abfd8251847962ccdff4d445ff2069da1dcb212a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Mon, 28 Jun 2010 12:37:39 +0000 Subject: [PATCH] vpn: prepared to implement tcp --- src/vpn/packet.c | 40 ++++++++++++++++++++-------------------- src/vpn/packet.h | 8 +++++++- 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) {{{ int w = 0; char* buf = (char*)malloc(sz+40); - buf[0] = (6 << 4) | (pkt->tclass >> 4); - buf[1] = (pkt->tclass << 4) | (pkt->flowlbl[0] >> 4); - buf[2] = pkt->flowlbl[1]; - buf[3] = pkt->flowlbl[2]; - buf[4] = pkt->paylgth[0]; - buf[5] = pkt->paylgth[1]; - buf[6] = pkt->nxthdr; - buf[7] = pkt->hoplmt; + buf[0] = (6 << 4) | (pkt->hdr.tclass >> 4); + buf[1] = (pkt->hdr.tclass << 4) | (pkt->hdr.flowlbl[0] >> 4); + buf[2] = pkt->hdr.flowlbl[1]; + buf[3] = pkt->hdr.flowlbl[2]; + buf[4] = pkt->hdr.paylgth[0]; + buf[5] = pkt->hdr.paylgth[1]; + buf[6] = pkt->hdr.nxthdr; + buf[7] = pkt->hdr.hoplmt; for (w = 0; w < 16; w++) { - buf[8+w] = pkt->sadr[w]; - buf[24+w] = pkt->dadr[w]; + buf[8+w] = pkt->hdr.sadr[w]; + buf[24+w] = pkt->hdr.dadr[w]; } memcpy(buf+40, pkt->data, sz); @@ -104,20 +104,20 @@ int recv_pkt(int fd, struct pkt_tun** pkt) {{{ struct ip6_pkt* parse_ip6(struct pkt_tun* pkt) {{{ struct ip6_pkt* pkt6 = (struct ip6_pkt*)malloc(sizeof(struct ip6_pkt)); - pkt6->tclass = pkt->data[0] << 4 | pkt->data[1] >> 4; - pkt6->flowlbl[0] = pkt->data[1]>>4; - pkt6->flowlbl[1] = pkt->data[2]; - pkt6->flowlbl[2] = pkt->data[3]; + pkt6->hdr.tclass = pkt->data[0] << 4 | pkt->data[1] >> 4; + pkt6->hdr.flowlbl[0] = pkt->data[1]>>4; + pkt6->hdr.flowlbl[1] = pkt->data[2]; + pkt6->hdr.flowlbl[2] = pkt->data[3]; - pkt6->paylgth[0] = pkt->data[4]; - pkt6->paylgth[1] = pkt->data[5]; + pkt6->hdr.paylgth[0] = pkt->data[4]; + pkt6->hdr.paylgth[1] = pkt->data[5]; - pkt6->nxthdr = pkt->data[6]; - pkt6->hoplmt = pkt->data[7]; + pkt6->hdr.nxthdr = pkt->data[6]; + pkt6->hdr.hoplmt = pkt->data[7]; for (int w = 0; w < 16; w++) { - pkt6->sadr[w] = pkt->data[8+w]; - pkt6->dadr[w] = pkt->data[24+w]; + pkt6->hdr.sadr[w] = pkt->data[8+w]; + pkt6->hdr.dadr[w] = pkt->data[24+w]; } 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 { unsigned char* data; }; -struct ip6_pkt { +struct ip6_hdr { unsigned char tclass; unsigned char flowlbl[3]; unsigned char paylgth[2]; @@ -16,6 +16,12 @@ struct ip6_pkt { unsigned char hoplmt; unsigned char sadr[16]; unsigned char dadr[16]; +}; + +struct ip6_pkt { + struct ip6_hdr hdr; + unsigned char* data; +}; unsigned char* data; }; 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) { struct pkt_tun* pkt; for(;;) { - printf("read %d bytes from socket, now to parse'em\n", recv_pkt(fd, &pkt)); - struct ip6_pkt* pkt6 = parse_ip6(pkt); - pkt_printf(pkt6); + printf("read %d bytes from socket, ", recv_pkt(fd, &pkt)); + switch (pkt->type[0] << 8 | pkt->type[1]) { + case 0x86dd: + printf("parsing ipv6:\n"); + struct ip6_pkt* pkt6 = parse_ip6(pkt); + pkt_printf(pkt6); + break; + default: + printf("unknown/unimplemented packet-type\n"); + break; + } } } -- 2.25.1