-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
66 lines (58 loc) · 1.36 KB
/
main.c
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
#include <stdio.h>
#include "check_ip.h"
int main(int argc, char **argv)
{
int exit_code = 0;
char *valid[] = {
"0.0.0.0",
"127.0.0.1",
"127.127.0.1",
"127.127.127.127",
"1.0.0.1",
};
printf("Valid IPv4 addresses:\n\n");
for (size_t i = 0; i < (sizeof(valid) / sizeof(valid[0])); i++)
{
if (is_valid_ipv4(valid[i]))
{
printf(" -- '%s' is valid\n", valid[i]);
}
else
{
exit_code = 1;
printf(" -- '%s' is invalid (should be valid)\n", valid[i]);
}
}
printf("\nInvalid IPv4 addresses:\n\n");
char *invalid[] = {
NULL,
"",
"abcd",
"1.1",
"1.1.1",
"1.1.1.",
"1.1.1.1.",
"1.1.1.1.1",
"01.0.0.1",
"256.0.0.1",
"a.b.c.d",
"1024.1.1.1",
"-0.0.0.0",
"+0.0.0.0",
"0 .0.0.0",
" 0.0.0.0",
};
for (size_t i = 0; i < (sizeof(invalid) / sizeof(invalid[0])); i++)
{
if (!is_valid_ipv4(invalid[i]))
{
printf(" -- '%s' is invalid\n", invalid[i] ? invalid[i] : "(null)");
}
else
{
exit_code = 1;
printf(" -- '%s' is valid (should be invalid)\n", invalid[i] ? invalid[i] : "(null)");
}
}
return exit_code;
}