]> sjero.net Git - wget/blobdiff - src/host.c
[svn] Updated long_to_string(); enhanced opt.downloaded to use
[wget] / src / host.c
index 1b6abf35a1baeb77371b29cf68fda88b5e8f46a9..1ff8150f60c07fa63209fb5867222adcf781c536 100644 (file)
@@ -144,10 +144,15 @@ store_hostaddress (unsigned char *where, const char *hostname)
   /* If we have the numeric address, just store it.  */
   if ((int)addr != -1)
     {
-      /* This works on both little and big endian architecture, as
-        inet_addr returns the address in the proper order.  It
-        appears to work on 64-bit machines too.  */
-      memcpy (where, &addr, 4);
+      /* ADDR is in network byte order, meaning the code works on
+         little and big endian 32-bit architectures without change.
+         On big endian 64-bit architectures we need to be careful to
+         copy the correct four bytes.  */
+      int offset = 0;
+#ifdef WORDS_BIGENDIAN
+      offset = sizeof (unsigned long) - 4;
+#endif
+      memcpy (where, (char *)&addr + offset, 4);
       return 1;
     }
   /* Since all else has failed, let's try gethostbyname().  Note that