Results 1 to 2 of 2
  1. #1
    cjtemple is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default Buffered Reader is missing data

    As part of a program I am writing I am looking to do some MTU discovery, but the results aren't coming through. Any suggestions?

    Java Code:
        private static void __testMTU() {
        	int base = 0;
        	int limit = _length;
        	int attemptNumber = 1;
        	int attempt = 0;
        	boolean isFragmented = false;
     
        	while(base!=limit){
        		if(attemptNumber!=1){
        			attempt = (base+limit)/2;
        		} else {
        			attempt = limit;
        		}
                String stmt = "ping ";
                if(_OS.equalsIgnoreCase("win")){
                    stmt += "-n 1 -f -l "+attempt+" "+_target;
                } else if (_OS.equalsIgnoreCase("mac") || _OS.equalsIgnoreCase("nix")){
                    stmt += "-c 1 -s "+attempt+" -D "+_target;
                } else {
                	_summary += "MTU can not be tested on a Solaris system as the ping utility does not support the Do Not Fragment Flag.";
                	break;
                }
     
                try {
                    Process p=Runtime.getRuntime().exec(stmt);
                    p.waitFor();
                    BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
                    _summary += stmt+"\n";
                    String line=reader.readLine();
                    while(line!=null) {
                    	_summary += line+"\n";
                    	if(line.lastIndexOf("truncated") >= 0 || line.lastIndexOf("fragmented") >= 0 || line.lastIndexOf("too long") >= 0) {
                    		isFragmented = true;
                    	}
                        line=reader.readLine();
                    }
                }
                catch(Exception e) {}
     
                if(attemptNumber==1 && !isFragmented) {
                	break;
                }
     
        		if(attemptNumber==1 && isFragmented) {
        			_summary += "Your packet size exceeds the MTU for this connection and will be adjusted to equal the maximum MTU possible.";
        		}
     
        		if(isFragmented){
        			limit = attempt;
        		} else {
        			base = attempt;
        		}
    			attemptNumber++;
        	}
        	_length = base;
        }
    The script returns:
    ping -c 1 -s 64565 -D Google
    PING Google (74.125.130.103): 64565 data bytes

    --- Google ping statistics ---
    1 packets transmitted, 0 packets received, 100.0% packet loss
    but executing the command from the terminal returns:
    localhost:bin john$ ping -c 1 -s 64565 -D Google
    PING Google (74.125.130.103): 64565 data bytes
    ping: sendto: Message too long

    --- Google ping statistics ---
    1 packets transmitted, 0 packets received, 100.0% packet loss
    I really need that Message too long statement. :)

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,656
    Blog Entries
    7
    Rep Power
    21

    Default Re: Buffered Reader is missing data

    You're waiting for another process to complete and only then are you trying to read its output. Don't wait for its completion (its output buffer might fill up) but start reading its output right away.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Buffered reader
    By franckboy in forum New To Java
    Replies: 1
    Last Post: 02-02-2011, 07:16 PM
  2. Buffered Reader
    By ilovepolluting in forum New To Java
    Replies: 2
    Last Post: 02-04-2010, 09:16 AM
  3. Buffered Reader problem
    By pradeep.theonlyone in forum New To Java
    Replies: 3
    Last Post: 07-31-2009, 11:37 AM
  4. Buffered Reader Exception
    By hitmen in forum New To Java
    Replies: 6
    Last Post: 01-07-2009, 11:14 AM
  5. FileReader / Buffered Reader
    By sepaht in forum New To Java
    Replies: 9
    Last Post: 07-10-2008, 08:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •