1
0
mirror of https://code.semirocket.science/wrapsix synced 2025-12-08 09:55:13 +02:00

Integrated wrapper into WrapSix

Fixed bug in resolver so now even normal applications accept its answers
Improved configuration - now accepts arguments from command line
Cleaned the code a little bit
Added simple build script
Written more documentation into README
Chosen the licence - GNU AGPLv3
This commit is contained in:
xHire
2009-01-14 23:05:12 +01:00
parent e7d8a4c1dd
commit c894b7186c
9 changed files with 205 additions and 58 deletions

View File

@@ -52,24 +52,39 @@ void process_packet4(const struct s_ethernet *eth, const unsigned char *packet)
printf(" From: %s\n", inet_ntoa(ip->ip_src));
printf(" To: %s\n", inet_ntoa(ip->ip_dest));
/* check if this packet is ours */
if (memcmp(&ip4addr_wrapsix, &ip->ip_dest, 4)) {
printf("==> This packet is not ours! <==\n");
return;
}
/* determine protocol */
switch (ip->proto) {
case IPPROTO_TCP:
printf(" Protocol: TCP\n");
/* check if this packet is ours */
if (memcmp(&ip4addr_wrapsix, &ip->ip_dest, 4)) {
printf("==> This packet is not ours! <==\n");
return;
}
process_tcp4(eth, ip, payload, htons(ip->pckt_len) - header_length);
break;
case IPPROTO_UDP:
printf(" Protocol: UDP\n");
/* check if this packet is ours */
if (memcmp(dev_ip, &ip->ip_dest, 4)) {
printf("==> This packet is not ours! <==\n");
return;
}
process_udp4(eth, ip, payload, htons(ip->pckt_len) - header_length);
break;
case IPPROTO_ICMP:
printf(" Protocol: ICMP\n");
/* check if this packet is ours */
if (memcmp(dev_ip, &ip->ip_dest, 4)) {
printf("==> This packet is not ours! <==\n");
return;
}
process_icmp4(eth, ip, payload, htons(ip->pckt_len) - header_length);
break;
default:
@@ -117,11 +132,11 @@ void process_tcp4(const struct s_ethernet *eth_hdr, struct s_ip4 *ip_hdr, const
/* check if this packet is from wrapped connection */
if (ent == NULL) {
fprintf(stderr, "Error: data not found\n");
printf("Error: data not found\n");
return;
}
else if (memcmp(&ent->addr_to, &ip_hdr->ip_src, sizeof(struct in_addr))) {
fprintf(stderr, "Error: data not appropriate\n");
printf("Error: data not appropriate\n");
printf(" Ent-to: %s\n", inet_ntoa(ent->addr_to));
printf(" IP-from: %s\n", inet_ntoa(ip_hdr->ip_src));
return;
@@ -280,11 +295,11 @@ void process_udp4(const struct s_ethernet *eth_hdr, struct s_ip4 *ip_hdr, const
/* check if this packet is from wrapped connection */
if (ent == NULL) {
fprintf(stderr, "Error: data not found\n");
printf("Error: data not found\n");
return;
}
else if (memcmp(&ent->addr_to, &ip_hdr->ip_src, sizeof(struct in_addr))) {
fprintf(stderr, "Error: data not appropriate\n");
printf("Error: data not appropriate\n");
printf(" Ent-to: %s\n", inet_ntoa(ent->addr_to));
printf(" IP-from: %s\n", inet_ntoa(ip_hdr->ip_src));
return;
@@ -387,11 +402,11 @@ void process_icmp4(const struct s_ethernet *eth_hdr, struct s_ip4 *ip_hdr, const
/* check if this packet is from wrapped connection */
if (ent == NULL) {
fprintf(stderr, "Error: data not found\n");
printf("Error: data not found\n");
return;
}
else if (memcmp(&ent->addr_to, &ip_hdr->ip_src, sizeof(struct in_addr))) {
fprintf(stderr, "Error: data not appropriate\n");
printf("Error: data not appropriate\n");
printf(" Ent-to: %s\n", inet_ntoa(ent->addr_to));
printf(" IP-from: %s\n", inet_ntoa(ip_hdr->ip_src));
return;

View File

@@ -13,9 +13,13 @@ jsw_rbtree_t *stg_conn_tcp;
jsw_rbtree_t *stg_conn_udp;
jsw_rbtree_t *stg_conn_icmp;
/*
* 1: IPv4 address
* 2: IPv6 prefix
* 3: ethernet device
*/
int main(int argc, char **argv)
{
char errbuf[PCAP_ERRBUF_SIZE]; /* error buffer */
pcap_t *handle; /* packet capture handle */
@@ -30,10 +34,20 @@ int main(int argc, char **argv)
/* find a capture device */
dev = NULL;
dev = pcap_lookupdev(errbuf);
if (dev == NULL) {
fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
exit(EXIT_FAILURE);
printf("Args: %d\n", argc);
if (argc == 4) {
if ((dev = malloc(strlen(argv[3]))) == NULL) {
fprintf(stderr, "Fatal Error! Lack of free memory!\n");
exit(EXIT_FAILURE);
}
memcpy(dev, argv[3], sizeof(dev));
}
else {
dev = pcap_lookupdev(errbuf);
if (dev == NULL) {
fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
exit(EXIT_FAILURE);
}
}
/* print capture info */
@@ -72,8 +86,10 @@ int main(int argc, char **argv)
dev_index = get_dev_index(dev);
/* set the WrapSix addresses */
inet_aton("10.0.0.111", &ip4addr_wrapsix);
inet_pton(AF_INET6, "fc00:1::", &ip6addr_wrapsix);
//inet_aton("10.0.0.111", &ip4addr_wrapsix);
//inet_pton(AF_INET6, "fc00:1::", &ip6addr_wrapsix);
inet_aton(argv[1], &ip4addr_wrapsix);
inet_pton(AF_INET6, argv[2], &ip6addr_wrapsix);
/* compile the filter expression */
if (pcap_compile(handle, &fp, filter_exp, 0, 0) == -1) {