mirror of
https://github.com/nmap/nmap.git
synced 2026-01-03 05:09:14 +00:00
Remove byte order dependency in in_addr_to_octets.
Because in_addr is stored in network byte order, this function could extract the octets in MSB-to-LSB order or in LSB-to-MSB order. This didn't matter in the case of resolved names, because the same order was used when generating the octet array and later when matching against it. But the function parse_ipv4_ranges, which handles literal IPv4 addresses, always uses octet[0] as the MSB, so comparisons failed in later matching. As it was, the code worked on little-endian architectures but didn't on big-endian.
This commit is contained in:
@@ -203,13 +203,16 @@ static char *address_to_string(const struct sockaddr *sa, size_t sa_len,
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Break an IPv4 address into an array of octets. */
|
||||
/* Break an IPv4 address into an array of octets. octets[0] contains the most
|
||||
significant octet and octets[3] the least significant. */
|
||||
static void in_addr_to_octets(const struct in_addr *ia, uint8_t octets[4])
|
||||
{
|
||||
octets[0] = (uint8_t) (ia->s_addr & 0xFF);
|
||||
octets[1] = (uint8_t) ((ia->s_addr & (0xFF << 8)) >> 8);
|
||||
octets[2] = (uint8_t) ((ia->s_addr & (0xFF << 16)) >> 16);
|
||||
octets[3] = (uint8_t) ((ia->s_addr & (0xFF << 24)) >> 24);
|
||||
u32 hbo = ntohl(ia->s_addr);
|
||||
|
||||
octets[0] = (uint8_t) ((hbo & (0xFF << 24)) >> 24);
|
||||
octets[1] = (uint8_t) ((hbo & (0xFF << 16)) >> 16);
|
||||
octets[2] = (uint8_t) ((hbo & (0xFF << 8)) >> 8);
|
||||
octets[3] = (uint8_t) (hbo & 0xFF);
|
||||
}
|
||||
|
||||
#define BITVECTOR_BITS (sizeof(bitvector_t) * CHAR_BIT)
|
||||
|
||||
Reference in New Issue
Block a user