How can I convert a hex ip (such as 42477f35), and get it to spit out the correct decimal ip (in the example before, the correct result is 66.71.127.53
42477f35
66.71.127.53
This is one possibility:
#include int ip_hex_to_dquad(const char *input, char *output, size_t outlen) { unsigned int a, b, c, d; if (sscanf(input, "%2x%2x%2x%2x", &a, &b, &c, &d) != 4) return -1; snprintf(output, outlen, "%u.%u.%u.%u", a, b, c, d); return 0; }