Peter Mel
Peter Mel

Reputation: 367

How to use Java to determine if the machine I am running in is using ipv4 or ipv6?

I need to return 0.0.0.0 for the bind IP of an UDP socket in Java. But I am not sure if I should return "0.0.0.0" (ipv4) or "::" (ipv6) for the host of my socket. Can I always return "0.0.0.0" and it will work? Or should I have to first find out if the machine I am running on is ipv4 or ipv6?

Upvotes: 4

Views: 160

Answers (1)

user207421
user207421

Reputation: 311048

need to return 0.0.0.0 for the bind IP of an UDP socket in Java.

Why? Just use an InetAddress of null. It means the same thing, but it is IP-version-agnostic.

Upvotes: 2

Related Questions