1
0
mirror of https://code.semirocket.science/wrapsix synced 2024-12-22 12:30:18 +02:00

Some more NAT stuff (init & quit calling)

IPv4 address structure
IP addresses translation functions
Makefile.am update
This commit is contained in:
Michal Zima 2010-02-22 15:00:14 +01:00
parent f9f2bd501b
commit e0015145e2
4 changed files with 62 additions and 2 deletions

View File

@ -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

27
src/ipv4.h Normal file
View File

@ -0,0 +1,27 @@
/*
* WrapSix
* Copyright (C) 2008-2010 Michal Zima <xhire@mujmalysvet.cz>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef IPV4_H
#define IPV4_H
/* IPv4 address structure */
struct s_ipv4_addr {
unsigned char addr[4];
} __attribute__ ((__packed__));
#endif /* IPV4_H */

View File

@ -27,8 +27,10 @@
#include <sys/ioctl.h> /* ioctl, SIOCGIFINDEX */
#include <unistd.h> /* 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;
}

View File

@ -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 */