Skip to content

Endianness in the is_ip_valid() function #25

@lese123

Description

@lese123

Line 603 of the is_ip_valid function in the ip.c file:

                if (ipXto4(*ip) != INADDR_LOOPBACK && ipXto4(*ip) != INADDR_NONE)
                        return YES;

It only works on a big endian device. On a little endian device, ipXto4(*ip) of a loopback device has the value 0x100007f while INADDR_LOOPBACK has the value 0x7f000001.

Should we use something like htonl' to convert IP addresses from host order to network order before the comparison?

Also on line 592, for an IPv6 loopback address ::1, is_zero((void*) ip, sizeof ( IPX_T) - sizeof (IP4_T) always evaluates TRUE but family is AF_INET6, so the condition (family != (is_zero((void*) ip, sizeof ( IPX_T) - sizeof (IP4_T)) ? AF_INET : AF_INET6) is alway TRUE. Line 595 to 598 will always be skipped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions