File: ipv6_conv.c

package info (click to toggle)
dcc 1.2.74-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,552 kB
  • ctags: 4,041
  • sloc: ansic: 41,034; perl: 2,310; sh: 2,186; makefile: 224
file content (56 lines) | stat: -rw-r--r-- 1,632 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Distributed Checksum Clearinghouse
 *
 * Copyright (c) 2005 by Rhyolite Software
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE DISCLAIMS ALL
 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE
 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 *
 * Rhyolite Software DCC 1.2.74-1.10 $Revision$
 */

#include "dcc_defs.h"


/* convert IPv4 address to IPv6 */
void
dcc_ipv4toipv6(struct in6_addr *dst, const struct in_addr src)
{
	/* do it in an order that allows dst==src */
	dst->s6_addr32[3] = src.s_addr;
	dst->s6_addr32[0] = 0;
	dst->s6_addr32[1] = 0;
	dst->s6_addr32[2] = htonl(0xffff);
}



/* try to convert IPv6 address to IPv4 */
u_char					/* 1=did it */
dcc_ipv6toipv4(struct in_addr *dst, const struct in6_addr *src)
{
	if (DCC_IN6_ADDR_V4MAPPED(src)) {
		dst->s_addr = src->s6_addr32[3];
		return 1;
	}

	if (src->s6_addr32[0] != 0
	    || src->s6_addr32[1] != 0
	    || src->s6_addr32[2] != 0)
		return 0;

	if (src->s6_addr32[3] == ntohl(1))
		dst->s_addr = ntohl(0x7f000001);
	else
		dst->s_addr = src->s6_addr32[3];
	return 1;
}