[En-Nut-Discussion] Ping

Gediminas Simanskis gedas at tvk.lt
Fri Oct 1 19:29:59 CEST 2004


simple "Ping" example:

NETBUF    *nb;
HANDLE    ping;
u_char dataa[2] = "A";

while(1){
       nb = NutNetBufAlloc(0, NBAF_APPLICATION, 1);
         if(nb) {
           memcpy(nb->nb_ap.vp,dataa,1);
            if( NutIcmpReply(ICMP_ECHO, 0, 0,WdConfig.aip2, nb) == 0){
                 NutNetBufFree(nb);
             }
         }
         tim = NutEventWait(&ping, 1000L);
         if(!tim)  fprintf(uart,"Ping Ok\r\n")  else   fprintf(uart,"Ping 
Error\r\n);
}

modification  file icmpin.c
//**********************************************
void NutIcmpInput(NUTDEVICE * dev, NETBUF * nb)
{
 u_char *data;

    if (nb->nb_tp.sz > ICMP_MINLEN) {
        ICMPHDR *icp = (ICMPHDR *) nb->nb_tp.vp;
        if (icp->icmp_type == ICMP_ECHO)
         {
           NutIcmpReflect(dev, ICMP_ECHOREPLY, nb);
         }
    if (icp->icmp_type == ICMP_ECHOREPLY)
     {
        nb->nb_ap.vp = nb->nb_tp.vp + sizeof(ICMPHDR);
       data = (u_char*) nb->nb_ap.vp ;
       if(*data)  NutEventPost(&ping);
     }
    }
    NutNetBufFree(nb);
}





More information about the En-Nut-Discussion mailing list