[En-Nut-Discussion] Ping

Ralph Mason ralph.mason at telogis.com
Tue Oct 5 00:09:38 CEST 2004


I have a full and stable ICMP sockets implementation that I have been 
using for about 12 months.

I wonder if it's time that this gets integrated into the main ether nut 
distribution

example ping code

int ping(char* args[],int argc, FILE* f){
   
    u_long addr;
    ICMPSOCKET* sock;
    u_char data[32];
    int i;
   
    if ( argc < 2 ){
        fputs_P(PSTR("usage: ping host [timeout]\r\n"),f);
        return -1;
    }
   
    if( (addr = resolve_address_name(args[1],f)) == 0 ){
        cr(f);
        return 0;
    }
   
    sock = NutIcmpCreateSocket(IPPROTO_ICMP,1);
   
    fprintf_P(f,PSTR("Pinging %s [%a] with 32 bytes\r\n\r\n"),args[1],addr);
    fflush(f);
   
    for( i = 0 ; i < 4 ; i++){
        u_long reply_addr;
        u_char type;
        u_char code;
        u_long ticks;
       
        NutIcmpSendTo(sock,addr,ICMP_ECHO,0,data,32);
        ticks = NutGetTickCount();
       
        if ( 
NutIcmpReceiveFrom(sock,&reply_addr,&type,&code,data,32,3000) != 0){
               
            switch( type){
                case ICMP_ECHOREPLY:
                    fprintf_P(f,PSTR("Reply from %a %i 
ms\r\n"),reply_addr,(int)(((NutGetTickCount()-ticks)*1000)/ 40L));
                    break;

                default:
                    fprintf_P(f,PSTR("Reply from %a type %i code 
%i\r\n"),reply_addr,type,code);
                }
            }
            else{
                fputs_P(PSTR("Request timed out.\r\n"),f);
            }
           
            fflush(f);
    }
   
    NutIcmpDestroySocket(sock);
   
    return 0;
}


Ralph

>Hi
>
>Does that mean I have to modify the NutIcmpInput function? Is there no
>possibility to do such thing without modifying NutOS?
>
>bye
>Thorsten
>
>  
>
>>modification  file icmpin.c
>>//**********************************************
>>void NutIcmpInput(NUTDEVICE * dev, NETBUF * nb)
>>{
>>    
>>
>
>_______________________________________________
>En-Nut-Discussion mailing list
>En-Nut-Discussion at egnite.de
>http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
>
>
>  
>




More information about the En-Nut-Discussion mailing list