The manual for inet_ntoa
says:
The string is returned in a statically allocated buffer, which subsequent calls will overwrite.
You have two functions in printf("c:%s %s\n", inet_ntoa(c), inet_ntoa(d));
that overwrite the same buffer.
Try if (inet_ntoa(c) == inet_ntoa(d))
, you may be surprised by the result.