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