Fixing address resolution via getaddrinfo in libfreeswan. 4.3.4
authorTobias Brunner <tobias@strongswan.org>
Tue, 18 Aug 2009 10:30:11 +0000 (12:30 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 18 Aug 2009 10:30:11 +0000 (12:30 +0200)
src/libfreeswan/atoaddr.c
src/libfreeswan/ttoaddr.c

index c962a16..cbda541 100644 (file)
@@ -108,7 +108,8 @@ struct in_addr *addrp;
        }
        else
        {
-               memcpy(&addrp->s_addr, res->ai_addr->sa_data, sizeof(addrp->s_addr));
+               struct sockaddr_in *in = (struct sockaddr_in*)res->ai_addr;
+               memcpy(&addrp->s_addr, &in->sin_addr.s_addr, sizeof(addrp->s_addr));
                freeaddrinfo(res);
        }
 
index ede0713..bda2be5 100644 (file)
@@ -202,8 +202,35 @@ ip_address *dst;
        }
        else
        {
-               addr = res->ai_addr->sa_data;
-               err = initaddr(addr, res->ai_addrlen, af, dst);
+               struct addrinfo *r = res;
+               while (r)
+               {
+                       size_t addr_len;
+                       switch (r->ai_family)
+                       {
+                               case AF_INET:
+                               {
+                                       struct sockaddr_in *in = (struct sockaddr_in*)r->ai_addr;
+                                       addr_len = 4;
+                                       addr = (unsigned char*)&in->sin_addr.s_addr;
+                                       break;
+                               }
+                               case AF_INET6:
+                               {
+                                       struct sockaddr_in6 *in6 = (struct sockaddr_in6*)r->ai_addr;
+                                       addr_len = 16;
+                                       addr = (unsigned char*)&in6->sin6_addr.s6_addr;
+                                       break;
+                               }
+                               default:
+                               {       /* unknown family, try next result */
+                                       r = r->ai_next;
+                                       continue;
+                               }
+                       }
+                       err = initaddr(addr, addr_len, r->ai_family, dst);
+                       break;
+               }
                freeaddrinfo(res);
        }