mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-22 20:44:56 +00:00
almost compiling on android. linker error.
This commit is contained in:
parent
b7aac66551
commit
9783b971fb
19
libtorrent/runme-android.sh
Normal file
19
libtorrent/runme-android.sh
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
export PATH=/home/miguel/android/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/:$PATH
|
||||||
|
export NDK=/home/miguel/android/android-ndk-r8b
|
||||||
|
export NDK_BASE=$NDK
|
||||||
|
export SYSROOT=$NDK/platforms/android-9/arch-arm
|
||||||
|
export BOOSTDIR=/home/miguel/android/Boost-for-Android/build/
|
||||||
|
|
||||||
|
#make -j2
|
||||||
|
#exit
|
||||||
|
|
||||||
|
./configure --host=arm-linux-androideabi --enable-shared=no --enable-static=yes\
|
||||||
|
CPPFLAGS="-I$SYSROOT/usr/include/ -I$BOOSTDIR/include \
|
||||||
|
-I$NDK_BASE/sources/cxx-stl/gnu-libstdc++/4.6/include \
|
||||||
|
-I$NDK_BASE/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include \
|
||||||
|
-fexceptions -frtti" \
|
||||||
|
LDFLAGS="-Wl,-rpath-link=$SYSROOT/usr/lib/ -L$SYSROOT/usr/lib/ -L$BOOSTDIR/lib \
|
||||||
|
$BOOSTDIR/lib/libboost_system-gcc-mt-1_49.a $BOOSTDIR/lib/libboost_thread-gcc-mt-1_49.a \
|
||||||
|
$NDK_BASE/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/libgnustl_static.a" \
|
||||||
|
LIBS="-lc" CFLAGS="-nostdlib" --prefix="$SYSROOT/usr" \
|
||||||
|
--with-boost=$BOOSTDIR --with-boost-libdir=$BOOSTDIR/lib && make -j2
|
222
src/makefile.android
Normal file
222
src/makefile.android
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
# Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||||
|
# Distributed under the MIT/X11 software license, see the accompanying
|
||||||
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
# :=0 --> UPnP support turned off by default at runtime
|
||||||
|
# :=1 --> UPnP support turned on by default at runtime
|
||||||
|
# :=- --> No UPnP support - miniupnp not required
|
||||||
|
USE_UPNP:=-
|
||||||
|
|
||||||
|
# :=1 --> Enable IPv6 support
|
||||||
|
# :=0 --> Disable IPv6 support
|
||||||
|
USE_IPV6:=0
|
||||||
|
|
||||||
|
LINK:=$(CXX)
|
||||||
|
|
||||||
|
DEFS=-DBOOST_SPIRIT_THREADSAFE -D_FILE_OFFSET_BITS=64
|
||||||
|
|
||||||
|
DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
|
||||||
|
LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
|
||||||
|
|
||||||
|
TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
|
||||||
|
|
||||||
|
LMODE = static
|
||||||
|
LMODE2 = static
|
||||||
|
ifdef STATIC
|
||||||
|
LMODE = static
|
||||||
|
ifeq (${STATIC}, all)
|
||||||
|
LMODE2 = static
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
TESTDEFS += -DBOOST_TEST_DYN_LINK
|
||||||
|
endif
|
||||||
|
|
||||||
|
# for boost 1.37, add -mt to the boost libraries
|
||||||
|
LIBS += \
|
||||||
|
-Wl,-B$(LMODE) \
|
||||||
|
-l boost_system$(BOOST_LIB_SUFFIX) \
|
||||||
|
-l boost_filesystem$(BOOST_LIB_SUFFIX) \
|
||||||
|
-l boost_program_options$(BOOST_LIB_SUFFIX) \
|
||||||
|
-l boost_thread$(BOOST_LIB_SUFFIX) \
|
||||||
|
-l db_cxx$(BDB_LIB_SUFFIX) \
|
||||||
|
-l ssl \
|
||||||
|
-l crypto \
|
||||||
|
-l rt
|
||||||
|
|
||||||
|
TESTLIBS += \
|
||||||
|
-Wl,-B$(LMODE) \
|
||||||
|
-l boost_unit_test_framework$(BOOST_LIB_SUFFIX)
|
||||||
|
|
||||||
|
ifndef USE_UPNP
|
||||||
|
override USE_UPNP = -
|
||||||
|
endif
|
||||||
|
ifneq (${USE_UPNP}, -)
|
||||||
|
LIBS += -l miniupnpc
|
||||||
|
DEFS += -DUSE_UPNP=$(USE_UPNP)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq (${USE_IPV6}, -)
|
||||||
|
DEFS += -DUSE_IPV6=$(USE_IPV6)
|
||||||
|
endif
|
||||||
|
|
||||||
|
LIBS+= \
|
||||||
|
-Wl,-B$(LMODE2) \
|
||||||
|
-l z \
|
||||||
|
-l dl \
|
||||||
|
-l pthread
|
||||||
|
|
||||||
|
|
||||||
|
# Hardening
|
||||||
|
# Make some classes of vulnerabilities unexploitable in case one is discovered.
|
||||||
|
#
|
||||||
|
# This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
|
||||||
|
# -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
|
||||||
|
# see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
|
||||||
|
HARDENING=-fno-stack-protector
|
||||||
|
|
||||||
|
# Stack Canaries
|
||||||
|
# Put numbers at the beginning of each stack frame and check that they are the same.
|
||||||
|
# If a stack buffer if overflowed, it writes over the canary number and then on return
|
||||||
|
# when that number is checked, it won't be the same and the program will exit with
|
||||||
|
# a "Stack smashing detected" error instead of being exploited.
|
||||||
|
HARDENING+=-fstack-protector-all -Wstack-protector
|
||||||
|
|
||||||
|
# Make some important things such as the global offset table read only as soon as
|
||||||
|
# the dynamic linker is finished building it. This will prevent overwriting of addresses
|
||||||
|
# which would later be jumped to.
|
||||||
|
LDHARDENING+=-Wl,-z,relro -Wl,-z,now
|
||||||
|
|
||||||
|
# Build position independent code to take advantage of Address Space Layout Randomization
|
||||||
|
# offered by some kernels.
|
||||||
|
# see doc/build-unix.txt for more information.
|
||||||
|
ifdef PIE
|
||||||
|
HARDENING+=-fPIE
|
||||||
|
LDHARDENING+=-pie
|
||||||
|
endif
|
||||||
|
|
||||||
|
# -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
|
||||||
|
# the source such overflowing a statically defined buffer.
|
||||||
|
HARDENING+=-D_FORTIFY_SOURCE=2
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
DEBUGFLAGS=-g
|
||||||
|
|
||||||
|
# CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only
|
||||||
|
# adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work.
|
||||||
|
xCXXFLAGS=-O2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter \
|
||||||
|
$(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
|
||||||
|
|
||||||
|
# LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only
|
||||||
|
# adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work.
|
||||||
|
xLDFLAGS=$(LDHARDENING) $(LDFLAGS)
|
||||||
|
|
||||||
|
OBJS= \
|
||||||
|
leveldb/libleveldb.a \
|
||||||
|
../libtorrent/src/.libs/libtorrent-rasterbar.a \
|
||||||
|
obj/alert.o \
|
||||||
|
obj/version.o \
|
||||||
|
obj/checkpoints.o \
|
||||||
|
obj/netbase.o \
|
||||||
|
obj/addrman.o \
|
||||||
|
obj/crypter.o \
|
||||||
|
obj/key.o \
|
||||||
|
obj/db.o \
|
||||||
|
obj/init.o \
|
||||||
|
obj/bitcoind.o \
|
||||||
|
obj/keystore.o \
|
||||||
|
obj/core.o \
|
||||||
|
obj/main.o \
|
||||||
|
obj/net.o \
|
||||||
|
obj/protocol.o \
|
||||||
|
obj/bitcoinrpc.o \
|
||||||
|
obj/rpcdump.o \
|
||||||
|
obj/rpcnet.o \
|
||||||
|
obj/rpcmining.o \
|
||||||
|
obj/rpcwallet.o \
|
||||||
|
obj/rpcblockchain.o \
|
||||||
|
obj/rpcrawtransaction.o \
|
||||||
|
obj/script.o \
|
||||||
|
obj/sync.o \
|
||||||
|
obj/util.o \
|
||||||
|
obj/wallet.o \
|
||||||
|
obj/walletdb.o \
|
||||||
|
obj/hash.o \
|
||||||
|
obj/bloom.o \
|
||||||
|
obj/noui.o \
|
||||||
|
obj/leveldb.o \
|
||||||
|
obj/txdb.o \
|
||||||
|
obj/chainparams.o \
|
||||||
|
obj/twister.o \
|
||||||
|
obj/twister_utils.o
|
||||||
|
|
||||||
|
|
||||||
|
all: twisterd
|
||||||
|
|
||||||
|
test check: test_bitcoin FORCE
|
||||||
|
./test_bitcoin
|
||||||
|
|
||||||
|
#
|
||||||
|
# LevelDB support
|
||||||
|
#
|
||||||
|
MAKEOVERRIDES =
|
||||||
|
LIBS += $(CURDIR)/leveldb/libleveldb.a $(CURDIR)/leveldb/libmemenv.a
|
||||||
|
DEFS += $(addprefix -I,$(CURDIR)/leveldb/include)
|
||||||
|
DEFS += $(addprefix -I,$(CURDIR)/leveldb/helpers)
|
||||||
|
leveldb/libleveldb.a:
|
||||||
|
@echo "Building LevelDB ..." && cd leveldb && $(MAKE) CC=$(CC) CXX=$(CXX) OPT="$(xCXXFLAGS)" libleveldb.a libmemenv.a && cd ..
|
||||||
|
|
||||||
|
#
|
||||||
|
# libtorrent hack
|
||||||
|
#
|
||||||
|
MAKEOVERRIDES =
|
||||||
|
LIBS += $(CURDIR)/../libtorrent/src/.libs/libtorrent-rasterbar.a
|
||||||
|
DEFS += $(addprefix -I,$(CURDIR)/../libtorrent/include)
|
||||||
|
DEFS += -DTORRENT_DEBUG
|
||||||
|
DEFS += -DBOOST_ASIO_SEPARATE_COMPILATION
|
||||||
|
#DEFS += -DBOOST_ASIO_DYN_LINK
|
||||||
|
../libtorrent/src/.libs/libtorrent-rasterbar.a:
|
||||||
|
@echo "Building libtorrent ..." && cd ../libtorrent && $(MAKE) CC=$(CC) CXX=$(CXX) OPT="$(xCXXFLAGS)" && cd ../src
|
||||||
|
|
||||||
|
|
||||||
|
# auto-generated dependencies:
|
||||||
|
-include obj/*.P
|
||||||
|
-include obj-test/*.P
|
||||||
|
|
||||||
|
obj/build.h: FORCE
|
||||||
|
/bin/sh ../share/genbuild.sh obj/build.h
|
||||||
|
version.cpp: obj/build.h
|
||||||
|
DEFS += -DHAVE_BUILD_INFO
|
||||||
|
|
||||||
|
obj/%.o: %.cpp
|
||||||
|
$(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
|
||||||
|
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
|
||||||
|
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
|
||||||
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
|
||||||
|
rm -f $(@:%.o=%.d)
|
||||||
|
|
||||||
|
twisterd: $(OBJS:obj/%=obj/%)
|
||||||
|
$(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
|
||||||
|
|
||||||
|
TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
|
||||||
|
|
||||||
|
obj-test/%.o: test/%.cpp
|
||||||
|
$(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
|
||||||
|
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
|
||||||
|
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
|
||||||
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
|
||||||
|
rm -f $(@:%.o=%.d)
|
||||||
|
|
||||||
|
test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o obj/bitcoind.o,$(OBJS:obj/%=obj/%))
|
||||||
|
$(LINK) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ $(TESTLIBS) $(xLDFLAGS) $(LIBS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-rm -f twisterd test_bitcoin
|
||||||
|
-rm -f obj/*.o
|
||||||
|
-rm -f obj-test/*.o
|
||||||
|
-rm -f obj/*.P
|
||||||
|
-rm -f obj-test/*.P
|
||||||
|
-rm -f obj/build.h
|
||||||
|
-cd leveldb && $(MAKE) clean || true
|
||||||
|
|
||||||
|
FORCE:
|
372
src/net.cpp
372
src/net.cpp
@ -1638,173 +1638,259 @@ bool BindListenPort(const CService &addrBind, string& strError)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
// Implementation of getifaddrs for Android.
|
||||||
|
// Fills out a list of ifaddr structs (see below) which contain information
|
||||||
|
// about every network interface available on the host.
|
||||||
|
// See 'man getifaddrs' on Linux or OS X (nb: it is not a POSIX function).
|
||||||
struct ifaddrs {
|
struct ifaddrs {
|
||||||
struct ifaddrs *ifa_next;
|
struct ifaddrs* ifa_next;
|
||||||
char *ifa_name;
|
char* ifa_name;
|
||||||
unsigned int ifa_flags;
|
unsigned int ifa_flags;
|
||||||
struct sockaddr *ifa_addr;
|
struct sockaddr* ifa_addr;
|
||||||
struct sockaddr *ifa_netmask;
|
struct sockaddr* ifa_netmask;
|
||||||
union {
|
// Real ifaddrs has broadcast, point to point and data members.
|
||||||
struct sockaddr *ifu_broadaddr;
|
// We don't need them (yet?).
|
||||||
struct sockaddr *ifu_dstaddr;
|
|
||||||
} ifa_ifu;
|
|
||||||
#define ifa_broadaddr ifa_ifu.ifu_broadaddr
|
|
||||||
#define ifa_dstaddr ifa_ifu.ifu_dstaddr
|
|
||||||
void *ifa_data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern int getifaddrs(struct ifaddrs **ifap);
|
int getifaddrs(struct ifaddrs** result);
|
||||||
extern void freeifaddrs(struct ifaddrs *ifa);
|
void freeifaddrs(struct ifaddrs* addrs);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* libjingle
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
|
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
/* external/dhcpcd/ifaddrs.c
|
|
||||||
**
|
|
||||||
** Copyright 2011, The Android Open Source Project
|
|
||||||
**
|
|
||||||
** Licensed under the Apache License, Version 2.0 (the "License");.
|
|
||||||
** you may not use this file except in compliance with the License..
|
|
||||||
** You may obtain a copy of the License at.
|
|
||||||
**
|
|
||||||
** http://www.apache.org/licenses/LICENSE-2.0.
|
|
||||||
**
|
|
||||||
** Unless required by applicable law or agreed to in writing, software.
|
|
||||||
** distributed under the License is distributed on an "AS IS" BASIS,.
|
|
||||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied..
|
|
||||||
** See the License for the specific language governing permissions and.
|
|
||||||
** limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include "ifaddrs.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <dirent.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/ether.h>
|
#include <sys/utsname.h>
|
||||||
#include <netdb.h>
|
#include <sys/ioctl.h>
|
||||||
#include <linux/if_packet.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/if_ether.h>
|
#include <net/if.h>
|
||||||
#include <linux/if_arp.h>
|
#include <unistd.h>
|
||||||
#include <netutils/ifc.h>
|
#include <errno.h>
|
||||||
|
#include <linux/netlink.h>
|
||||||
|
#include <linux/rtnetlink.h>
|
||||||
|
|
||||||
struct ifaddrs *get_interface(const char *name, sa_family_t family)
|
struct netlinkrequest {
|
||||||
{
|
nlmsghdr header;
|
||||||
unsigned addr, mask, flags;
|
ifaddrmsg msg;
|
||||||
struct ifaddrs *ifa;
|
};
|
||||||
struct sockaddr_in *saddr = NULL;
|
|
||||||
struct sockaddr_in *smask = NULL;
|
|
||||||
struct sockaddr_ll *hwaddr = NULL;
|
|
||||||
unsigned char hwbuf[ETH_ALEN];
|
|
||||||
|
|
||||||
if(ifc_get_info(name, &addr, &mask, &flags))
|
namespace {
|
||||||
return NULL;
|
const int kMaxReadSize = 4096;
|
||||||
|
};
|
||||||
|
|
||||||
if ((family == AF_INET) && (addr == 0))
|
int set_ifname(struct ifaddrs* ifaddr, int interface) {
|
||||||
return NULL;
|
char buf[IFNAMSIZ] = {0};
|
||||||
|
char* name = if_indextoname(interface, buf);
|
||||||
|
if (name == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ifaddr->ifa_name = new char[strlen(name) + 1];
|
||||||
|
strncpy(ifaddr->ifa_name, name, strlen(name) + 1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
ifa = malloc(sizeof(struct ifaddrs));
|
int set_flags(struct ifaddrs* ifaddr) {
|
||||||
if (!ifa)
|
int fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
return NULL;
|
if (fd == -1) {
|
||||||
memset(ifa, 0, sizeof(struct ifaddrs));
|
return -1;
|
||||||
|
}
|
||||||
|
ifreq ifr;
|
||||||
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
|
strncpy(ifr.ifr_name, ifaddr->ifa_name, IFNAMSIZ - 1);
|
||||||
|
int rc = ioctl(fd, SIOCGIFFLAGS, &ifr);
|
||||||
|
close(fd);
|
||||||
|
if (rc == -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ifaddr->ifa_flags = ifr.ifr_flags;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
ifa->ifa_name = malloc(strlen(name)+1);
|
int set_addresses(struct ifaddrs* ifaddr, ifaddrmsg* msg, void* data,
|
||||||
if (!ifa->ifa_name) {
|
size_t len) {
|
||||||
free(ifa);
|
if (msg->ifa_family == AF_INET) {
|
||||||
return NULL;
|
sockaddr_in* sa = new sockaddr_in;
|
||||||
|
sa->sin_family = AF_INET;
|
||||||
|
memcpy(&sa->sin_addr, data, len);
|
||||||
|
ifaddr->ifa_addr = reinterpret_cast<sockaddr*>(sa);
|
||||||
|
} else if (msg->ifa_family == AF_INET6) {
|
||||||
|
sockaddr_in6* sa = new sockaddr_in6;
|
||||||
|
sa->sin6_family = AF_INET6;
|
||||||
|
sa->sin6_scope_id = msg->ifa_index;
|
||||||
|
memcpy(&sa->sin6_addr, data, len);
|
||||||
|
ifaddr->ifa_addr = reinterpret_cast<sockaddr*>(sa);
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int make_prefixes(struct ifaddrs* ifaddr, int family, int prefixlen) {
|
||||||
|
char* prefix = NULL;
|
||||||
|
if (family == AF_INET) {
|
||||||
|
sockaddr_in* mask = new sockaddr_in;
|
||||||
|
mask->sin_family = AF_INET;
|
||||||
|
memset(&mask->sin_addr, 0, sizeof(in_addr));
|
||||||
|
ifaddr->ifa_netmask = reinterpret_cast<sockaddr*>(mask);
|
||||||
|
if (prefixlen > 32) {
|
||||||
|
prefixlen = 32;
|
||||||
}
|
}
|
||||||
strcpy(ifa->ifa_name, name);
|
prefix = reinterpret_cast<char*>(&mask->sin_addr);
|
||||||
ifa->ifa_flags = flags;
|
} else if (family == AF_INET6) {
|
||||||
|
sockaddr_in6* mask = new sockaddr_in6;
|
||||||
|
mask->sin6_family = AF_INET6;
|
||||||
|
memset(&mask->sin6_addr, 0, sizeof(in6_addr));
|
||||||
|
ifaddr->ifa_netmask = reinterpret_cast<sockaddr*>(mask);
|
||||||
|
if (prefixlen > 128) {
|
||||||
|
prefixlen = 128;
|
||||||
|
}
|
||||||
|
prefix = reinterpret_cast<char*>(&mask->sin6_addr);
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < (prefixlen / 8); i++) {
|
||||||
|
*prefix++ = 0xFF;
|
||||||
|
}
|
||||||
|
char remainder = 0xff;
|
||||||
|
remainder <<= (8 - prefixlen % 8);
|
||||||
|
*prefix = remainder;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (family == AF_INET) {
|
int populate_ifaddrs(struct ifaddrs* ifaddr, ifaddrmsg* msg, void* bytes,
|
||||||
saddr = malloc(sizeof(struct sockaddr_in));
|
size_t len) {
|
||||||
if (saddr) {
|
if (set_ifname(ifaddr, msg->ifa_index) != 0) {
|
||||||
saddr->sin_addr.s_addr = addr;
|
return -1;
|
||||||
saddr->sin_family = family;
|
}
|
||||||
}
|
if (set_flags(ifaddr) != 0) {
|
||||||
ifa->ifa_addr = (struct sockaddr *)saddr;
|
return -1;
|
||||||
|
}
|
||||||
|
if (set_addresses(ifaddr, msg, bytes, len) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (make_prefixes(ifaddr, msg->ifa_family, msg->ifa_prefixlen) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (mask != 0) {
|
int getifaddrs(struct ifaddrs** result) {
|
||||||
smask = malloc(sizeof(struct sockaddr_in));
|
int fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
|
||||||
if (smask) {
|
if (fd < 0) {
|
||||||
smask->sin_addr.s_addr = mask;
|
return -1;
|
||||||
smask->sin_family = family;
|
}
|
||||||
|
|
||||||
|
netlinkrequest ifaddr_request;
|
||||||
|
memset(&ifaddr_request, 0, sizeof(ifaddr_request));
|
||||||
|
ifaddr_request.header.nlmsg_flags = NLM_F_ROOT | NLM_F_REQUEST;
|
||||||
|
ifaddr_request.header.nlmsg_type = RTM_GETADDR;
|
||||||
|
ifaddr_request.header.nlmsg_len = NLMSG_LENGTH(sizeof(ifaddrmsg));
|
||||||
|
|
||||||
|
ssize_t count = send(fd, &ifaddr_request, ifaddr_request.header.nlmsg_len, 0);
|
||||||
|
if (static_cast<size_t>(count) != ifaddr_request.header.nlmsg_len) {
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
struct ifaddrs* start = NULL;
|
||||||
|
struct ifaddrs* current = NULL;
|
||||||
|
char buf[kMaxReadSize];
|
||||||
|
ssize_t amount_read = recv(fd, &buf, kMaxReadSize, 0);
|
||||||
|
while (amount_read > 0) {
|
||||||
|
nlmsghdr* header = reinterpret_cast<nlmsghdr*>(&buf[0]);
|
||||||
|
size_t header_size = static_cast<size_t>(amount_read);
|
||||||
|
for ( ; NLMSG_OK(header, header_size);
|
||||||
|
header = NLMSG_NEXT(header, header_size)) {
|
||||||
|
switch (header->nlmsg_type) {
|
||||||
|
case NLMSG_DONE:
|
||||||
|
// Success. Return.
|
||||||
|
*result = start;
|
||||||
|
close(fd);
|
||||||
|
return 0;
|
||||||
|
case NLMSG_ERROR:
|
||||||
|
close(fd);
|
||||||
|
freeifaddrs(start);
|
||||||
|
return -1;
|
||||||
|
case RTM_NEWADDR: {
|
||||||
|
ifaddrmsg* address_msg =
|
||||||
|
reinterpret_cast<ifaddrmsg*>(NLMSG_DATA(header));
|
||||||
|
rtattr* rta = IFA_RTA(address_msg);
|
||||||
|
ssize_t payload_len = IFA_PAYLOAD(header);
|
||||||
|
while (RTA_OK(rta, payload_len)) {
|
||||||
|
if (rta->rta_type == IFA_ADDRESS) {
|
||||||
|
int family = address_msg->ifa_family;
|
||||||
|
if (family == AF_INET || family == AF_INET6) {
|
||||||
|
ifaddrs* newest = new ifaddrs;
|
||||||
|
memset(newest, 0, sizeof(ifaddrs));
|
||||||
|
if (current) {
|
||||||
|
current->ifa_next = newest;
|
||||||
|
} else {
|
||||||
|
start = newest;
|
||||||
|
}
|
||||||
|
if (populate_ifaddrs(newest, address_msg, RTA_DATA(rta),
|
||||||
|
RTA_PAYLOAD(rta)) != 0) {
|
||||||
|
freeifaddrs(start);
|
||||||
|
*result = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
current = newest;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
rta = RTA_NEXT(rta, payload_len);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
ifa->ifa_netmask = (struct sockaddr *)smask;
|
}
|
||||||
} else if (family == AF_PACKET) {
|
|
||||||
if (!ifc_get_hwaddr(name, hwbuf)) {
|
|
||||||
hwaddr = malloc(sizeof(struct sockaddr_ll));
|
|
||||||
if (hwaddr) {
|
|
||||||
memset(hwaddr, 0, sizeof(struct sockaddr_ll));
|
|
||||||
hwaddr->sll_family = family;
|
|
||||||
/* hwaddr->sll_protocol = ETHERTYPE_IP; */
|
|
||||||
hwaddr->sll_hatype = ARPHRD_ETHER;
|
|
||||||
hwaddr->sll_halen = ETH_ALEN;
|
|
||||||
memcpy(hwaddr->sll_addr, hwbuf, ETH_ALEN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ifa->ifa_addr = (struct sockaddr *)hwaddr;
|
|
||||||
ifa->ifa_netmask = (struct sockaddr *)smask;
|
|
||||||
}
|
}
|
||||||
return ifa;
|
amount_read = recv(fd, &buf, kMaxReadSize, 0);
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
freeifaddrs(start);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getifaddrs(struct ifaddrs **ifap)
|
void freeifaddrs(struct ifaddrs* addrs) {
|
||||||
{
|
struct ifaddrs* last = NULL;
|
||||||
DIR *d;
|
struct ifaddrs* cursor = addrs;
|
||||||
struct dirent *de;
|
while (cursor) {
|
||||||
struct ifaddrs *ifa;
|
delete[] cursor->ifa_name;
|
||||||
struct ifaddrs *ifah = NULL;
|
delete cursor->ifa_addr;
|
||||||
|
delete cursor->ifa_netmask;
|
||||||
if (!ifap)
|
last = cursor;
|
||||||
return -1;
|
cursor = cursor->ifa_next;
|
||||||
*ifap = NULL;
|
delete last;
|
||||||
|
}
|
||||||
if (ifc_init())
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
d = opendir("/sys/class/net");
|
|
||||||
if (d == 0)
|
|
||||||
return -1;
|
|
||||||
while ((de = readdir(d))) {
|
|
||||||
if (de->d_name[0] == '.')
|
|
||||||
continue;
|
|
||||||
ifa = get_interface(de->d_name, AF_INET);
|
|
||||||
if (ifa != NULL) {
|
|
||||||
ifa->ifa_next = ifah;
|
|
||||||
ifah = ifa;
|
|
||||||
}
|
|
||||||
ifa = get_interface(de->d_name, AF_PACKET);
|
|
||||||
if (ifa != NULL) {
|
|
||||||
ifa->ifa_next = ifah;
|
|
||||||
ifah = ifa;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*ifap = ifah;
|
|
||||||
closedir(d);
|
|
||||||
ifc_close();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeifaddrs(struct ifaddrs *ifa)
|
|
||||||
{
|
|
||||||
struct ifaddrs *ifp;
|
|
||||||
|
|
||||||
while (ifa) {
|
|
||||||
ifp = ifa;
|
|
||||||
free(ifp->ifa_name);
|
|
||||||
if (ifp->ifa_addr)
|
|
||||||
free(ifp->ifa_addr);
|
|
||||||
if (ifp->ifa_netmask)
|
|
||||||
free(ifp->ifa_netmask);
|
|
||||||
ifa = ifa->ifa_next;
|
|
||||||
free(ifp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void static Discover()
|
void static Discover()
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <sys/fcntl.h>
|
#include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
|
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
|
||||||
|
27
src/runme-android.sh
Normal file
27
src/runme-android.sh
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
export PATH=/home/miguel/android/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/:$PATH
|
||||||
|
export NDK=/home/miguel/android/android-ndk-r8b
|
||||||
|
export NDK_BASE=$NDK
|
||||||
|
export SYSROOT=$NDK/platforms/android-9/arch-arm
|
||||||
|
export BOOSTDIR=/home/miguel/android/Boost-for-Android/build/
|
||||||
|
export TARGET_OS=OS_ANDROID_CROSSCOMPILE
|
||||||
|
|
||||||
|
export CXX=arm-linux-androideabi-gcc
|
||||||
|
export CXXFLAGS="-I$SYSROOT/usr/include/ -I$BOOSTDIR/include/boost-1_49 \
|
||||||
|
-I$NDK_BASE/sources/cxx-stl/gnu-libstdc++/4.6/include \
|
||||||
|
-I$NDK_BASE/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include \
|
||||||
|
-fexceptions -frtti -DHAVE_CXX_STDHEADERS -DANDROID"
|
||||||
|
|
||||||
|
make -f makefile.android -j2
|
||||||
|
#make -j2
|
||||||
|
#exit
|
||||||
|
|
||||||
|
#./configure --host=arm-linux-androideabi --enable-shared=no --enable-static=yes\
|
||||||
|
# CPPFLAGS="-I$SYSROOT/usr/include/ -I$BOOSTDIR/include \
|
||||||
|
# -I$NDK_BASE/sources/cxx-stl/gnu-libstdc++/4.6/include \
|
||||||
|
# -I$NDK_BASE/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include \
|
||||||
|
# -fexceptions -frtti" \
|
||||||
|
# LDFLAGS="-Wl,-rpath-link=$SYSROOT/usr/lib/ -L$SYSROOT/usr/lib/ -L$BOOSTDIR/lib \
|
||||||
|
# $BOOSTDIR/lib/libboost_system-gcc-mt-1_49.a $BOOSTDIR/lib/libboost_thread-gcc-mt-1_49.a \
|
||||||
|
# $NDK_BASE/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/libgnustl_static.a" \
|
||||||
|
# LIBS="-lc" CFLAGS="-nostdlib" --prefix="$SYSROOT/usr" \
|
||||||
|
# --with-boost=$BOOSTDIR --with-boost-libdir=$BOOSTDIR/lib && make -j2
|
@ -1221,7 +1221,7 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
|
|||||||
fcntl(fileno(file), F_PREALLOCATE, &fst);
|
fcntl(fileno(file), F_PREALLOCATE, &fst);
|
||||||
}
|
}
|
||||||
ftruncate(fileno(file), fst.fst_length);
|
ftruncate(fileno(file), fst.fst_length);
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__) && !defined(__ANDROID__)
|
||||||
// Version using posix_fallocate
|
// Version using posix_fallocate
|
||||||
off_t nEndPos = (off_t)offset + length;
|
off_t nEndPos = (off_t)offset + length;
|
||||||
posix_fallocate(fileno(file), 0, nEndPos);
|
posix_fallocate(fileno(file), 0, nEndPos);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user