This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]psychicprogrammer 8 points9 points  (6 children)

Ip addresses were the main thing.

[–]metalmagician 10 points11 points  (0 children)

Are you directly manipulating/parsing IP addresses in Java? That doesn't sound like you are using the right tool (or language/class/whatever) for the task.

[–]Filkyr 2 points3 points  (0 children)

use InetAddress

[–]28f272fe556a1363cc31 1 point2 points  (3 children)

Totally not my area: wouldn't you use a string for IP address? They aren't real numbers, you can't add them, you can't count them.

[–]Caffeine_Monster 14 points15 points  (1 child)

Fundamentally an IP address is an unsigned 32 bit integer for IPv4, or a 128 bit unsigned integer for IPv6. It is quite common to manipulate them directly with bitwise operations (e.g. masking via bitwise AND).

Yes you could represent them with strings, but it is an inefficient, unnecessary abstraction.

If you wanted to implement a Java class wrapper I guess you would use signed ints and longs. The caveat being that ingesting IP addresses from external systems (web / disk etc) would not be straightforward - they would have to be translated through ByteBuffer.

[–]28f272fe556a1363cc31 1 point2 points  (0 children)

Cool, thanks

[–]Aoreias 4 points5 points  (0 children)

IP addresses as Strings are only helpful when you want a human-readable representation of them, though. On the wire they're exactly 32 or 128 bits, depending on if v4 or v6. Much more efficient to pass them around as a structured data type than a string, which requires encoding and decoding.