@dittolive/ditto 4.4.5 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DittoReactNative.podspec +27 -0
- package/README.md +68 -51
- package/node/ditto.cjs.js +1639 -851
- package/node/ditto.darwin-arm64.node +0 -0
- package/node/ditto.darwin-x64.node +0 -0
- package/node/ditto.linux-arm.node +0 -0
- package/node/ditto.linux-x64.node +0 -0
- package/node/ditto.win32-x64.node +0 -0
- package/node/transports.darwin-arm64.node +0 -0
- package/node/transports.darwin-x64.node +0 -0
- package/package.json +34 -38
- package/react-native/android/CMakeLists.txt +37 -0
- package/react-native/android/build.gradle +203 -0
- package/react-native/android/cpp-adapter.cpp +254 -0
- package/react-native/android/gradle.properties +5 -0
- package/react-native/android/src/main/AndroidManifest.xml +4 -0
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.java +85 -0
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKPackage.java +28 -0
- package/react-native/boost/boost/assert.hpp +85 -0
- package/react-native/boost/boost/config/abi/borland_prefix.hpp +27 -0
- package/react-native/boost/boost/config/abi/borland_suffix.hpp +12 -0
- package/react-native/boost/boost/config/abi/msvc_prefix.hpp +22 -0
- package/react-native/boost/boost/config/abi/msvc_suffix.hpp +8 -0
- package/react-native/boost/boost/config/abi_prefix.hpp +25 -0
- package/react-native/boost/boost/config/abi_suffix.hpp +25 -0
- package/react-native/boost/boost/config/assert_cxx03.hpp +211 -0
- package/react-native/boost/boost/config/assert_cxx11.hpp +209 -0
- package/react-native/boost/boost/config/assert_cxx14.hpp +47 -0
- package/react-native/boost/boost/config/assert_cxx17.hpp +62 -0
- package/react-native/boost/boost/config/assert_cxx20.hpp +59 -0
- package/react-native/boost/boost/config/assert_cxx98.hpp +23 -0
- package/react-native/boost/boost/config/auto_link.hpp +525 -0
- package/react-native/boost/boost/config/compiler/borland.hpp +339 -0
- package/react-native/boost/boost/config/compiler/clang.hpp +366 -0
- package/react-native/boost/boost/config/compiler/clang_version.hpp +83 -0
- package/react-native/boost/boost/config/compiler/codegear.hpp +385 -0
- package/react-native/boost/boost/config/compiler/comeau.hpp +59 -0
- package/react-native/boost/boost/config/compiler/common_edg.hpp +183 -0
- package/react-native/boost/boost/config/compiler/compaq_cxx.hpp +19 -0
- package/react-native/boost/boost/config/compiler/cray.hpp +446 -0
- package/react-native/boost/boost/config/compiler/diab.hpp +26 -0
- package/react-native/boost/boost/config/compiler/digitalmars.hpp +143 -0
- package/react-native/boost/boost/config/compiler/gcc.hpp +383 -0
- package/react-native/boost/boost/config/compiler/gcc_xml.hpp +114 -0
- package/react-native/boost/boost/config/compiler/greenhills.hpp +28 -0
- package/react-native/boost/boost/config/compiler/hp_acc.hpp +149 -0
- package/react-native/boost/boost/config/compiler/intel.hpp +577 -0
- package/react-native/boost/boost/config/compiler/kai.hpp +33 -0
- package/react-native/boost/boost/config/compiler/metrowerks.hpp +198 -0
- package/react-native/boost/boost/config/compiler/mpw.hpp +140 -0
- package/react-native/boost/boost/config/compiler/nvcc.hpp +61 -0
- package/react-native/boost/boost/config/compiler/pathscale.hpp +138 -0
- package/react-native/boost/boost/config/compiler/pgi.hpp +23 -0
- package/react-native/boost/boost/config/compiler/sgi_mipspro.hpp +29 -0
- package/react-native/boost/boost/config/compiler/sunpro_cc.hpp +222 -0
- package/react-native/boost/boost/config/compiler/vacpp.hpp +186 -0
- package/react-native/boost/boost/config/compiler/visualc.hpp +391 -0
- package/react-native/boost/boost/config/compiler/xlcpp.hpp +299 -0
- package/react-native/boost/boost/config/compiler/xlcpp_zos.hpp +173 -0
- package/react-native/boost/boost/config/detail/cxx_composite.hpp +203 -0
- package/react-native/boost/boost/config/detail/posix_features.hpp +95 -0
- package/react-native/boost/boost/config/detail/select_compiler_config.hpp +157 -0
- package/react-native/boost/boost/config/detail/select_platform_config.hpp +147 -0
- package/react-native/boost/boost/config/detail/select_stdlib_config.hpp +121 -0
- package/react-native/boost/boost/config/detail/suffix.hpp +1294 -0
- package/react-native/boost/boost/config/header_deprecated.hpp +26 -0
- package/react-native/boost/boost/config/helper_macros.hpp +37 -0
- package/react-native/boost/boost/config/no_tr1/cmath.hpp +28 -0
- package/react-native/boost/boost/config/no_tr1/complex.hpp +28 -0
- package/react-native/boost/boost/config/no_tr1/functional.hpp +28 -0
- package/react-native/boost/boost/config/no_tr1/memory.hpp +28 -0
- package/react-native/boost/boost/config/no_tr1/utility.hpp +28 -0
- package/react-native/boost/boost/config/platform/aix.hpp +33 -0
- package/react-native/boost/boost/config/platform/amigaos.hpp +15 -0
- package/react-native/boost/boost/config/platform/beos.hpp +26 -0
- package/react-native/boost/boost/config/platform/bsd.hpp +83 -0
- package/react-native/boost/boost/config/platform/cloudabi.hpp +18 -0
- package/react-native/boost/boost/config/platform/cray.hpp +18 -0
- package/react-native/boost/boost/config/platform/cygwin.hpp +71 -0
- package/react-native/boost/boost/config/platform/haiku.hpp +31 -0
- package/react-native/boost/boost/config/platform/hpux.hpp +87 -0
- package/react-native/boost/boost/config/platform/irix.hpp +31 -0
- package/react-native/boost/boost/config/platform/linux.hpp +106 -0
- package/react-native/boost/boost/config/platform/macos.hpp +87 -0
- package/react-native/boost/boost/config/platform/qnxnto.hpp +31 -0
- package/react-native/boost/boost/config/platform/solaris.hpp +31 -0
- package/react-native/boost/boost/config/platform/symbian.hpp +97 -0
- package/react-native/boost/boost/config/platform/vms.hpp +25 -0
- package/react-native/boost/boost/config/platform/vxworks.hpp +422 -0
- package/react-native/boost/boost/config/platform/wasm.hpp +23 -0
- package/react-native/boost/boost/config/platform/win32.hpp +90 -0
- package/react-native/boost/boost/config/platform/zos.hpp +32 -0
- package/react-native/boost/boost/config/pragma_message.hpp +31 -0
- package/react-native/boost/boost/config/requires_threads.hpp +92 -0
- package/react-native/boost/boost/config/stdlib/dinkumware.hpp +324 -0
- package/react-native/boost/boost/config/stdlib/libcomo.hpp +93 -0
- package/react-native/boost/boost/config/stdlib/libcpp.hpp +180 -0
- package/react-native/boost/boost/config/stdlib/libstdcpp3.hpp +482 -0
- package/react-native/boost/boost/config/stdlib/modena.hpp +79 -0
- package/react-native/boost/boost/config/stdlib/msl.hpp +98 -0
- package/react-native/boost/boost/config/stdlib/roguewave.hpp +208 -0
- package/react-native/boost/boost/config/stdlib/sgi.hpp +168 -0
- package/react-native/boost/boost/config/stdlib/stlport.hpp +258 -0
- package/react-native/boost/boost/config/stdlib/vacpp.hpp +74 -0
- package/react-native/boost/boost/config/stdlib/xlcpp_zos.hpp +61 -0
- package/react-native/boost/boost/config/user.hpp +133 -0
- package/react-native/boost/boost/config/warning_disable.hpp +47 -0
- package/react-native/boost/boost/config/workaround.hpp +305 -0
- package/react-native/boost/boost/config.hpp +67 -0
- package/react-native/boost/boost/cstdint.hpp +556 -0
- package/react-native/boost/boost/intrusive_ptr.hpp +18 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count.hpp +103 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_gcc.hpp +79 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_gcc_atomic.hpp +63 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_gcc_x86.hpp +88 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_nt.hpp +66 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_pt.hpp +104 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_spin.hpp +69 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_std_atomic.hpp +67 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_sync.hpp +72 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_win32.hpp +70 -0
- package/react-native/boost/boost/smart_ptr/detail/local_counted_base.hpp +148 -0
- package/react-native/boost/boost/smart_ptr/detail/local_sp_deleter.hpp +91 -0
- package/react-native/boost/boost/smart_ptr/detail/operator_bool.hpp +64 -0
- package/react-native/boost/boost/smart_ptr/detail/requires_cxx11.hpp +23 -0
- package/react-native/boost/boost/smart_ptr/detail/shared_count.hpp +707 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_convertible.hpp +92 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base.hpp +92 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_acc_ia64.hpp +163 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_aix.hpp +152 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_cw_ppc.hpp +185 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp +148 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_ia64.hpp +170 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_mips.hpp +200 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_ppc.hpp +194 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_sparc.hpp +179 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp +186 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_nt.hpp +119 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_pt.hpp +147 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_snc_ps3.hpp +174 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_spin.hpp +141 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_std_atomic.hpp +147 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_sync.hpp +165 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_vacpp_ppc.hpp +163 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_w32.hpp +140 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_impl.hpp +309 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_disable_deprecated.hpp +40 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_forward.hpp +52 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_has_gcc_intrinsics.hpp +27 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_has_sync_intrinsics.hpp +69 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_interlocked.hpp +173 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_noexcept.hpp +48 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_nullptr_t.hpp +45 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_obsolete.hpp +32 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_thread_pause.hpp +51 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_thread_sleep.hpp +104 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_thread_yield.hpp +100 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_typeinfo_.hpp +58 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_win32_sleep.hpp +49 -0
- package/react-native/boost/boost/smart_ptr/intrusive_ptr.hpp +409 -0
- package/react-native/boost/boost/smart_ptr/intrusive_ref_counter.hpp +188 -0
- package/react-native/cpp/include/Attachment.h +16 -0
- package/react-native/cpp/include/Authentication.h +23 -0
- package/react-native/cpp/include/Collection.h +13 -0
- package/react-native/cpp/include/DQL.h +21 -0
- package/react-native/cpp/include/Document.h +17 -0
- package/react-native/cpp/include/Identity.h +17 -0
- package/react-native/cpp/include/Lifecycle.h +16 -0
- package/react-native/cpp/include/LiveQuery.h +17 -0
- package/react-native/cpp/include/Logger.h +22 -0
- package/react-native/cpp/include/Misc.h +26 -0
- package/react-native/cpp/include/Presence.h +14 -0
- package/react-native/cpp/include/RetainableState.h +24 -0
- package/react-native/cpp/include/SmallPeerInfo.h +17 -0
- package/react-native/cpp/include/Transports.h +25 -0
- package/react-native/cpp/include/TypedArray.hpp +167 -0
- package/react-native/cpp/include/Utils.h +61 -0
- package/react-native/cpp/include/main.h +10 -0
- package/react-native/cpp/src/Attachment.cpp +86 -0
- package/react-native/cpp/src/Authentication.cpp +224 -0
- package/react-native/cpp/src/Collection.cpp +54 -0
- package/react-native/cpp/src/DQL.cpp +254 -0
- package/react-native/cpp/src/Document.cpp +146 -0
- package/react-native/cpp/src/Identity.cpp +123 -0
- package/react-native/cpp/src/Lifecycle.cpp +75 -0
- package/react-native/cpp/src/LiveQuery.cpp +64 -0
- package/react-native/cpp/src/Logger.cpp +200 -0
- package/react-native/cpp/src/Misc.cpp +271 -0
- package/react-native/cpp/src/Presence.cpp +77 -0
- package/react-native/cpp/src/RetainableState.cpp +15 -0
- package/react-native/cpp/src/SmallPeerInfo.cpp +108 -0
- package/react-native/cpp/src/Transports.cpp +270 -0
- package/react-native/cpp/src/TypedArray.cpp +303 -0
- package/react-native/cpp/src/Utils.cpp +138 -0
- package/react-native/cpp/src/main.cpp +149 -0
- package/react-native/dittoffi/dittoffi.h +4698 -0
- package/react-native/dittoffi/ifaddrs.cpp +385 -0
- package/react-native/dittoffi/ifaddrs.h +206 -0
- package/react-native/ios/DittoRNSDK.h +7 -0
- package/react-native/ios/DittoRNSDK.mm +107 -0
- package/react-native/ios/YeetJSIUtils.h +60 -0
- package/react-native/ios/YeetJSIUtils.mm +196 -0
- package/react-native/lib/commonjs/ditto.rn.js +93 -0
- package/react-native/lib/commonjs/ditto.rn.js.map +1 -0
- package/react-native/lib/commonjs/index.js +14 -0
- package/react-native/lib/commonjs/index.js.map +1 -0
- package/react-native/lib/module/ditto.rn.js +83 -0
- package/react-native/lib/module/ditto.rn.js.map +1 -0
- package/react-native/lib/module/index.js +13 -0
- package/react-native/lib/module/index.js.map +1 -0
- package/react-native/lib/typescript/ditto.rn.d.ts +15 -0
- package/react-native/lib/typescript/ditto.rn.d.ts.map +1 -0
- package/react-native/lib/typescript/index.d.ts +1 -0
- package/react-native/lib/typescript/index.d.ts.map +1 -0
- package/react-native/scripts/ruby/include_local_boost.rb +78 -0
- package/react-native/src/ditto.rn.ts +91 -0
- package/react-native/src/environment/environment.fallback.ts +4 -0
- package/react-native/src/index.ts +26 -0
- package/react-native/src/sources/@cbor-redux.ts +2 -0
- package/react-native/src/sources/@ditto.core.ts +1 -0
- package/react-native/src/sources/@environment.ts +2 -0
- package/react-native/src/sources/attachment-fetch-event.ts +54 -0
- package/react-native/src/sources/attachment-fetcher-manager.ts +129 -0
- package/react-native/src/sources/attachment-fetcher.ts +124 -0
- package/react-native/src/sources/attachment-token.ts +48 -0
- package/react-native/src/sources/attachment.ts +59 -0
- package/react-native/src/sources/augment.ts +89 -0
- package/react-native/src/sources/authenticator.ts +314 -0
- package/react-native/src/sources/base-pending-cursor-operation.ts +237 -0
- package/react-native/src/sources/base-pending-id-specific-operation.ts +109 -0
- package/react-native/src/sources/bridge.ts +549 -0
- package/react-native/src/sources/build-time-constants.ts +4 -0
- package/react-native/src/sources/cbor.ts +35 -0
- package/react-native/src/sources/collection-interface.ts +67 -0
- package/react-native/src/sources/collection.ts +212 -0
- package/react-native/src/sources/collections-event.ts +99 -0
- package/react-native/src/sources/counter.ts +77 -0
- package/react-native/src/sources/ditto.ts +945 -0
- package/react-native/src/sources/document-id.ts +159 -0
- package/react-native/src/sources/document-path.ts +303 -0
- package/react-native/src/sources/document.ts +192 -0
- package/react-native/src/sources/epilogue.ts +24 -0
- package/react-native/src/sources/error-codes.ts +52 -0
- package/react-native/src/sources/error.ts +203 -0
- package/react-native/src/sources/essentials.ts +53 -0
- package/react-native/src/sources/ffi-error.ts +117 -0
- package/react-native/src/sources/ffi.ts +1972 -0
- package/react-native/src/sources/identity.ts +163 -0
- package/react-native/src/sources/init.ts +70 -0
- package/react-native/src/sources/internal.ts +113 -0
- package/react-native/src/sources/keep-alive.ts +69 -0
- package/react-native/src/sources/key-path.ts +195 -0
- package/react-native/src/sources/live-query-event.ts +208 -0
- package/react-native/src/sources/live-query-manager.ts +101 -0
- package/react-native/src/sources/live-query.ts +164 -0
- package/react-native/src/sources/logger.ts +196 -0
- package/react-native/src/sources/observer-manager.ts +175 -0
- package/react-native/src/sources/observer.ts +77 -0
- package/react-native/src/sources/pending-collections-operation.ts +232 -0
- package/react-native/src/sources/pending-cursor-operation.ts +218 -0
- package/react-native/src/sources/pending-id-specific-operation.ts +216 -0
- package/react-native/src/sources/presence-manager.ts +160 -0
- package/react-native/src/sources/presence.ts +238 -0
- package/react-native/src/sources/query-result-item.ts +116 -0
- package/react-native/src/sources/query-result.ts +55 -0
- package/react-native/src/sources/register.ts +92 -0
- package/react-native/src/sources/small-peer-info.ts +176 -0
- package/react-native/src/sources/static-tcp-client.ts +6 -0
- package/react-native/src/sources/store-observer.ts +176 -0
- package/react-native/src/sources/store.ts +365 -0
- package/react-native/src/sources/subscription-manager.ts +98 -0
- package/react-native/src/sources/subscription.ts +88 -0
- package/react-native/src/sources/sync-subscription.ts +90 -0
- package/react-native/src/sources/sync.ts +495 -0
- package/react-native/src/sources/test-helpers.ts +24 -0
- package/react-native/src/sources/transport-conditions-manager.ts +104 -0
- package/react-native/src/sources/transport-config.ts +428 -0
- package/react-native/src/sources/update-result.ts +66 -0
- package/react-native/src/sources/update-results-map.ts +57 -0
- package/react-native/src/sources/websocket-client.ts +6 -0
- package/react-native/src/sources/write-transaction-collection.ts +122 -0
- package/react-native/src/sources/write-transaction-pending-cursor-operation.ts +101 -0
- package/react-native/src/sources/write-transaction-pending-id-specific-operation.ts +72 -0
- package/react-native/src/sources/write-transaction.ts +119 -0
- package/react-native.config.js +9 -0
- package/types/ditto.d.ts +1230 -798
- package/web/ditto.es6.js +1 -1
- package/web/ditto.umd.js +1 -1
- package/web/ditto.wasm +0 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
// DITTO VENDORING - bionic/ifaddrs.cpp, modified
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (C) 2015 The Android Open Source Project
|
|
5
|
+
* All rights reserved.
|
|
6
|
+
*
|
|
7
|
+
* Redistribution and use in source and binary forms, with or without
|
|
8
|
+
* modification, are permitted provided that the following conditions
|
|
9
|
+
* are met:
|
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
|
12
|
+
* * Redistributions in binary form must reproduce the above copyright
|
|
13
|
+
* notice, this list of conditions and the following disclaimer in
|
|
14
|
+
* the documentation and/or other materials provided with the
|
|
15
|
+
* distribution.
|
|
16
|
+
*
|
|
17
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
18
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
19
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
20
|
+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
21
|
+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
22
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
23
|
+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
24
|
+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
25
|
+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
26
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
27
|
+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
28
|
+
* SUCH DAMAGE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
#include "ifaddrs.h"
|
|
32
|
+
|
|
33
|
+
#include <errno.h>
|
|
34
|
+
#include <linux/if_packet.h>
|
|
35
|
+
#include <net/if.h>
|
|
36
|
+
#include <netinet/in.h>
|
|
37
|
+
#include <stdint.h>
|
|
38
|
+
#include <stdio.h>
|
|
39
|
+
#include <stdlib.h>
|
|
40
|
+
#include <string.h>
|
|
41
|
+
#include <unistd.h>
|
|
42
|
+
|
|
43
|
+
// The public ifaddrs struct is full of pointers. Rather than track several
|
|
44
|
+
// different allocations, we use a maximally-sized structure with the public
|
|
45
|
+
// part at offset 0, and pointers into its hidden tail.
|
|
46
|
+
struct ifaddrs_storage {
|
|
47
|
+
// Must come first, so that `ifaddrs_storage` is-a `ifaddrs`.
|
|
48
|
+
ifaddrs ifa;
|
|
49
|
+
|
|
50
|
+
// The interface index, so we can match RTM_NEWADDR messages with
|
|
51
|
+
// earlier RTM_NEWLINK messages (to copy the interface flags).
|
|
52
|
+
int interface_index;
|
|
53
|
+
|
|
54
|
+
// Storage for the pointers in `ifa`.
|
|
55
|
+
sockaddr_storage addr;
|
|
56
|
+
sockaddr_storage netmask;
|
|
57
|
+
sockaddr_storage ifa_ifu;
|
|
58
|
+
char name[IFNAMSIZ + 1];
|
|
59
|
+
|
|
60
|
+
explicit ifaddrs_storage(ifaddrs** list) {
|
|
61
|
+
memset(this, 0, sizeof(*this));
|
|
62
|
+
|
|
63
|
+
// push_front onto `list`.
|
|
64
|
+
ifa.ifa_next = *list;
|
|
65
|
+
*list = reinterpret_cast<ifaddrs*>(this);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void SetAddress(int family, const void* data, size_t byteCount) {
|
|
69
|
+
// The kernel currently uses the order IFA_ADDRESS, IFA_LOCAL, IFA_BROADCAST
|
|
70
|
+
// in inet_fill_ifaddr, but let's not assume that will always be true...
|
|
71
|
+
if (ifa.ifa_addr == nullptr) {
|
|
72
|
+
// This is an IFA_ADDRESS and haven't seen an IFA_LOCAL yet, so assume this is the
|
|
73
|
+
// local address. SetLocalAddress will fix things if we later see an IFA_LOCAL.
|
|
74
|
+
ifa.ifa_addr = CopyAddress(family, data, byteCount, &addr);
|
|
75
|
+
} else {
|
|
76
|
+
// We already saw an IFA_LOCAL, which implies this is a destination address.
|
|
77
|
+
ifa.ifa_dstaddr = CopyAddress(family, data, byteCount, &ifa_ifu);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
void SetBroadcastAddress(int family, const void* data, size_t byteCount) {
|
|
82
|
+
// ifa_broadaddr and ifa_dstaddr overlap in a union. Unfortunately, it's possible
|
|
83
|
+
// to have an interface with both. Keeping the last thing the kernel gives us seems
|
|
84
|
+
// to be glibc 2.19's behavior too, so our choice is being source compatible with
|
|
85
|
+
// badly-written code that assumes ifa_broadaddr and ifa_dstaddr are interchangeable
|
|
86
|
+
// or supporting interfaces with both addresses configured. My assumption is that
|
|
87
|
+
// bad code is more common than weird network interfaces...
|
|
88
|
+
ifa.ifa_broadaddr = CopyAddress(family, data, byteCount, &ifa_ifu);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
void SetLocalAddress(int family, const void* data, size_t byteCount) {
|
|
92
|
+
// The kernel source says "for point-to-point IFA_ADDRESS is DESTINATION address,
|
|
93
|
+
// local address is supplied in IFA_LOCAL attribute".
|
|
94
|
+
// -- http://lxr.free-electrons.com/source/include/uapi/linux/if_addr.h#L17
|
|
95
|
+
|
|
96
|
+
// So copy any existing IFA_ADDRESS into ifa_dstaddr...
|
|
97
|
+
if (ifa.ifa_addr != nullptr) {
|
|
98
|
+
ifa.ifa_dstaddr = reinterpret_cast<sockaddr*>(memcpy(&ifa_ifu, &addr, sizeof(addr)));
|
|
99
|
+
}
|
|
100
|
+
// ...and then put this IFA_LOCAL into ifa_addr.
|
|
101
|
+
ifa.ifa_addr = CopyAddress(family, data, byteCount, &addr);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Netlink gives us the prefix length as a bit count. We need to turn
|
|
105
|
+
// that into a BSD-compatible netmask represented by a sockaddr*.
|
|
106
|
+
void SetNetmask(int family, size_t prefix_length) {
|
|
107
|
+
// ...and work out the netmask from the prefix length.
|
|
108
|
+
netmask.ss_family = family;
|
|
109
|
+
uint8_t* dst = SockaddrBytes(family, &netmask);
|
|
110
|
+
memset(dst, 0xff, prefix_length / 8);
|
|
111
|
+
if ((prefix_length % 8) != 0) {
|
|
112
|
+
dst[prefix_length/8] = (0xff << (8 - (prefix_length % 8)));
|
|
113
|
+
}
|
|
114
|
+
ifa.ifa_netmask = reinterpret_cast<sockaddr*>(&netmask);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
void SetPacketAttributes(int ifindex, unsigned short hatype, unsigned char halen) {
|
|
118
|
+
sockaddr_ll* sll = reinterpret_cast<sockaddr_ll*>(&addr);
|
|
119
|
+
sll->sll_ifindex = ifindex;
|
|
120
|
+
sll->sll_hatype = hatype;
|
|
121
|
+
sll->sll_halen = halen;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private:
|
|
125
|
+
sockaddr* CopyAddress(int family, const void* data, size_t byteCount, sockaddr_storage* ss) {
|
|
126
|
+
// Netlink gives us the address family in the header, and the
|
|
127
|
+
// sockaddr_in or sockaddr_in6 bytes as the payload. We need to
|
|
128
|
+
// stitch the two bits together into the sockaddr that's part of
|
|
129
|
+
// our portable interface.
|
|
130
|
+
ss->ss_family = family;
|
|
131
|
+
memcpy(SockaddrBytes(family, ss), data, byteCount);
|
|
132
|
+
|
|
133
|
+
// For IPv6 we might also have to set the scope id.
|
|
134
|
+
if (family == AF_INET6 && (IN6_IS_ADDR_LINKLOCAL(data) || IN6_IS_ADDR_MC_LINKLOCAL(data))) {
|
|
135
|
+
reinterpret_cast<sockaddr_in6*>(ss)->sin6_scope_id = interface_index;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return reinterpret_cast<sockaddr*>(ss);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Returns a pointer to the first byte in the address data (which is
|
|
142
|
+
// stored in network byte order).
|
|
143
|
+
uint8_t* SockaddrBytes(int family, sockaddr_storage* ss) {
|
|
144
|
+
if (family == AF_INET) {
|
|
145
|
+
sockaddr_in* ss4 = reinterpret_cast<sockaddr_in*>(ss);
|
|
146
|
+
return reinterpret_cast<uint8_t*>(&ss4->sin_addr);
|
|
147
|
+
} else if (family == AF_INET6) {
|
|
148
|
+
sockaddr_in6* ss6 = reinterpret_cast<sockaddr_in6*>(ss);
|
|
149
|
+
return reinterpret_cast<uint8_t*>(&ss6->sin6_addr);
|
|
150
|
+
} else if (family == AF_PACKET) {
|
|
151
|
+
sockaddr_ll* sll = reinterpret_cast<sockaddr_ll*>(ss);
|
|
152
|
+
return reinterpret_cast<uint8_t*>(&sll->sll_addr);
|
|
153
|
+
}
|
|
154
|
+
return nullptr;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
static void __getifaddrs_callback(void* context, nlmsghdr* hdr) {
|
|
159
|
+
ifaddrs** out = reinterpret_cast<ifaddrs**>(context);
|
|
160
|
+
|
|
161
|
+
if (hdr->nlmsg_type == RTM_NEWLINK) {
|
|
162
|
+
ifinfomsg* ifi = reinterpret_cast<ifinfomsg*>(NLMSG_DATA(hdr));
|
|
163
|
+
|
|
164
|
+
// Create a new ifaddr entry, and set the interface index and flags.
|
|
165
|
+
ifaddrs_storage* new_addr = new ifaddrs_storage(out);
|
|
166
|
+
new_addr->interface_index = ifi->ifi_index;
|
|
167
|
+
new_addr->ifa.ifa_flags = ifi->ifi_flags;
|
|
168
|
+
|
|
169
|
+
// Go through the various bits of information and find the name.
|
|
170
|
+
rtattr* rta = IFLA_RTA(ifi);
|
|
171
|
+
size_t rta_len = IFLA_PAYLOAD(hdr);
|
|
172
|
+
while (RTA_OK(rta, rta_len)) {
|
|
173
|
+
if (rta->rta_type == IFLA_ADDRESS) {
|
|
174
|
+
if (RTA_PAYLOAD(rta) < sizeof(new_addr->addr)) {
|
|
175
|
+
new_addr->SetAddress(AF_PACKET, RTA_DATA(rta), RTA_PAYLOAD(rta));
|
|
176
|
+
new_addr->SetPacketAttributes(ifi->ifi_index, ifi->ifi_type, RTA_PAYLOAD(rta));
|
|
177
|
+
}
|
|
178
|
+
} else if (rta->rta_type == IFLA_BROADCAST) {
|
|
179
|
+
if (RTA_PAYLOAD(rta) < sizeof(new_addr->ifa_ifu)) {
|
|
180
|
+
new_addr->SetBroadcastAddress(AF_PACKET, RTA_DATA(rta), RTA_PAYLOAD(rta));
|
|
181
|
+
new_addr->SetPacketAttributes(ifi->ifi_index, ifi->ifi_type, RTA_PAYLOAD(rta));
|
|
182
|
+
}
|
|
183
|
+
} else if (rta->rta_type == IFLA_IFNAME) {
|
|
184
|
+
if (RTA_PAYLOAD(rta) < sizeof(new_addr->name)) {
|
|
185
|
+
memcpy(new_addr->name, RTA_DATA(rta), RTA_PAYLOAD(rta));
|
|
186
|
+
new_addr->ifa.ifa_name = new_addr->name;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
rta = RTA_NEXT(rta, rta_len);
|
|
190
|
+
}
|
|
191
|
+
} else if (hdr->nlmsg_type == RTM_NEWADDR) {
|
|
192
|
+
ifaddrmsg* msg = reinterpret_cast<ifaddrmsg*>(NLMSG_DATA(hdr));
|
|
193
|
+
|
|
194
|
+
// We might already know about this interface from an RTM_NEWLINK message.
|
|
195
|
+
const ifaddrs_storage* known_addr = reinterpret_cast<const ifaddrs_storage*>(*out);
|
|
196
|
+
while (known_addr != nullptr && known_addr->interface_index != static_cast<int>(msg->ifa_index)) {
|
|
197
|
+
known_addr = reinterpret_cast<const ifaddrs_storage*>(known_addr->ifa.ifa_next);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Create a new ifaddr entry, and set the interface index.
|
|
201
|
+
ifaddrs_storage* new_addr = new ifaddrs_storage(out);
|
|
202
|
+
new_addr->interface_index = static_cast<int>(msg->ifa_index);
|
|
203
|
+
|
|
204
|
+
// If this is a known interface, copy what we already know.
|
|
205
|
+
// If we don't know about this interface yet, we try to resolve the name and flags using ioctl
|
|
206
|
+
// calls during postprocessing.
|
|
207
|
+
if (known_addr != nullptr) {
|
|
208
|
+
strcpy(new_addr->name, known_addr->name);
|
|
209
|
+
new_addr->ifa.ifa_name = new_addr->name;
|
|
210
|
+
new_addr->ifa.ifa_flags = known_addr->ifa.ifa_flags;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Go through the various bits of information and find the name, address
|
|
214
|
+
// and any broadcast/destination address.
|
|
215
|
+
rtattr* rta = IFA_RTA(msg);
|
|
216
|
+
size_t rta_len = IFA_PAYLOAD(hdr);
|
|
217
|
+
while (RTA_OK(rta, rta_len)) {
|
|
218
|
+
if (rta->rta_type == IFA_ADDRESS) {
|
|
219
|
+
if (msg->ifa_family == AF_INET || msg->ifa_family == AF_INET6) {
|
|
220
|
+
new_addr->SetAddress(msg->ifa_family, RTA_DATA(rta), RTA_PAYLOAD(rta));
|
|
221
|
+
new_addr->SetNetmask(msg->ifa_family, msg->ifa_prefixlen);
|
|
222
|
+
}
|
|
223
|
+
} else if (rta->rta_type == IFA_BROADCAST) {
|
|
224
|
+
if (msg->ifa_family == AF_INET) {
|
|
225
|
+
new_addr->SetBroadcastAddress(msg->ifa_family, RTA_DATA(rta), RTA_PAYLOAD(rta));
|
|
226
|
+
if (known_addr == nullptr) {
|
|
227
|
+
// We did not read the broadcast flag from an RTM_NEWLINK message.
|
|
228
|
+
// Ensure that it is set.
|
|
229
|
+
new_addr->ifa.ifa_flags |= IFF_BROADCAST;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
} else if (rta->rta_type == IFA_LOCAL) {
|
|
233
|
+
if (msg->ifa_family == AF_INET || msg->ifa_family == AF_INET6) {
|
|
234
|
+
new_addr->SetLocalAddress(msg->ifa_family, RTA_DATA(rta), RTA_PAYLOAD(rta));
|
|
235
|
+
}
|
|
236
|
+
} else if (rta->rta_type == IFA_LABEL) {
|
|
237
|
+
if (RTA_PAYLOAD(rta) < sizeof(new_addr->name)) {
|
|
238
|
+
memcpy(new_addr->name, RTA_DATA(rta), RTA_PAYLOAD(rta));
|
|
239
|
+
new_addr->ifa.ifa_name = new_addr->name;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
rta = RTA_NEXT(rta, rta_len);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
static void resolve_or_remove_nameless_interfaces(ifaddrs** list) {
|
|
248
|
+
ifaddrs_storage* addr = reinterpret_cast<ifaddrs_storage*>(*list);
|
|
249
|
+
ifaddrs_storage* prev_addr = nullptr;
|
|
250
|
+
while (addr != nullptr) {
|
|
251
|
+
ifaddrs* next_addr = addr->ifa.ifa_next;
|
|
252
|
+
|
|
253
|
+
// Try resolving interfaces without a name first.
|
|
254
|
+
if (strlen(addr->name) == 0) {
|
|
255
|
+
if (if_indextoname(addr->interface_index, addr->name) != nullptr) {
|
|
256
|
+
addr->ifa.ifa_name = addr->name;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// If the interface could not be resolved, remove it.
|
|
261
|
+
if (strlen(addr->name) == 0) {
|
|
262
|
+
if (prev_addr == nullptr) {
|
|
263
|
+
*list = next_addr;
|
|
264
|
+
} else {
|
|
265
|
+
prev_addr->ifa.ifa_next = next_addr;
|
|
266
|
+
}
|
|
267
|
+
free(addr);
|
|
268
|
+
} else {
|
|
269
|
+
prev_addr = addr;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
addr = reinterpret_cast<ifaddrs_storage*>(next_addr);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
static void get_interface_flags_via_ioctl(ifaddrs** list) {
|
|
277
|
+
ScopedFd s(socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0));
|
|
278
|
+
if (s.get() == -1) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
for (ifaddrs_storage* addr = reinterpret_cast<ifaddrs_storage*>(*list); addr != nullptr;
|
|
283
|
+
addr = reinterpret_cast<ifaddrs_storage*>(addr->ifa.ifa_next)) {
|
|
284
|
+
ifreq ifr = {};
|
|
285
|
+
strlcpy(ifr.ifr_name, addr->ifa.ifa_name, sizeof(ifr.ifr_name));
|
|
286
|
+
if (ioctl(s.get(), SIOCGIFFLAGS, &ifr) != -1) {
|
|
287
|
+
addr->ifa.ifa_flags = ifr.ifr_flags;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
int getifaddrs(ifaddrs** out) {
|
|
293
|
+
// We construct the result directly into `out`, so terminate the list.
|
|
294
|
+
*out = nullptr;
|
|
295
|
+
|
|
296
|
+
// Open the netlink socket and ask for all the links and addresses.
|
|
297
|
+
NetlinkConnection nc;
|
|
298
|
+
// SELinux policy only allows RTM_GETLINK messages to be sent by system apps.
|
|
299
|
+
bool getlink_success = false;
|
|
300
|
+
bool getaddr_success =
|
|
301
|
+
nc.SendRequest(RTM_GETADDR) && nc.ReadResponses(__getifaddrs_callback, out);
|
|
302
|
+
|
|
303
|
+
if (!getaddr_success) {
|
|
304
|
+
freeifaddrs(*out);
|
|
305
|
+
// Ensure that callers crash if they forget to check for success.
|
|
306
|
+
*out = nullptr;
|
|
307
|
+
return -1;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (!getlink_success) {
|
|
311
|
+
// If we weren't able to depend on GETLINK messages, it's possible some
|
|
312
|
+
// interfaces never got their name set. Resolve them using if_indextoname or remove them.
|
|
313
|
+
resolve_or_remove_nameless_interfaces(out);
|
|
314
|
+
// Similarly, without GETLINK messages, interfaces will not have their flags set.
|
|
315
|
+
// Resolve them using the SIOCGIFFLAGS ioctl call.
|
|
316
|
+
get_interface_flags_via_ioctl(out);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return 0;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
void freeifaddrs(ifaddrs* list) {
|
|
323
|
+
while (list != nullptr) {
|
|
324
|
+
ifaddrs* current = list;
|
|
325
|
+
list = list->ifa_next;
|
|
326
|
+
free(current);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// DITTO VENDORING - bionic/bionic_netlink.cpp, modified
|
|
331
|
+
|
|
332
|
+
NetlinkConnection::NetlinkConnection() {
|
|
333
|
+
// The kernel keeps packets under 8KiB (NLMSG_GOODSIZE),
|
|
334
|
+
// but that's a bit too large to go on the stack.
|
|
335
|
+
size_ = 8192;
|
|
336
|
+
data_ = new char[size_];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
NetlinkConnection::~NetlinkConnection() {
|
|
340
|
+
delete[] data_;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
bool NetlinkConnection::SendRequest(int type) {
|
|
344
|
+
// Rather than force all callers to check for the unlikely event of being
|
|
345
|
+
// unable to allocate 8KiB, check here.
|
|
346
|
+
if (data_ == nullptr) return false;
|
|
347
|
+
|
|
348
|
+
// Did we open a netlink socket yet?
|
|
349
|
+
if (fd_.get() == -1) {
|
|
350
|
+
fd_.reset(socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE));
|
|
351
|
+
if (fd_.get() == -1) return false;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Construct and send the message.
|
|
355
|
+
struct NetlinkMessage {
|
|
356
|
+
nlmsghdr hdr;
|
|
357
|
+
rtgenmsg msg;
|
|
358
|
+
} request;
|
|
359
|
+
memset(&request, 0, sizeof(request));
|
|
360
|
+
request.hdr.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST;
|
|
361
|
+
request.hdr.nlmsg_type = type;
|
|
362
|
+
request.hdr.nlmsg_len = sizeof(request);
|
|
363
|
+
request.msg.rtgen_family = AF_UNSPEC; // All families.
|
|
364
|
+
return (TEMP_FAILURE_RETRY(send(fd_.get(), &request, sizeof(request), 0)) == sizeof(request));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
bool NetlinkConnection::ReadResponses(void callback(void*, nlmsghdr*), void* context) {
|
|
368
|
+
// Read through all the responses, handing interesting ones to the callback.
|
|
369
|
+
ssize_t bytes_read;
|
|
370
|
+
while ((bytes_read = TEMP_FAILURE_RETRY(recv(fd_.get(), data_, size_, 0))) > 0) {
|
|
371
|
+
nlmsghdr* hdr = reinterpret_cast<nlmsghdr*>(data_);
|
|
372
|
+
for (; NLMSG_OK(hdr, static_cast<size_t>(bytes_read)); hdr = NLMSG_NEXT(hdr, bytes_read)) {
|
|
373
|
+
if (hdr->nlmsg_type == NLMSG_DONE) return true;
|
|
374
|
+
if (hdr->nlmsg_type == NLMSG_ERROR) {
|
|
375
|
+
nlmsgerr* err = reinterpret_cast<nlmsgerr*>(NLMSG_DATA(hdr));
|
|
376
|
+
errno = (hdr->nlmsg_len >= NLMSG_LENGTH(sizeof(nlmsgerr))) ? -err->error : EIO;
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
callback(context, hdr);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// We only get here if recv fails before we see a NLMSG_DONE.
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// DITTO VENDORING - private/ScopedFd.h, modified
|
|
2
|
+
|
|
3
|
+
#include <sys/types.h>
|
|
4
|
+
#include <unistd.h>
|
|
5
|
+
|
|
6
|
+
#include <linux/netlink.h>
|
|
7
|
+
#include <linux/rtnetlink.h>
|
|
8
|
+
|
|
9
|
+
class ScopedFd final {
|
|
10
|
+
public:
|
|
11
|
+
explicit ScopedFd(int fd) : fd_(fd) {
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
ScopedFd() : fd_(-1) {
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
~ScopedFd() {
|
|
18
|
+
reset(-1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
void reset(int fd = -1) {
|
|
22
|
+
if (fd_ != -1) {
|
|
23
|
+
close(fd_);
|
|
24
|
+
}
|
|
25
|
+
fd_ = fd;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
int get() const {
|
|
29
|
+
return fd_;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private:
|
|
33
|
+
int fd_;
|
|
34
|
+
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// DITTO VENDORING - bionic/ifaddrs.h, modified
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
* Copyright (C) 2019 The Android Open Source Project
|
|
41
|
+
* All rights reserved.
|
|
42
|
+
*
|
|
43
|
+
* Redistribution and use in source and binary forms, with or without
|
|
44
|
+
* modification, are permitted provided that the following conditions
|
|
45
|
+
* are met:
|
|
46
|
+
* * Redistributions of source code must retain the above copyright
|
|
47
|
+
* notice, this list of conditions and the following disclaimer.
|
|
48
|
+
* * Redistributions in binary form must reproduce the above copyright
|
|
49
|
+
* notice, this list of conditions and the following disclaimer in
|
|
50
|
+
* the documentation and/or other materials provided with the
|
|
51
|
+
* distribution.
|
|
52
|
+
*
|
|
53
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
54
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
55
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
56
|
+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
57
|
+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
58
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
59
|
+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
60
|
+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
61
|
+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
62
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
63
|
+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
64
|
+
* SUCH DAMAGE.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
* Copyright (C) 2015 The Android Open Source Project
|
|
70
|
+
* All rights reserved.
|
|
71
|
+
*
|
|
72
|
+
* Redistribution and use in source and binary forms, with or without
|
|
73
|
+
* modification, are permitted provided that the following conditions
|
|
74
|
+
* are met:
|
|
75
|
+
* * Redistributions of source code must retain the above copyright
|
|
76
|
+
* notice, this list of conditions and the following disclaimer.
|
|
77
|
+
* * Redistributions in binary form must reproduce the above copyright
|
|
78
|
+
* notice, this list of conditions and the following disclaimer in
|
|
79
|
+
* the documentation and/or other materials provided with the
|
|
80
|
+
* distribution.
|
|
81
|
+
*
|
|
82
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
83
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
84
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
85
|
+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
86
|
+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
87
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
88
|
+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
89
|
+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
90
|
+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
91
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
92
|
+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
93
|
+
* SUCH DAMAGE.
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @file ifaddrs.h
|
|
98
|
+
* @brief Access to network interface addresses.
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
#include <sys/cdefs.h>
|
|
102
|
+
#include <netinet/in.h>
|
|
103
|
+
#include <sys/socket.h>
|
|
104
|
+
|
|
105
|
+
__BEGIN_DECLS
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Returned by getifaddrs() and freed by freeifaddrs().
|
|
109
|
+
*/
|
|
110
|
+
struct ifaddrs {
|
|
111
|
+
/** Pointer to the next element in the linked list. */
|
|
112
|
+
struct ifaddrs* ifa_next;
|
|
113
|
+
|
|
114
|
+
/** Interface name. */
|
|
115
|
+
char* ifa_name;
|
|
116
|
+
/** Interface flags (like `SIOCGIFFLAGS`). */
|
|
117
|
+
unsigned int ifa_flags;
|
|
118
|
+
/** Interface address. */
|
|
119
|
+
struct sockaddr* ifa_addr;
|
|
120
|
+
/** Interface netmask. */
|
|
121
|
+
struct sockaddr* ifa_netmask;
|
|
122
|
+
|
|
123
|
+
union {
|
|
124
|
+
/** Interface broadcast address (if IFF_BROADCAST is set). */
|
|
125
|
+
struct sockaddr* ifu_broadaddr;
|
|
126
|
+
/** Interface destination address (if IFF_POINTOPOINT is set). */
|
|
127
|
+
struct sockaddr* ifu_dstaddr;
|
|
128
|
+
} ifa_ifu;
|
|
129
|
+
|
|
130
|
+
/** Unused. */
|
|
131
|
+
void* ifa_data;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/** Synonym for `ifa_ifu.ifu_broadaddr` in `struct ifaddrs`. */
|
|
135
|
+
#define ifa_broadaddr ifa_ifu.ifu_broadaddr
|
|
136
|
+
/** Synonym for `ifa_ifu.ifu_dstaddr` in `struct ifaddrs`. */
|
|
137
|
+
#define ifa_dstaddr ifa_ifu.ifu_dstaddr
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* [getifaddrs(3)](http://man7.org/linux/man-pages/man3/getifaddrs.3.html) creates a linked list
|
|
141
|
+
* of `struct ifaddrs`. The list must be freed by freeifaddrs().
|
|
142
|
+
*
|
|
143
|
+
* Returns 0 and stores the list in `*__list_ptr` on success,
|
|
144
|
+
* and returns -1 and sets `errno` on failure.
|
|
145
|
+
*
|
|
146
|
+
* Available since API level 24.
|
|
147
|
+
*/
|
|
148
|
+
int getifaddrs(struct ifaddrs** __list_ptr) __INTRODUCED_IN(24);
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* [freeifaddrs(3)](http://man7.org/linux/man-pages/man3/freeifaddrs.3.html) frees a linked list
|
|
152
|
+
* of `struct ifaddrs` returned by getifaddrs().
|
|
153
|
+
*
|
|
154
|
+
* Available since API level 24.
|
|
155
|
+
*/
|
|
156
|
+
void freeifaddrs(struct ifaddrs* __ptr) __INTRODUCED_IN(24);
|
|
157
|
+
|
|
158
|
+
__END_DECLS
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
// DITTO VENDORING - bionic/bionic_netlink.h, modified
|
|
162
|
+
|
|
163
|
+
/*
|
|
164
|
+
* Copyright (C) 2016 The Android Open Source Project
|
|
165
|
+
* All rights reserved.
|
|
166
|
+
*
|
|
167
|
+
* Redistribution and use in source and binary forms, with or without
|
|
168
|
+
* modification, are permitted provided that the following conditions
|
|
169
|
+
* are met:
|
|
170
|
+
* * Redistributions of source code must retain the above copyright
|
|
171
|
+
* notice, this list of conditions and the following disclaimer.
|
|
172
|
+
* * Redistributions in binary form must reproduce the above copyright
|
|
173
|
+
* notice, this list of conditions and the following disclaimer in
|
|
174
|
+
* the documentation and/or other materials provided with the
|
|
175
|
+
* distribution.
|
|
176
|
+
*
|
|
177
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
178
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
179
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
180
|
+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
181
|
+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
182
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
183
|
+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
184
|
+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
185
|
+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
186
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
187
|
+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
188
|
+
* SUCH DAMAGE.
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
struct nlmsghdr;
|
|
193
|
+
|
|
194
|
+
class NetlinkConnection {
|
|
195
|
+
public:
|
|
196
|
+
NetlinkConnection();
|
|
197
|
+
~NetlinkConnection();
|
|
198
|
+
|
|
199
|
+
bool SendRequest(int type);
|
|
200
|
+
bool ReadResponses(void callback(void*, nlmsghdr*), void* context);
|
|
201
|
+
|
|
202
|
+
private:
|
|
203
|
+
ScopedFd fd_;
|
|
204
|
+
char* data_;
|
|
205
|
+
size_t size_;
|
|
206
|
+
};
|