vpn: cleanup of the code
authorPhilipp Tölke <toelke@in.tum.de>
Mon, 28 Jun 2010 12:37:44 +0000 (12:37 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Mon, 28 Jun 2010 12:37:44 +0000 (12:37 +0000)
src/vpn/packet.c
src/vpn/pretty-print.c

index 4e96fb5f1b8d3350406235efaf385f2cb74ce295..963c6948fbc074d6c4532deac13a3d1860e24969 100644 (file)
@@ -31,21 +31,20 @@ void send_pkt(int fd, struct ip6_pkt* pkt) {{{
        free(buf);
 }}}
 
-int recv_ipv6pkt(int fd, struct pkt_tun** pkt) {{{
-}}}
-
 int recv_pkt(int fd, struct pkt_tun** pkt) {{{
-       // TODO: länge lesen?
-       *pkt = (struct pkt_tun*)malloc(1504);
-       struct pkt_tun* _pkt = *pkt;
-
-       unsigned char *data = (unsigned char*)_pkt;
+       int size = 1504;
+       unsigned char data[size];
 
        debug(1, 0, "beginning to read...\n");
 
-       int r = read(fd, data, 1504);
+       int r = read(fd, data, size);
        debug(1, 0, "read %d bytes\n", r);
 
+       *pkt = (struct pkt_tun*)malloc(r);
+
+       memcpy(*pkt, data, r);
+       struct pkt_tun *_pkt = *pkt;
+
        debug(1, 0, "read the flags: %04x\n", ntohs(_pkt->flags));
        debug(1, 0, "read the type: %04x\n", ntohs(_pkt->type));
 
@@ -53,7 +52,7 @@ int recv_pkt(int fd, struct pkt_tun** pkt) {{{
                case 0x86dd:
                        debug(1, 0, "reading an ipv6-packet\n");
                        struct ip6_pkt * pkt6 = (struct ip6_pkt*) *pkt;
-                       int size = payload(&(pkt6->hdr));
+                       size = payload(&(pkt6->hdr));
                        debug(1, 0, "read the size: %d\n", size);
                        return size;
                        break;
index 96e435d2d42844ab51c7139d5ea2c82632b7fac5..22a642728b4d86d54429fa271ad54cbd096a3b37 100644 (file)
@@ -151,7 +151,7 @@ void pkt_printf_ip6tcp(struct ip6_tcp* pkt) {{{
        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: %u\n", ntohs(pkt->data.crc));
+       printf("crc: 0x%x\n", ntohs(pkt->data.crc));
        printf("urg: %u\n", ntohs(pkt->data.urg));
        printf("flags: %c%c%c%c%c%c%c%c\n",
                        pkt->data.flg & 0x80 ? 'C' : '.',