- {
- struct sockaddr_in *sinp =
- (struct sockaddr_in *) (*pai)->ai_addr;
-
- memcpy (&sinp->sin_addr,
- at2->addr, sizeof (struct in_addr));
- sinp->sin_port = st2->port;
- memset (sinp->sin_zero, '\0', sizeof (sinp->sin_zero));
- }
-
- if (c)
- {
- (*pai)->ai_canonname = ((void *) (*pai) +
- sizeof (struct addrinfo) + socklen);
- strcpy ((*pai)->ai_canonname, c);
+#if defined __UCLIBC_HAS_IPV4__ && defined __UCLIBC_HAS_IPV6__
+ else
+#endif
+#if defined __UCLIBC_HAS_IPV4__
+ {
+ family = AF_INET;
+ socklen = sizeof(struct sockaddr_in);
+ }
+#endif
+ for (st2 = st; st2 != NULL; st2 = st2->next) {
+ if (req->ai_flags & AI_ADDRCONFIG) {
+ if (family == AF_INET && !(seen & SEEN_IPV4))
+ break;
+#if defined __UCLIBC_HAS_IPV6__
+ else if (family == AF_INET6 && !(seen & SEEN_IPV6))
+ break;
+#endif
+ }
+ *pai = malloc(sizeof(struct addrinfo) + socklen + namelen);
+ if (*pai == NULL)
+ return -EAI_MEMORY;
+
+ (*pai)->ai_flags = req->ai_flags;
+ (*pai)->ai_family = family;
+ (*pai)->ai_socktype = st2->socktype;
+ (*pai)->ai_protocol = st2->protocol;
+ (*pai)->ai_addrlen = socklen;
+ (*pai)->ai_addr = (void *) (*pai) + sizeof(struct addrinfo);
+#if 0 /* SALEN */
+ (*pai)->ai_addr->sa_len = socklen;
+#endif
+ (*pai)->ai_addr->sa_family = family;
+
+#if defined __UCLIBC_HAS_IPV6__
+ if (family == AF_INET6) {
+ struct sockaddr_in6 *sin6p = (struct sockaddr_in6 *) (*pai)->ai_addr;
+
+ sin6p->sin6_flowinfo = 0;
+ if (at2->family == AF_INET6) {
+ memcpy(&sin6p->sin6_addr,
+ at2->addr, sizeof(struct in6_addr));
+ } else {
+ sin6p->sin6_addr.s6_addr32[0] = 0;
+ sin6p->sin6_addr.s6_addr32[1] = 0;
+ sin6p->sin6_addr.s6_addr32[2] = htonl(0x0000ffff);
+ memcpy(&sin6p->sin6_addr.s6_addr32[3],
+ at2->addr, sizeof(sin6p->sin6_addr.s6_addr32[3]));
+ }
+ sin6p->sin6_port = st2->port;
+ sin6p->sin6_scope_id = at2->scopeid;
+ }
+#endif
+#if defined __UCLIBC_HAS_IPV4__ && defined __UCLIBC_HAS_IPV6__
+ else
+#endif
+#if defined __UCLIBC_HAS_IPV4__
+ {
+ struct sockaddr_in *sinp = (struct sockaddr_in *) (*pai)->ai_addr;
+
+ memcpy(&sinp->sin_addr, at2->addr, sizeof(struct in_addr));
+ sinp->sin_port = st2->port;
+ memset(sinp->sin_zero, '\0', sizeof(sinp->sin_zero));
+ }
+#endif
+ if (c) {
+ (*pai)->ai_canonname = ((void *) (*pai) +
+ sizeof(struct addrinfo) + socklen);
+ strcpy((*pai)->ai_canonname, c);
+ } else {
+ (*pai)->ai_canonname = NULL;
+ }
+ (*pai)->ai_next = NULL;
+ pai = &((*pai)->ai_next);
+ }
+
+ at2 = at2->next;