1
0
mirror of https://code.semirocket.science/wrapsix synced 2024-11-14 01:51:14 +02:00

Simplified assigning of IP addresses

This commit is contained in:
Michal Zima 2013-02-14 14:04:33 +01:00
parent 378d3200c2
commit e722e80149
3 changed files with 8 additions and 10 deletions

View File

@ -1,6 +1,6 @@
/* /*
* WrapSix * WrapSix
* Copyright (C) 2008-2012 Michal Zima <xhire@mujmalysvet.cz> * Copyright (C) 2008-2013 Michal Zima <xhire@mujmalysvet.cz>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -125,7 +125,7 @@ int icmp_ipv4(struct s_ethernet *eth4, struct s_ipv4 *ip4,
ip6->next_header = IPPROTO_ICMPV6; ip6->next_header = IPPROTO_ICMPV6;
ip6->hop_limit = ip4->ttl; ip6->hop_limit = ip4->ttl;
ipv4_to_ipv6(&ip4->ip_src, &ip6->ip_src); ipv4_to_ipv6(&ip4->ip_src, &ip6->ip_src);
memcpy(&ip6->ip_dest, &connection->ipv6, sizeof(struct s_ipv6_addr)); ip6->ip_dest = connection->ipv6;
/* compute ICMP checksum */ /* compute ICMP checksum */
icmp->checksum = 0x0; icmp->checksum = 0x0;
@ -247,8 +247,8 @@ int icmp_ipv6(struct s_ethernet *eth6, struct s_ipv6 *ip6, char *payload)
ip4->flags_offset = htons(IPV4_FLAG_DONT_FRAGMENT); ip4->flags_offset = htons(IPV4_FLAG_DONT_FRAGMENT);
ip4->ttl = ip6->hop_limit; ip4->ttl = ip6->hop_limit;
ip4->proto = IPPROTO_ICMP; ip4->proto = IPPROTO_ICMP;
ip4->ip_src = wrapsix_ipv4_addr;
ipv6_to_ipv4(&ip6->ip_dest, &ip4->ip_dest); ipv6_to_ipv4(&ip6->ip_dest, &ip4->ip_dest);
memcpy(&ip4->ip_src, &wrapsix_ipv4_addr, sizeof(struct s_ipv4_addr));
/* compute ICMP checksum */ /* compute ICMP checksum */
icmp->checksum = 0x0; icmp->checksum = 0x0;

View File

@ -220,8 +220,7 @@ int tcp_ipv4(struct s_ethernet *eth4, struct s_ipv4 *ip4, char *payload,
ip6->flow_label = 0x0; ip6->flow_label = 0x0;
ip6->hop_limit = ip4->ttl; ip6->hop_limit = ip4->ttl;
ipv4_to_ipv6(&ip4->ip_src, &ip6->ip_src); ipv4_to_ipv6(&ip4->ip_src, &ip6->ip_src);
memcpy(&ip6->ip_dest, &connection->ipv6, ip6->ip_dest = connection->ipv6;
sizeof(struct s_ipv6_addr));
/* set incoming source port */ /* set incoming source port */
tcp->port_dest = connection->ipv6_port_src; tcp->port_dest = connection->ipv6_port_src;
@ -367,8 +366,7 @@ int tcp_ipv4(struct s_ethernet *eth4, struct s_ipv4 *ip4, char *payload,
ip6->hop_limit = ip4->ttl; ip6->hop_limit = ip4->ttl;
ip6->next_header = IPPROTO_FRAGMENT; ip6->next_header = IPPROTO_FRAGMENT;
ipv4_to_ipv6(&ip4->ip_src, &ip6->ip_src); ipv4_to_ipv6(&ip4->ip_src, &ip6->ip_src);
memcpy(&ip6->ip_dest, &connection->ipv6, ip6->ip_dest = connection->ipv6;
sizeof(struct s_ipv6_addr));
/* build IPv6 fragment header */ /* build IPv6 fragment header */
frag->next_header = IPPROTO_TCP; frag->next_header = IPPROTO_TCP;
@ -579,8 +577,8 @@ int tcp_ipv6(struct s_ethernet *eth6, struct s_ipv6 *ip6, char *payload)
ip4->flags_offset = htons(IPV4_FLAG_DONT_FRAGMENT); ip4->flags_offset = htons(IPV4_FLAG_DONT_FRAGMENT);
ip4->ttl = ip6->hop_limit; ip4->ttl = ip6->hop_limit;
ip4->proto = IPPROTO_TCP; ip4->proto = IPPROTO_TCP;
ip4->ip_src = wrapsix_ipv4_addr;
ipv6_to_ipv4(&ip6->ip_dest, &ip4->ip_dest); ipv6_to_ipv4(&ip6->ip_dest, &ip4->ip_dest);
memcpy(&ip4->ip_src, &wrapsix_ipv4_addr, sizeof(struct s_ipv4_addr));
/* set outgoing source port */ /* set outgoing source port */
tcp->port_src = connection->ipv4_port_src; tcp->port_src = connection->ipv4_port_src;

View File

@ -108,7 +108,7 @@ int udp_ipv4(struct s_ethernet *eth4, struct s_ipv4 *ip4, char *payload,
ip6->next_header = IPPROTO_UDP; ip6->next_header = IPPROTO_UDP;
ip6->hop_limit = ip4->ttl; ip6->hop_limit = ip4->ttl;
ipv4_to_ipv6(&ip4->ip_src, &ip6->ip_src); ipv4_to_ipv6(&ip4->ip_src, &ip6->ip_src);
memcpy(&ip6->ip_dest, &connection->ipv6, sizeof(struct s_ipv6_addr)); ip6->ip_dest = connection->ipv6;
/* set incoming source port */ /* set incoming source port */
udp->port_dest = connection->ipv6_port_src; udp->port_dest = connection->ipv6_port_src;
@ -210,8 +210,8 @@ int udp_ipv6(struct s_ethernet *eth6, struct s_ipv6 *ip6, char *payload)
ip4->flags_offset = htons(IPV4_FLAG_DONT_FRAGMENT); ip4->flags_offset = htons(IPV4_FLAG_DONT_FRAGMENT);
ip4->ttl = ip6->hop_limit; ip4->ttl = ip6->hop_limit;
ip4->proto = IPPROTO_UDP; ip4->proto = IPPROTO_UDP;
ip4->ip_src = wrapsix_ipv4_addr;
ipv6_to_ipv4(&ip6->ip_dest, &ip4->ip_dest); ipv6_to_ipv4(&ip6->ip_dest, &ip4->ip_dest);
memcpy(&ip4->ip_src, &wrapsix_ipv4_addr, sizeof(struct s_ipv4_addr));
/* set outgoing source port */ /* set outgoing source port */
udp->port_src = connection->ipv4_port_src; udp->port_src = connection->ipv4_port_src;