+#endif
+ abort();
+}
+
+/**
+ * wget_sockaddr_get_addr
+ *
+ * This function return the adress from an sockaddr as byte string.
+ * Unsuported adress family will abort the whole programm.
+ *
+ * Require:
+ * that the IP-Protocol already is set.
+ *
+ * Input:
+ * wget_sockaddr* Socket Information
+ *
+ * Output:
+ * unsigned char * IP address as byte string.
+ */
+void *
+wget_sockaddr_get_addr (wget_sockaddr *sa)
+{
+ if (sa->sa.sa_family == AF_INET)
+ return &sa->sin.sin_addr;
+#ifdef INET6
+ if (sa->sa.sa_family == AF_INET6)
+ return &sa->sin6.sin6_addr;
+#endif
+ abort();
+ /* unreached */
+ return NULL;
+}
+
+/**
+ * wget_sockaddr_get_port
+ *
+ * This function only return the port from the input structure
+ * Unsuported adress family will abort the whole programm.
+ *
+ * Require:
+ * that the IP-Protocol already is set.
+ *
+ * Input:
+ * wget_sockaddr* Information where to get the port
+ *
+ * Output:
+ * unsigned short Port Number in host order.
+ */
+unsigned short
+wget_sockaddr_get_port (const wget_sockaddr *sa)
+{
+ if (sa->sa.sa_family == AF_INET)
+ return htons (sa->sin.sin_port);
+#ifdef INET6
+ if (sa->sa.sa_family == AF_INET6)
+ return htons (sa->sin6.sin6_port);
+#endif
+ abort();
+ /* do not complain about return nothing */
+ return -1;
+}
+
+/**
+ * sockaddr_len
+ *
+ * This function return the length of the sockaddr corresponding to
+ * the acutall prefered protocol for (bind, connect etc...)
+ * Unsuported adress family will abort the whole programm.
+ *
+ * Require:
+ * that the IP-Protocol already is set.
+ *
+ * Input:
+ * - Public IP-Family Information
+ *
+ * Output:
+ * int structure length for socket options
+ */
+int
+sockaddr_len ()
+{
+ if (ip_default_family == AF_INET)
+ return sizeof (struct sockaddr_in);
+#ifdef INET6
+ if (ip_default_family == AF_INET6)
+ return sizeof (struct sockaddr_in6);
+#endif
+ abort();
+ /* do not complain about return nothing */
+ return 0;
+}
+
+/**
+ * Map an IPv4 adress to the internal adress format.
+ */
+void
+map_ipv4_to_ip (ip4_address *ipv4, ip_address *ip)
+{
+#ifdef INET6
+ static unsigned char ipv64[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff};
+ memcpy ((char *)ip + 12, ipv4 , 4);
+ memcpy ((char *)ip + 0, ipv64, 12);
+#else
+ if ((char *)ip != (char *)ipv4)
+ memcpy (ip, ipv4, 4);
+#endif
+}