Reputation: 1467
How can I convert an IP in hex
format (eg. 0101007F) to Dotted Decimal
using C++ in Linux?
Upvotes: 2
Views: 1261
Reputation: 172618
You can try like this:
static char* hexdecimal_to_decimalip(const char *in)
{
char *out = (char*)malloc(sizeof(char) * 16);
unsigned int p, q, r, s;
if (sscanf(in, "%2x%2x%2x%2x", &p, &q, &r, &s) != 4)
return out;
sprintf(out, "%u.%u.%u.%u", p, q, r, s);
return out;
}
Upvotes: 1