summaryrefslogtreecommitdiff
path: root/net/wget/patches/patch-ac
blob: bed5e0b9f47b312259782c150ace76ea611eb0dd (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
$NetBSD: patch-ac,v 1.7 2005/01/25 20:07:25 bouyer Exp $

--- src/host.c.orig	Sun Oct 26 02:38:25 2003
+++ src/host.c	Sun Jan 23 21:23:28 2005
@@ -189,13 +189,15 @@
     if (ai->ai_family == AF_INET6) 
       {
 	struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)ai->ai_addr;
-	memcpy (al->addresses + i, &sin6->sin6_addr, 16);
+	memcpy (al->addresses[i].bytes, &sin6->sin6_addr, 16);
+	al->addresses[i].family = AF_INET6;
 	++i;
       } 
     else if (ai->ai_family == AF_INET)
       {
 	struct sockaddr_in *sin = (struct sockaddr_in *)ai->ai_addr;
-        map_ipv4_to_ip ((ip4_address *)&sin->sin_addr, al->addresses + i);
+	memcpy (al->addresses[i].bytes, &sin->sin_addr, 4);
+	al->addresses[i].family = AF_INET;
 	++i;
       }
   assert (i == cnt);
@@ -219,8 +221,11 @@
   al->addresses = xmalloc (count * sizeof (ip_address));
   al->refcount  = 1;
 
-  for (i = 0; i < count; i++)
-    map_ipv4_to_ip ((ip4_address *)h_addr_list[i], al->addresses + i);
+  for (i = 0; i < count; i++) {
+    memcpy (al->addresses[i].bytes, h_addr_list[i], 4);
+    al->addresses[i].family = AF_INET;
+  }
+
 
   return al;
 }
@@ -279,33 +284,29 @@
   */
 void
 wget_sockaddr_set_address (wget_sockaddr *sa, 
-			   int ip_family, unsigned short port, ip_address *addr)
+			   unsigned short port, ip_address *addr, int family)
 {
-  if (ip_family == AF_INET) 
+  if (family == AF_INET)
     {
-      sa->sin.sin_family = ip_family;
+      sa->sin.sin_family = AF_INET;
       sa->sin.sin_port = htons (port);
       if (addr == NULL) 
 	memset (&sa->sin.sin_addr, 0,      sizeof(ip4_address));
       else
 	{
-	  ip4_address addr4;
-	  if (!map_ip_to_ipv4 (addr, &addr4))
-	    /* should the callers have prevented this? */
-	    abort ();
-	  memcpy (&sa->sin.sin_addr, &addr4, sizeof(ip4_address));
+	  memcpy (&sa->sin.sin_addr, addr->bytes, sizeof(ip4_address));
 	}
       return;
     }
 #ifdef ENABLE_IPV6
-  if (ip_family == AF_INET6) 
+  if (family == AF_INET6)
     {
-      sa->sin6.sin6_family = ip_family;
+      sa->sin6.sin6_family = AF_INET6;
       sa->sin6.sin6_port = htons (port);
       if (addr == NULL) 
 	memset (&sa->sin6.sin6_addr, 0   , 16);
       else	     
-	memcpy (&sa->sin6.sin6_addr, addr, 16);
+	memcpy (&sa->sin6.sin6_addr, addr->bytes, 16);
       return;
     }
 #endif  
@@ -422,12 +423,12 @@
   * socklen_t	structure length for socket options
   */
 socklen_t
-sockaddr_len () 
+sockaddr_len (int family) 
 {
-  if (ip_default_family == AF_INET) 
+  if (family == AF_INET) 
     return sizeof (struct sockaddr_in);
 #ifdef ENABLE_IPV6
-  if (ip_default_family == AF_INET6) 
+  if (family == AF_INET6) 
     return sizeof (struct sockaddr_in6);
 #endif
   abort();
@@ -435,42 +436,6 @@
   return 0;
 }
 
-/**
-  * Map an IPv4 adress to the internal adress format.
-  */
-void 
-map_ipv4_to_ip (ip4_address *ipv4, ip_address *ip) 
-{
-#ifdef ENABLE_IPV6
-  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
-}
-
-/* Detect whether an IP adress represents an IPv4 address and, if so,
-   copy it to IPV4.  0 is returned on failure.
-   This operation always succeeds when Wget is compiled without IPv6.
-   If IPV4 is NULL, don't copy, just detect.  */
-
-int 
-map_ip_to_ipv4 (ip_address *ip, ip4_address *ipv4) 
-{
-#ifdef ENABLE_IPV6
-  static unsigned char ipv64[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff};
-  if (0 != memcmp (ip, ipv64, 12))
-    return 0;
-  if (ipv4)
-    memcpy (ipv4, (char *)ip + 12, 4);
-#else
-  if (ipv4)
-    memcpy (ipv4, (char *)ip, 4);
-#endif
-  return 1;
-}
 
 /* Versions of gethostbyname and getaddrinfo that support timeout. */
 
@@ -559,17 +524,16 @@
 pretty_print_address (ip_address *addr)
 {
 #ifdef ENABLE_IPV6
-  ip4_address addr4;
   static char buf[128];
 
-  if (map_ip_to_ipv4 (addr, &addr4))
-    return inet_ntoa (*(struct in_addr *)&addr4);
-
-  if (!inet_ntop (AF_INET6, addr, buf, sizeof (buf)))
-    return "<unknown>";
-  return buf;
+  if (addr->family == AF_INET6)
+    {
+      if (!inet_ntop (AF_INET6, addr->bytes, buf, sizeof (buf)))
+        return "<unknown>";
+      return buf;
+    }
 #endif
-  return inet_ntoa (*(struct in_addr *)addr);
+  return inet_ntoa (*(struct in_addr *)addr->bytes);
 }
 
 /* Add host name HOST with the address ADDR_TEXT to the cache.
@@ -601,23 +565,27 @@
 lookup_host (const char *host, int silent)
 {
   struct address_list *al = NULL;
-  uint32_t addr_ipv4;
   ip_address addr;
+  u_int32_t addr4;
 
   /* First, try to check whether the address is already a numeric
      address.  */
 
 #ifdef ENABLE_IPV6
-  if (inet_pton (AF_INET6, host, &addr) > 0)
-    return address_list_from_single (&addr);
+  if (inet_pton (AF_INET6, host, addr.bytes) > 0)
+    {
+      addr.family = AF_INET6;
+      return address_list_from_single (&addr);
+    }
 #endif
 
-  addr_ipv4 = (uint32_t)inet_addr (host);
-  if (addr_ipv4 != (uint32_t)-1)
+  addr4 = (uint32_t)inet_addr (host);
+  memcpy(addr.bytes, &addr4, 4);
+  addr.family = AF_INET;
+  if (addr4 != (uint32_t)-1)
     {
       /* ADDR is defined to be in network byte order, which is what
 	 this returns, so we can just copy it to STORE_IP.  */
-      map_ipv4_to_ip ((ip4_address *)&addr_ipv4, &addr);
       return address_list_from_single (&addr);
     }