Back to index

courier  0.68.2
rfc1035ipv6to4.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2000-2003 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #include      "config.h"
00007 #include      "rfc1035.h"
00008 #include      <stdio.h>
00009 #include      <string.h>
00010 #include      <stdlib.h>
00011 #include      <arpa/inet.h>
00012 
00013 
00014 #if RFC1035_FREEBSD40
00015 #define       s6_addr16     __u6_addr.__u6_addr16
00016 #define s6_addr32    __u6_addr.__u6_addr32
00017 #endif
00018 
00019 #if RFC1035_SOLARIS8
00020 #define s6_addr32    _S6_un._S6_u32
00021 #endif
00022 
00023 #if RFC1035_IPV6
00024 
00025 void rfc1035_ipv6to4(struct in_addr *ip4, const struct in6_addr *ip6)
00026 {
00027        ip4->s_addr=ip6->s6_addr32[3];
00028 }
00029 
00030 void rfc1035_ipv4to6(struct in6_addr *ip6, const struct in_addr *ip4)
00031 {
00032        memset(ip6, 0, sizeof(*ip6));
00033 
00034 #if RFC1035_SOLARIS8
00035 
00036        /* No 16-bit union <grumble>... */
00037 
00038        ip6->_S6_un._S6_u8[10]= ~0;
00039        ip6->_S6_un._S6_u8[11]= ~0;
00040 
00041 #else
00042        ip6->s6_addr16[5]= ~0;
00043 #endif
00044 
00045        ip6->s6_addr32[3]= ip4->s_addr;
00046 
00047        if (ip4->s_addr == INADDR_ANY)
00048               *ip6= in6addr_any;
00049 }
00050 #endif
00051