-
Notifications
You must be signed in to change notification settings - Fork 11
/
check-sizes.c
121 lines (105 loc) · 3.39 KB
/
check-sizes.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
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
/*
* The TCP Scanner (tcp-scan) is Copyright (C) 2003-2008 Roy Hills,
* NTA Monitor Ltd.
*
* This file is part of tcp-scan.
*
* tcp-scan is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* tcp-scan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with tcp-scan. If not, see <http://www.gnu.org/licenses/>.
*
* If this license is unacceptable to you, I may be willing to negotiate
* alternative licenses (contact [email protected]).
*
* You are encouraged to send comments, improvements or suggestions to
* me at [email protected].
*
* check-sizes -- Check sizes of structures and types
*
* Author: Roy Hills
* Date: 30 October 2008
*
* Check that the sizes of the various structs are what we expect them
* to be. If they are not, then we return with a failure status.
*/
#include "tcp-scan.h"
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#define EXPECTED_IP_HDR 20
#define EXPECTED_TCP_HDR 20
#define EXPECTED_PSEUDO_HDR 12
#define EXPECTED_UINT8_T 1
#define EXPECTED_UINT16_T 2
#define EXPECTED_UINT32_T 4
int
main() {
unsigned octets_per_char; /* Almost always 1 */
int error=0;
if (CHAR_BIT % 8)
err_msg("CHAR_BIT is not a multiple of 8");
octets_per_char = CHAR_BIT/8;
printf("Structure\tExpect\tObserved\n\n");
printf("iphdr\t\t%u\t%lu\t", EXPECTED_IP_HDR,
(unsigned long) (octets_per_char * sizeof(struct iphdr)));
if (octets_per_char * sizeof(struct iphdr) != EXPECTED_IP_HDR) {
error++;
printf("ERROR\n");
} else {
printf("ok\n");
}
printf("tcphdr\t\t%u\t%lu\t", EXPECTED_TCP_HDR,
(unsigned long) (octets_per_char * sizeof(struct tcphdr)));
if (octets_per_char * sizeof(struct tcphdr) != EXPECTED_TCP_HDR) {
error++;
printf("ERROR\n");
} else {
printf("ok\n");
}
printf("pseudo_hdr\t%u\t%lu\t", EXPECTED_PSEUDO_HDR,
(unsigned long) (octets_per_char * sizeof(pseudo_hdr)));
if (octets_per_char * sizeof(pseudo_hdr) != EXPECTED_PSEUDO_HDR) {
error++;
printf("ERROR\n");
} else {
printf("ok\n");
}
printf("\nType\t\tExpect\tObserved\n\n");
printf("uint8_t\t\t%u\t%lu\t", EXPECTED_UINT8_T,
(unsigned long) (octets_per_char * sizeof(uint8_t)));
if (octets_per_char * sizeof(uint8_t) != EXPECTED_UINT8_T) {
error++;
printf("ERROR\n");
} else {
printf("ok\n");
}
printf("uint16_t\t%u\t%lu\t", EXPECTED_UINT16_T,
(unsigned long) (octets_per_char * sizeof(uint16_t)));
if (octets_per_char * sizeof(uint16_t) != EXPECTED_UINT16_T) {
error++;
printf("ERROR\n");
} else {
printf("ok\n");
}
printf("uint32_t\t%u\t%lu\t", EXPECTED_UINT32_T,
(unsigned long) (octets_per_char * sizeof(uint32_t)));
if (octets_per_char * sizeof(uint32_t) != EXPECTED_UINT32_T) {
error++;
printf("ERROR\n");
} else {
printf("ok\n");
}
if (error)
return EXIT_FAILURE;
else
return EXIT_SUCCESS;
}