1*8d67ca89SAndroid Build Coastguard Worker /*
2*8d67ca89SAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project
3*8d67ca89SAndroid Build Coastguard Worker *
4*8d67ca89SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*8d67ca89SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*8d67ca89SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*8d67ca89SAndroid Build Coastguard Worker *
8*8d67ca89SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*8d67ca89SAndroid Build Coastguard Worker *
10*8d67ca89SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*8d67ca89SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*8d67ca89SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*8d67ca89SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*8d67ca89SAndroid Build Coastguard Worker * limitations under the License.
15*8d67ca89SAndroid Build Coastguard Worker */
16*8d67ca89SAndroid Build Coastguard Worker
17*8d67ca89SAndroid Build Coastguard Worker #include <netinet/udp.h>
18*8d67ca89SAndroid Build Coastguard Worker
19*8d67ca89SAndroid Build Coastguard Worker #include <gtest/gtest.h>
20*8d67ca89SAndroid Build Coastguard Worker
21*8d67ca89SAndroid Build Coastguard Worker #if defined(__BIONIC__)
22*8d67ca89SAndroid Build Coastguard Worker #define UDPHDR_USES_ANON_UNION
23*8d67ca89SAndroid Build Coastguard Worker #elif defined(__GLIBC_PREREQ)
24*8d67ca89SAndroid Build Coastguard Worker #if __GLIBC_PREREQ(2, 18)
25*8d67ca89SAndroid Build Coastguard Worker #define UDPHDR_USES_ANON_UNION
26*8d67ca89SAndroid Build Coastguard Worker #endif
27*8d67ca89SAndroid Build Coastguard Worker #endif
28*8d67ca89SAndroid Build Coastguard Worker
TEST(netinet_udp,compat)29*8d67ca89SAndroid Build Coastguard Worker TEST(netinet_udp, compat) {
30*8d67ca89SAndroid Build Coastguard Worker #if defined(UDPHDR_USES_ANON_UNION)
31*8d67ca89SAndroid Build Coastguard Worker static_assert(offsetof(udphdr, uh_sport) == offsetof(udphdr, source), "udphdr::source");
32*8d67ca89SAndroid Build Coastguard Worker static_assert(offsetof(udphdr, uh_dport) == offsetof(udphdr, dest), "udphdr::dest");
33*8d67ca89SAndroid Build Coastguard Worker static_assert(offsetof(udphdr, uh_ulen) == offsetof(udphdr, len), "udphdr::len");
34*8d67ca89SAndroid Build Coastguard Worker static_assert(offsetof(udphdr, uh_sum) == offsetof(udphdr, check), "udphdr::check");
35*8d67ca89SAndroid Build Coastguard Worker
36*8d67ca89SAndroid Build Coastguard Worker udphdr u;
37*8d67ca89SAndroid Build Coastguard Worker u.uh_sport = 0x1111;
38*8d67ca89SAndroid Build Coastguard Worker u.uh_dport = 0x2222;
39*8d67ca89SAndroid Build Coastguard Worker u.uh_ulen = 0x3333;
40*8d67ca89SAndroid Build Coastguard Worker u.uh_sum = 0x4444;
41*8d67ca89SAndroid Build Coastguard Worker ASSERT_EQ(0x1111, u.source);
42*8d67ca89SAndroid Build Coastguard Worker ASSERT_EQ(0x2222, u.dest);
43*8d67ca89SAndroid Build Coastguard Worker ASSERT_EQ(0x3333, u.len);
44*8d67ca89SAndroid Build Coastguard Worker ASSERT_EQ(0x4444, u.check);
45*8d67ca89SAndroid Build Coastguard Worker #endif
46*8d67ca89SAndroid Build Coastguard Worker }
47