1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Ping Buffer Size

Discussion in 'Programming' started by nvidura, Mar 31, 2007.

  1. #1
    Is it possible to ping a specified host with 65001 or more buffer size? I tried this in windows. But it display this message...
    Bad value for option -l, valid range is from 0 to 65500
    Code (markup):
    Why?

    thanks in advice...
     
    nvidura, Mar 31, 2007 IP
  2. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    According to RFC 2925 (which, among other things, defines ping) the answer is no (well, actual limit is a couple of bytes more, as you'll see below).

    From the spec (emphasis below is mine):
    You can find the rfc here: http://www.rfc-archive.org/getrfc.php?rfc=2925

    The quote is a fifth of the way down the page.
     
    sea otter, Mar 31, 2007 IP
  3. Thibaut

    Thibaut Well-Known Member

    Messages:
    886
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Thibaut, Apr 1, 2007 IP
  4. serjio28

    serjio28 Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here is what I got under Linux
     
    serjio28, Apr 2, 2007 IP
  5. nvidura

    nvidura Well-Known Member

    Messages:
    1,780
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    150
    #5
    Well, hmmmm, I'm not trying to play with ping of death. I just want to learn... but i need to know why my program stops responding if i change buffer size to a value higher than this limit...

    Native library removed for security reasons...



    public final class PingKnVX {
        private int socket;
        
        public PingKnVX() {
            socket = 0;
        }
        
        public final boolean begin(){
            if (socket != 0)
                return false;
            boolean flag = close(socket);
            socket = 0;
            return flag;
            
        }
        
        public final boolean end(){
            if (socket == 0)
                return false;
            boolean flag = close(socket);
            socket = 0;
            return flag;
        }
        
        public final boolean ping(String s, int i, int j){
            
            if (s == null || s.length() < 7 || s.length() > 15)
                return false;
            
           [COLOR="Red"] if (i < 0 || i > 65535) [/COLOR]
                return false;
            
           [COLOR="Red"] if (j < 0 || j > 65535)[/COLOR]
                return false;
            
            short word0;
            
            synchronized (this){
                word0 = sendPing(socket, s, i, j);
            }
            
            switch (word0){
                case 0: return true;
            }
            return false;
        }
        
        public final boolean pong(String as[]){
            byte abyte0[] = new byte[16];
            int ai[] = new int[3];
            int i = 0;
            if (as == null || as.length < 4)
                return false;
            
            do {
                short word0;
                synchronized (this){
                    word0 = recvPing(socket,(short)0, abyte0, ai);
                }
                switch (word0){
                    case -10:
                    case -5:
                    case -4:
                    case -2:
                        i = 5;
                        try {
                            Thread.sleep(i);
                        }catch (Exception ex){
                            // do nothing
                        }
                        break;
                        
                    case 0:
                        int j;
                        for (j = 0; j < abyte0.length; j++){
                            if (abyte0[j]==0)
                                break;
                            
                            as[0] = new String(abyte0, 0, j);
                            as[1] = new String(Integer.toString(ai[0]));
                            as[2] = new String(Integer.toString(ai[1]));
                            
                            int k = ai[2] -i;
                            if (i != 0 && k < 0)
                                k = i - k;
                            as[3] = new String(Integer.toString(k));
                            return true;    
                        }
                        
                    default:
                        return false;
                }
            }while(true);
        }
        private native int open();
        private native boolean close(int i);
        private native short sendPing(int i, String s, int j, int k);
        private native short recvPing(int i, short word0, byte abyte0[], int ai[]);
        
        static {
            try {
                System.loadLibrary("MYLIB");
            }catch(SecurityException e) {
                System.out.println("Error in loading dll");
                throw e; 
            }catch (UnsatisfiedLinkError x){
                System.out.println("Native library not found");
                throw x;
            }
        }
    }
    
    public class Main {
        
        
                  public static void main(String args[]) throws Exception
                        {
                        PingKnVX ping = new PingKnVX();
                        String[] dataRcv=new String[4];   
    
                        ping.begin();
    
    
                        if ( ping.ping("127.0.0.1", 5, 1) );   if no problem, it'll return "true".
                             {
                             ping.pong (dataRcv); is
                                          
                             System.out.println ("Host: "+dataRcv[0]+" ping time1: "+dataRcv[3]);
                             }
    
                       
    
                       
    
                        ping.end(); 
                        }
                  } 
    
    
    Code (markup):
     
    nvidura, Apr 2, 2007 IP
  6. Thibaut

    Thibaut Well-Known Member

    Messages:
    886
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    #6
    Hello,

    If you use an ICMP API to handle your ping, it is possible the API won't accept you to use a large buffer. In that case, I would recommand you to use Raw packets APIs.

    Regards
    Thibaut
     
    Thibaut, Apr 2, 2007 IP