Add code to get IPv4 addresses from 6to4 and Teredo IPv6 addresses.

It is not used yet.
This commit is contained in:
Jilles Tjoelker 2012-01-08 15:27:26 +01:00
parent 9319a2e206
commit 524a5b3ac7
3 changed files with 109 additions and 0 deletions

44
include/ipv4_from_ipv6.h Normal file
View file

@ -0,0 +1,44 @@
/*
* charybdis: An advanced ircd.
* ipv4_from_ipv6.h: Finds IPv4 addresses behind IPv6 transition technologies
*
* Copyright (C) 2012 Jilles Tjoelker
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*/
#ifndef _IPV4_FROM_IPV6_H_
#define _IPV4_FROM_IPV6_H_
#ifdef RB_IPV6
int ipv4_from_ipv6(const struct sockaddr_in6 *restrict ip6,
struct sockaddr_in *restrict ip4);
#endif
#endif

View file

@ -66,6 +66,7 @@ SRCS = \
hash.c \
hook.c \
hostmask.c \
ipv4_from_ipv6.c \
irc_dictionary.c \
ircd.c \
ircd_signal.c \

64
src/ipv4_from_ipv6.c Normal file
View file

@ -0,0 +1,64 @@
/*
* charybdis: A slightly useful ircd.
* ipv4_from_ipv6.c: Finds IPv4 addresses behind IPv6 transition technologies
*
* Copyright (C) 2012 Jilles Tjoelker
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "stdinc.h"
#include "ipv4_from_ipv6.h"
#ifdef RB_IPV6
int
ipv4_from_ipv6(const struct sockaddr_in6 *restrict ip6,
struct sockaddr_in *restrict ip4)
{
int i;
if (!memcmp(ip6->sin6_addr.s6_addr, "\x20\x02", 2))
{
/* 6to4 and similar */
memcpy(&ip4->sin_addr, ip6->sin6_addr.s6_addr + 2, 4);
}
else if (!memcmp(ip6->sin6_addr.s6_addr, "\x20\x01\x00\x00", 4))
{
/* Teredo */
for (i = 0; i < 4; i++)
((uint8_t *)&ip4->sin_addr)[i] = 0xFF ^
ip6->sin6_addr.s6_addr[12 + i];
}
else
return 0;
SET_SS_LEN(ip4, sizeof(struct sockaddr_in));
ip4->sin_family = AF_INET;
ip4->sin_port = 0;
return 1;
}
#endif /* RB_IPV6 */