test/jdk/java/net/DatagramSocket/SendDatagramToBadAddress.java
changeset 59124 d01fe40e9cd8
parent 54086 ccb4a50bee06
equal deleted inserted replaced
59122:5d73255c2d52 59124:d01fe40e9cd8
   108         SendDatagramToBadAddress ud = new SendDatagramToBadAddress ();
   108         SendDatagramToBadAddress ud = new SendDatagramToBadAddress ();
   109         ud.run ();
   109         ud.run ();
   110     }
   110     }
   111 
   111 
   112     public void run() throws Exception {
   112     public void run() throws Exception {
   113 
       
   114         if (OSsupportsFeature()) {
   113         if (OSsupportsFeature()) {
   115             print ("running on OS that supports ICMP port unreachable");
   114             print ("running on OS that supports ICMP port unreachable");
   116         }
   115         }
       
   116         try (DatagramSocket sock = new DatagramSocket()) {
       
   117             test(sock);
       
   118         }
       
   119     }
       
   120 
       
   121     private void test(DatagramSocket sock) throws Exception {
       
   122         print("Testing with " + sock.getClass());
   117         InetAddress addr = InetAddress.getLoopbackAddress();
   123         InetAddress addr = InetAddress.getLoopbackAddress();
   118         DatagramSocket sock = new DatagramSocket();
       
   119         DatagramSocket serversock = new DatagramSocket(0);
   124         DatagramSocket serversock = new DatagramSocket(0);
   120         DatagramPacket p;
   125         DatagramPacket p;
   121         byte[] buf;
   126         byte[] buf;
   122         int port = serversock.getLocalPort ();
   127         int port = serversock.getLocalPort ();
   123         final int loop = 5;
   128         final int loop = 5;