views:

590

answers:

1

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.

+10  A: 

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

Don't you feel that having a "sigblock" in your answer is a bit much? Your name is, after all, right there in the bottom right corner of your answer, clickable and everything ...
unwind