till now i'm using objects of InetAddress to create and verify ip-addresses. if the client enters a ip-address, i check if i can derive a new InetAddress object. if the ip is invalid ("3126.96.36.199"), InetAddress will return a null value.
(my experience tells me that it is always better to work with specialized object, if they are provided)
but now i discovered that InetAddress returns null for 127.0.0.1 (localhost), and probably for all ip-values below 127.x.x.x too. as far as i know this would not be correct for meeting my requirement, as a user can at least use localhost to let (one?) client and server run on the same machine, and probably also setup a local network with ip's below 127.x.x.x
how are you verifying the ip-input? are you doing this string based? or is there a better way?
I didn't, and lost nothing in that section if that means anything. If you're hell bent on doing it then maybe attempt to connect, there may be a better way but that's foolproof. Well almost, the machine may not be available when the user does the configuration. Sooooo, IMO, allow absolutely anything, I did a range check on ports, but allowed every one of them within the range, it was documented to be up to the user to know which ports they can/can't use or deal with the message and try again. On the plus side with allowing everything a user can type the name of the host instead of pinging "jan" to see the ip.
Joined: Feb 03, 2004
thanks for you answer!
i decided to build a little LocalIp class, with a appropriate constructor and a isCorrect() method. less then 30 lines of code, and a big simplification for my code...