summaryrefslogtreecommitdiff
path: root/inet/tst-checks.c
blob: 5d97564cd659098f2ec7ba7a31e831bc37cff9e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>


static int
do_test (void)
{
  int result = 0;
  char buf[16];
  memset (buf, '\0', 16);

  if (! IN6_IS_ADDR_UNSPECIFIED (buf))
    {
      puts ("positive IN6_IS_ADDR_UNSPECIFIED failed");
      result = 1;
    }
  for (size_t i = 0; i < 16; ++i)
    {
      buf[i] = 1;
      if (IN6_IS_ADDR_UNSPECIFIED (buf))
	{
	  printf ("negative IN6_IS_ADDR_UNSPECIFIED with byte %zu failed\n",
		  i);
	  result = 1;
	}
      buf[i] = 0;
    }

  if (IN6_IS_ADDR_LOOPBACK (buf))
    {
      puts ("negative IN6_IS_ADDR_UNSPECIFIED failed");
      result = 1;
    }
  buf[15] = 1;
  if (! IN6_IS_ADDR_LOOPBACK (buf))
    {
      puts ("positive IN6_IS_ADDR_UNSPECIFIED failed");
      result = 1;
    }
  buf[15] = 0;

  buf[0] = 0xfe;
  buf[1] = 0x80;
  if (! IN6_IS_ADDR_LINKLOCAL (buf))
    {
      puts ("positive IN6_IS_ADDR_LINKLOCAL failed");
      result = 1;
    }
  for (size_t i = 1; i < 16; ++i)
    {
      buf[i] ^= 1;
      if (! IN6_IS_ADDR_LINKLOCAL (buf))
	{
	  printf ("positive IN6_IS_ADDR_LINKLOCAL byte %zu failed\n", i);
	  result = 1;
	}
      buf[i] ^= 1;
    }
  buf[0] = 0xff;
  buf[1] = 0x80;
  if (IN6_IS_ADDR_LINKLOCAL (buf))
    {
      puts ("negative IN6_IS_ADDR_LINKLOCAL failed");
      result = 1;
    }
  buf[0] = 0xfe;
  buf[1] = 0xc0;
  if (IN6_IS_ADDR_LINKLOCAL (buf))
    {
      puts ("negative IN6_IS_ADDR_LINKLOCAL #2 failed");
      result = 1;
    }

  buf[0] = 0xfe;
  buf[1] = 0xc0;
  if (! IN6_IS_ADDR_SITELOCAL (buf))
    {
      puts ("positive IN6_IS_ADDR_SITELOCAL failed");
      result = 1;
    }
  for (size_t i = 1; i < 16; ++i)
    {
      buf[i] ^= 1;
      if (! IN6_IS_ADDR_SITELOCAL (buf))
	{
	  printf ("positive IN6_IS_ADDR_SITELOCAL byte %zu failed\n", i);
	  result = 1;
	}
      buf[i] ^= 1;
    }
  buf[0] = 0xff;
  buf[1] = 0x80;
  if (IN6_IS_ADDR_SITELOCAL (buf))
    {
      puts ("negative IN6_IS_ADDR_SITELOCAL failed");
      result = 1;
    }
  buf[0] = 0xf8;
  buf[1] = 0xc0;
  if (IN6_IS_ADDR_SITELOCAL (buf))
    {
      puts ("negative IN6_IS_ADDR_SITELOCAL #2 failed");
      result = 1;
    }

  memset (buf, '\0', 16);
  buf[10] = 0xff;
  buf[11] = 0xff;
  if (! IN6_IS_ADDR_V4MAPPED (buf))
    {
      puts ("positive IN6_IS_ADDR_V4MAPPED failed");
      result = 1;
    }
  for (size_t i = 12; i < 16; ++i)
    {
      buf[i] ^= 1;
      if (! IN6_IS_ADDR_V4MAPPED (buf))
	{
	  printf ("positive IN6_IS_ADDR_V4MAPPED byte %zu failed\n", i);
	  result = 1;
	}
      buf[i] ^= 1;
    }
  for (size_t i = 0; i < 12; ++i)
    {
      buf[i] ^= 1;
      if (IN6_IS_ADDR_V4MAPPED (buf))
	{
	  printf ("negative IN6_IS_ADDR_V4MAPPED byte %zu failed\n", i);
	  result = 1;
	}
      buf[i] ^= 1;
    }

  memset (buf, '\0', 16);
  for (size_t i = 12; i < 16; ++i)
    {
      buf[i] ^= 2;
      if (! IN6_IS_ADDR_V4COMPAT (buf))
	{
	  printf ("positive IN6_IS_ADDR_V4COMPAT byte %zu failed\n", i);
	  result = 1;
	}
      buf[i] ^= 2;
    }
  for (size_t i = 0; i < 12; ++i)
    {
      buf[i] ^= 1;
      if (IN6_IS_ADDR_V4COMPAT (buf))
	{
	  printf ("negative IN6_IS_ADDR_V4COMPAT byte %zu failed\n", i);
	  result = 1;
	}
      buf[i] ^= 1;
    }
  if (IN6_IS_ADDR_V4COMPAT (buf))
    {
      puts ("negative IN6_IS_ADDR_V4COMPAT #2 failed");
      result = 1;
    }
  buf[15] = 1;
  if (IN6_IS_ADDR_V4COMPAT (buf))
    {
      puts ("negative IN6_IS_ADDR_V4COMPAT #3 failed");
      result = 1;
    }

  return result;
}

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"