diff --git a/src/Makefile.am b/src/Makefile.am index dfd99f1..ae2a5c8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,7 @@ sbin_PROGRAMS = wrapsix-dnsproxy wrapsix-wrapper wrapsix_dnsproxy_SOURCES = dnsproxy.c wrapsix_wrapper_SOURCES = wrapper.c wrapper.h \ - ipv6.c ipv6.h + ipv6.c ipv6.h \ + ipv4.h \ + radixtree.c radixtree.h \ + nat.c nat.h diff --git a/src/ipv4.h b/src/ipv4.h new file mode 100644 index 0000000..0d2e00a --- /dev/null +++ b/src/ipv4.h @@ -0,0 +1,27 @@ +/* + * WrapSix + * Copyright (C) 2008-2010 Michal Zima + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef IPV4_H +#define IPV4_H + +/* IPv4 address structure */ +struct s_ipv4_addr { + unsigned char addr[4]; +} __attribute__ ((__packed__)); + +#endif /* IPV4_H */ diff --git a/src/wrapper.c b/src/wrapper.c index 5f16045..3744452 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -27,8 +27,10 @@ #include /* ioctl, SIOCGIFINDEX */ #include /* close */ -#include "wrapper.h" +#include "ipv4.h" #include "ipv6.h" +#include "nat.h" +#include "wrapper.h" #define INTERFACE "eth0" #define BUFFER_SIZE 65536 @@ -80,6 +82,9 @@ int main(int argc, char **argv) /* compute binary IPv6 address of WrapSix prefix */ inet_pton(AF_INET6, PREFIX, &wrapsix_ipv6_prefix); + /* initiate NAT tables */ + nat_init(); + /* sniff! :c) */ for (;;) { addr_size = sizeof(addr); @@ -92,6 +97,9 @@ int main(int argc, char **argv) } /* clean-up */ + /* empty NAT tables */ + nat_quit(); + /* unset the promiscuous mode */ if (setsockopt(sniff_sock, SOL_PACKET, PACKET_DROP_MEMBERSHIP, (char *) &pmr, sizeof(pmr)) == -1) { fprintf(stderr, "[Error] Unable to unset the promiscuous mode on the interface\n"); @@ -129,3 +137,22 @@ int process(char *packet) return 1; } } + +struct s_ipv4_addr ipv6_to_ipv4(struct s_ipv6_addr *ipv6_addr) +{ + struct s_ipv4_addr ipv4_addr; + + memcpy(&ipv4_addr, &ipv6_addr + 12, 4); + + return ipv4_addr; +} + +struct s_ipv6_addr ipv4_to_ipv6(struct s_ipv4_addr *ipv4_addr) +{ + struct s_ipv6_addr ipv6_addr; + + ipv6_addr = wrapsix_ipv6_prefix; + memcpy(&ipv6_addr + 12, &ipv4_addr, 4); + + return ipv6_addr; +} diff --git a/src/wrapper.h b/src/wrapper.h index ee9c430..e6deba5 100644 --- a/src/wrapper.h +++ b/src/wrapper.h @@ -39,4 +39,7 @@ struct s_ethernet { extern struct s_ipv6_addr ndp_multicast_addr; extern struct s_ipv6_addr wrapsix_ipv6_prefix; +struct s_ipv4_addr ipv6_to_ipv4(struct s_ipv6_addr *ipv6_addr); +struct s_ipv6_addr ipv4_to_ipv6(struct s_ipv4_addr *ipv4_addr); + #endif /* WRAPPER_H */