/* 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. */
+ /* 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
- if (sizeof (addr) == 8)
- addr <<= 32;
+ offset = sizeof (unsigned long) - 4;
#endif
- memcpy (where, &addr, 4);
+ memcpy (where, (char *)&addr + offset, 4);
return 1;
}
/* Since all else has failed, let's try gethostbyname(). Note that