Question

I'm trying to write a quick little java application to read the contents of a pcap file (from Wireshark) and play the data back on the network on a linux box. The file will only contain UDP broadcast packets, so my application only really needs the timestamp, port number, and data from the packet to do what I need. My problem is that the application that I'm trying to test with this code is listening for IPv4 UDP broadcasts on Windows. My test application keeps opening an IPv6 socket to send the data out.

I'm using netstat -a -u -p to determine that the socket is a udp6 socket. On windows I know it isn't.

What is the easiest or best way to force the test app on linux in java to open a udp or udp4 socket instead? I don't want to be forced in to providing the ipv4 network address each time. I want to be able to move this code to another machine without having to remember that their is some configuration that needs to be changed.

Was it helpful?

Solution

Add -Djava.net.preferIPv4Stack=true to your Java application runtime properties.

OTHER TIPS

Also you can use this command (as root) and you will not need to add the -Djava.net.preferIPv4Stack=true parameter in every java application:

 # echo 0 > /proc/sys/net/ipv6/bindv6only

If you want to keep this configuration forever you can write it in some initial script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top