Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endianness in the is_ip_valid() function #25

Open
lese123 opened this issue Aug 14, 2020 · 0 comments
Open

Endianness in the is_ip_valid() function #25

lese123 opened this issue Aug 14, 2020 · 0 comments

Comments

@lese123
Copy link

lese123 commented Aug 14, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant