Fixing error reporting
[tpg/acess2.git] / Modules / IPStack / icmp.c
index 90ef7cb..9f67175 100644 (file)
@@ -52,13 +52,27 @@ void ICMP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buff
                        Warning("[ICMP ] Code == %i for ICMP Echo Reply, should be 0", hdr->Code);
                        return ;
                }
-               if(hdr->ID != ~hdr->Sequence) {
+               if(hdr->ID != (Uint16)~hdr->Sequence) {
                        Warning("[ICMP ] ID and Sequence values do not match");
-                       return ;
+                       //return ;
                }
                gICMP_PingSlots[hdr->ID].bArrived = 1;
                break;
        
+       // -- 3: Destination Unreachable
+       case ICMP_UNREACHABLE:
+               switch(hdr->Code)
+               {
+               case 3: // Port Unreachable
+                       Log("[ICMP ] Destination Unreachable (Port Unreachable)");
+                       break;
+               default:
+                       Log("[ICMP ] Destination Unreachable (Code %i)", hdr->Code);
+                       break;
+               }
+//             IPv4_Unreachable( Interface, hdr->Code, htons(hdr->Length)-sizeof(tICMPHeader), hdr->Data );
+               break;
+       
        // -- 8: Echo Request
        case ICMP_ECHOREQ:
                if(hdr->Code != 0) {
@@ -72,6 +86,8 @@ void ICMP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buff
                Log("[ICMP ] Checksum = 0x%04x", hdr->Checksum);
                IPv4_SendPacket(Interface, *(tIPv4*)Address, 1, ntohs(hdr->Sequence), Length, hdr);
                break;
+       default:
+               break;
        }
        
 }
@@ -82,7 +98,8 @@ void ICMP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buff
  */
 int ICMP_Ping(tInterface *Interface, tIPv4 Addr)
 {
-       //Sint64        ts;
+       Sint64  ts;
+       Sint64  end;
        char    buf[32] = "\x8\0\0\0\0\0\0\0Acess2 I"
                       "P/TCP Stack 1.0\0";
        tICMPHeader     *hdr = (void*)buf;
@@ -94,7 +111,7 @@ int ICMP_Ping(tInterface *Interface, tIPv4 Addr)
                {
                        if(gICMP_PingSlots[i].Interface == NULL)        break;
                }
-               if(gICMP_PingSlots[i].Interface == NULL)        break;
+               if( i < PING_SLOTS )    break;
                Threads_Yield();
        }
        gICMP_PingSlots[i].Interface = Interface;
@@ -104,5 +121,12 @@ int ICMP_Ping(tInterface *Interface, tIPv4 Addr)
        hdr->Checksum = htons( IPv4_Checksum(hdr, sizeof(buf)) );
        IPv4_SendPacket(Interface, Addr, 1, i, sizeof(buf), buf);
        
-       return -1;
+       ts = now();
+       end = ts + Interface->TimeoutDelay;
+       while( !gICMP_PingSlots[i].bArrived && now() < end)     Threads_Yield();
+       
+       if(now() > end)
+               return -1;
+       
+       return (int)ts;
 }

UCC git Repository :: git.ucc.asn.au