X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Tools%2FNetTest_Runner%2Fip.c;h=13de5bc724ae3a27391cded4b4b9203275dda663;hb=13078002b01ee4f63eb2001d2ef479a2a006ea32;hp=628fdbe8e88ab57e1b113a646605b6d449a63b71;hpb=d2f1a4c62225533351551870cbe44d94a4ec4fab;p=tpg%2Facess2.git diff --git a/Tools/NetTest_Runner/ip.c b/Tools/NetTest_Runner/ip.c index 628fdbe8..13de5bc7 100644 --- a/Tools/NetTest_Runner/ip.c +++ b/Tools/NetTest_Runner/ip.c @@ -25,8 +25,10 @@ typedef struct { // === CODE === uint16_t IP_Checksum(uint16_t Prev, size_t Length, const void *Data) { + //test_trace_hexdump("IP Checksum", Data, Length); + const uint16_t *words = Data; - uint32_t ret = ~Prev; + uint32_t ret = 0; for( int i = 0; i < Length/2; i ++ ) { ret += ntohs(*words); @@ -38,6 +40,12 @@ uint16_t IP_Checksum(uint16_t Prev, size_t Length, const void *Data) while( ret >> 16 ) ret = (ret & 0xFFFF) + (ret >> 16); + //test_trace("IP Checksum = %04x + 0x%x", ret, (~Prev) & 0xFFFF); + + ret += (~Prev) & 0xFFFF; + while( ret >> 16 ) + ret = (ret & 0xFFFF) + (ret >> 16); + return ~ret; } @@ -84,7 +92,7 @@ void IP_Send(int IfNum, int AF, const void *Src, const void *Dst, uint8_t proto, } } -bool IP_Pkt_Check(size_t len, const void *data, size_t *ofs_out, int AF, const void *Src, const void *Dst, uint8_t proto) +bool IP_Pkt_Check(size_t len, const void *data, size_t *ofs_out, size_t *len_out, int AF, const void *Src, const void *Dst, uint8_t proto) { size_t ofs; if( AF == 4 ) { @@ -97,14 +105,16 @@ bool IP_Pkt_Check(size_t len, const void *data, size_t *ofs_out, int AF, const v TEST_ASSERT_REL(IP_Checksum(IP_CHECKSUM_START, sizeof(hdr), &hdr), ==, 0); TEST_ASSERT_REL(ntohs(hdr.TotalLength), <=, len - ofs); + TEST_ASSERT_REL(ntohs(hdr.TotalLength), >, (hdr.VerLen & 0xF) * 4); TEST_ASSERT_REL(ntohs(hdr.FragmentInfo), ==, 0); TEST_ASSERT_REL(hdr.TTL, >, 1); // >1 because there's no intervening hops TEST_ASSERT_REL(hdr.Protocol, ==, proto); - TEST_ASSERT( memcmp(hdr.SrcAddr, Src, 4) == 0 ); - TEST_ASSERT( memcmp(hdr.DstAddr, Dst, 4) == 0 ); - + if(Src) TEST_ASSERT( memcmp(hdr.SrcAddr, Src, 4) == 0 ); + if(Dst) TEST_ASSERT( memcmp(hdr.DstAddr, Dst, 4) == 0 ); + + *len_out = ntohs(hdr.TotalLength) - sizeof(hdr); *ofs_out = ofs + (hdr.VerLen & 0xF) * 4; return true; }