Here is how I do an IP address. I inferred this method from the Windows SDK headers and it just made sense to me. I've never tried using strtok() for this sort of thing. Perhaps this is the method //Tator had in mind.
String to IP:
DWORD IP_FromString(LPTSTR szIP)
{
// Assumes a properly formed IP string
// A proper implementation should check
// strlen() and formatting.
BYTE ip[4] = { 0, 0, 0, 0 };
_stscanf(szIP, _T("%hhd.%hhd.%hhd.%hhd"), &ip[3], &ip[2], &ip[1], &ip[0]);
return * (LPDWORD)ip;
}
IP to string
void IP_ToString(DWORD dwIP, LPTSTR buf, INT cchBuf)
{
// Assumes a buffer of sufficient length
BYTE ip[4];
*((LPDWORD)ip) = dwIP;
_stprintf(buf, cchBuf, _T("%d.%d.%d.%d"), ip[3], ip[2], ip[1], ip[0]);
}