Easiest (and, afaik the best) way would be with sscanf:
I read your post after placing this.. (I did quickly go over it but didn't really read it, oops) how does strfind() not work for you? It either returns -1 (string you're looking for not found), or it returns the first character of the found string (or according to the wiki: "The number of characters before the sub string (the sub string's start position) ", so basically the same thing)
To come back to the sscanf example, this would be an alternative way:
.
Code:
new
ip[] = "192.168.2.10";
ip_part1,
ip_part2,
ip_part3,
ip_part4
;
sscanf(ip, "p<.>dddd", ip_part1, ip_part2, ip_part3, ip_part4);
//OR, if you (as the title suggests) really just want the last part:
sscanf(ip, "p<.>{ddd}d", ip_part4);
//ip_part1 = 192
//ip_part2 = 168
//ip_part3 = 2
//ip_part4 = 10
I read your post after placing this.. (I did quickly go over it but didn't really read it, oops) how does strfind() not work for you? It either returns -1 (string you're looking for not found), or it returns the first character of the found string (or according to the wiki: "The number of characters before the sub string (the sub string's start position) ", so basically the same thing)
Code:
new ip[] = "192.168.1.200";
if (strfind(ip, "192.168.1") == 0) //0, because "192.168.1" should be found in "192.168.1.200".
//That found character 'has no characters before the sub string' (so, the found string started at index 0)
{
//OK, Accepted LAN IP
}
else
{
//NOK, VPN?
}
To come back to the sscanf example, this would be an alternative way:
Code:
new
ip[] = "192.168.1.200";
ip_part1,
ip_part2,
ip_part3,
ip_part4
;
sscanf(ip, "p<.>dddd", ip_part1, ip_part2, ip_part3, ip_part4);
if (ip_part1 == 192 && ip_part2 == 168 && ip_part3 == 1 && (1 <= ip_part4 <= 255))
{
//OK, Accepted LAN IP
}
else
{
//NOK, VPN?
}