How would I convert an ip address into bytes in C++? Basically how do I parse the IP address? For example, if I have a string equal to 121.122.123.124
.
I need
Try this:
char ipstr[] = "121.122.123.124";
char *marker, *ret;
unsigned char b1, b2, b3, b4;
ret = strtok_r(ipstr, ".", &marker);
b1 = (unsigned char)strtod(ret, NULL);
ret = strtok_r(NULL, ".", &marker);
b2 = (unsigned char)strtod(ret, NULL);
ret = strtok_r(NULL, ".", &marker);
b3 = (unsigned char)strtod(ret, NULL);
ret = strtok_r(NULL, ".", &marker);
b4 = (unsigned char)strtod(ret, NULL);