Tools/NetTest - TCP stack testing, going well
[tpg/acess2.git] / Tools / NetTest_Runner / link.c
1 /*
2  */
3 #include "common.h"
4 #include "net.h"
5 #include "link.h"
6 #include "test.h"
7 #include <stdlib.h>
8 #include <string.h>
9
10 // === CODE ===
11 void Link_Send(int IfNum, const void *Src, const void *Dst, uint16_t Proto,
12         int BufCount, size_t BufLens[], const void *Bufs[])
13 {
14         size_t  total_len = 6+6+2;
15         for( int i = 0; i < BufCount; i ++ )
16                 total_len += BufLens[i];
17         uint8_t *data = malloc(total_len);
18         
19         uint8_t *pos = data;
20         memcpy(pos, Dst, 6);    pos += 6;
21         memcpy(pos, Src, 6);    pos += 6;
22         *(uint16_t*)pos = htons(Proto); pos += 2;
23         
24         for( int i = 0; i < BufCount; i ++ )
25         {
26                 memcpy(pos, Bufs[i], BufLens[i]);
27                 pos += BufLens[i];
28         }
29         
30         Net_Send(IfNum, total_len, data);
31         
32         free(data);
33 }
34
35 bool Link_Pkt_Check(size_t len, const void *data, size_t *ofs_out,
36         const void *Src, const void *Dst, uint16_t Proto)
37 {
38         const uint8_t   *data8 = data;
39         TEST_ASSERT_REL(len, >=, 6+6+2);
40
41         if(Dst) TEST_ASSERT( memcmp(data8+0, Dst, 6) == 0 );
42         if(Src) TEST_ASSERT( memcmp(data8+6, Src, 6) == 0 );
43         
44         TEST_ASSERT_REL( ntohs(*(uint16_t*)(data8+12)), ==, Proto );
45
46         *ofs_out = 6+6+2;
47         return true;
48 }
49

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