Browse Source

Merge ../twister-android

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
70f96750b5
  1. 1558
      libtorrent/build-aux/config.guess
  2. 1793
      libtorrent/build-aux/config.sub
  3. 15
      libtorrent/include/libtorrent/config.hpp
  4. 22
      libtorrent/runme-android.sh
  5. 4
      libtorrent/src/asio_ssl.cpp
  6. 8
      libtorrent/src/file.cpp
  7. 5
      libtorrent/src/utp_stream.cpp
  8. 4
      src/bitcoinrpc.cpp
  9. 2
      src/compat.h
  10. 227
      src/makefile.android
  11. 256
      src/net.cpp
  12. 2
      src/netbase.cpp
  13. 29
      src/runme-android.sh
  14. 6
      src/util.cpp

1558
libtorrent/build-aux/config.guess vendored

File diff suppressed because it is too large Load Diff

1793
libtorrent/build-aux/config.sub vendored

File diff suppressed because it is too large Load Diff

15
libtorrent/include/libtorrent/config.hpp

@ -215,11 +215,22 @@ POSSIBILITY OF SUCH DAMAGE.
// ==== LINUX === // ==== LINUX ===
#elif defined __linux__ #elif defined __linux__
#define TORRENT_LINUX #define TORRENT_LINUX
#define TORRENT_USE_IFADDRS 1 #ifdef __ANDROID__
#define TORRENT_USE_IFADDRS 0
#else
#define TORRENT_USE_IFADDRS 1
#endif
#define TORRENT_USE_NETLINK 1 #define TORRENT_USE_NETLINK 1
#define TORRENT_USE_IFCONF 1 #define TORRENT_USE_IFCONF 1
#define TORRENT_HAS_SALEN 0 #define TORRENT_HAS_SALEN 0
#define TORRENT_USE_POSIX_MEMALIGN 1 #ifdef __ANDROID__
#define TORRENT_USE_POSIX_MEMALIGN 0
#define TORRENT_USE_MEMALIGN 1
#define TORRENT_USE_ICONV 0
#define TORRENT_HAS_FALLOCATE 0
#else
#define TORRENT_USE_POSIX_MEMALIGN 1
#endif
#if __amd64__ || __i386__ #if __amd64__ || __i386__
#define TORRENT_USE_EXECINFO 1 #define TORRENT_USE_EXECINFO 1
#endif #endif

22
libtorrent/runme-android.sh

@ -0,0 +1,22 @@
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/
if [ $1 == "configure" ]; then
./configure --host=arm-linux-androideabi --enable-shared=no --enable-static=yes \
--enable-debug \
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
fi
make -j2

4
libtorrent/src/asio_ssl.cpp

@ -1,6 +1,10 @@
// builds all boost.asio SSL source as a separate compilation unit // builds all boost.asio SSL source as a separate compilation unit
#include <boost/version.hpp> #include <boost/version.hpp>
#ifdef __ANDROID__
#define OPENSSL_NO_ENGINE 1
#endif
#if BOOST_VERSION >= 104610 #if BOOST_VERSION >= 104610
#include <boost/asio/ssl/impl/src.hpp> #include <boost/asio/ssl/impl/src.hpp>
#endif #endif

8
libtorrent/src/file.cpp

@ -72,7 +72,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> // for F_LOG2PHYS #include <fcntl.h> // for F_LOG2PHYS
#include <sys/types.h> #include <sys/types.h>
#ifndef __ANDROID__
#include <sys/statvfs.h> #include <sys/statvfs.h>
#else
#define statvfs statfs
#define fstatvfs fstatfs
#include <sys/vfs.h>
#endif
#include <errno.h> #include <errno.h>
#include <dirent.h> #include <dirent.h>
@ -112,12 +118,14 @@ static int my_fallocate(int fd, int mode, loff_t offset, loff_t len)
#undef _FILE_OFFSET_BITS #undef _FILE_OFFSET_BITS
#ifndef __ANDROID__
// make sure the _FILE_OFFSET_BITS define worked // make sure the _FILE_OFFSET_BITS define worked
// on this platform. It's supposed to make file // on this platform. It's supposed to make file
// related functions support 64-bit offsets. // related functions support 64-bit offsets.
// this test makes sure lseek() returns a type // this test makes sure lseek() returns a type
// at least 64 bits wide // at least 64 bits wide
BOOST_STATIC_ASSERT(sizeof(lseek(0, 0, 0)) >= 8); BOOST_STATIC_ASSERT(sizeof(lseek(0, 0, 0)) >= 8);
#endif
#endif // posix part #endif // posix part

5
libtorrent/src/utp_stream.cpp

@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/random.hpp" #include "libtorrent/random.hpp"
#include "libtorrent/invariant_check.hpp" #include "libtorrent/invariant_check.hpp"
#include <boost/cstdint.hpp> #include <boost/cstdint.hpp>
#include <limits>
#define TORRENT_UTP_LOG 0 #define TORRENT_UTP_LOG 0
#define TORRENT_VERBOSE_UTP_LOG 0 #define TORRENT_VERBOSE_UTP_LOG 0
@ -3098,8 +3099,8 @@ void utp_socket_impl::do_ledbat(int acked_bytes, int delay, int in_flight, ptime
} }
// make sure we don't wrap the cwnd // make sure we don't wrap the cwnd
if (scaled_gain >= INT64_MAX - m_cwnd) if (scaled_gain >= std::numeric_limits<boost::int64_t>::max() - m_cwnd)
scaled_gain = INT64_MAX - m_cwnd - 1; scaled_gain = std::numeric_limits<boost::int64_t>::max() - m_cwnd - 1;
if (scaled_gain > 0 && !m_cwnd_full if (scaled_gain > 0 && !m_cwnd_full
&& m_last_cwnd_hit + milliseconds(50) < now) && m_last_cwnd_hit + milliseconds(50) < now)

4
src/bitcoinrpc.cpp

@ -308,10 +308,14 @@ string rfc1123Time()
time_t now; time_t now;
time(&now); time(&now);
struct tm* now_gmt = gmtime(&now); struct tm* now_gmt = gmtime(&now);
#ifndef __ANDROID__
string locale(setlocale(LC_TIME, NULL)); string locale(setlocale(LC_TIME, NULL));
setlocale(LC_TIME, "C"); // we want POSIX (aka "C") weekday/month strings setlocale(LC_TIME, "C"); // we want POSIX (aka "C") weekday/month strings
#endif
strftime(buffer, sizeof(buffer), "%a, %d %b %Y %H:%M:%S +0000", now_gmt); strftime(buffer, sizeof(buffer), "%a, %d %b %Y %H:%M:%S +0000", now_gmt);
#ifndef __ANDROID__
setlocale(LC_TIME, locale.c_str()); setlocale(LC_TIME, locale.c_str());
#endif
return string(buffer); return string(buffer);
} }

2
src/compat.h

@ -23,8 +23,10 @@
#include <netdb.h> #include <netdb.h>
#include <net/if.h> #include <net/if.h>
#include <netinet/in.h> #include <netinet/in.h>
#ifndef __ANDROID__
#include <ifaddrs.h> #include <ifaddrs.h>
#endif #endif
#endif
typedef u_int SOCKET; typedef u_int SOCKET;
#ifdef WIN32 #ifdef WIN32

227
src/makefile.android

@ -0,0 +1,227 @@
# 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 -DBOOST_THREAD_USE_LIB
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 = dynamic
ifdef STATIC
LMODE = static
ifeq (${STATIC}, all)
LMODE2 = static
endif
else
TESTDEFS += -DBOOST_TEST_DYN_LINK
endif
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
# 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
# for boost 1.37, add -mt to the boost libraries
LIBS += \
-Wl,-B$(LMODE) \
-Wl,-rpath-link=$(SYSROOT)/usr/lib/ -L$(SYSROOT)/usr/lib/ \
-L$(BOOSTDIR)/lib \
-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$(NDK_BASE)/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/ -lgnustl_static
#-l ssl_static -l crypto_static
LIBS+= \
-Wl,-B$(LMODE2) \
-Wl,-rpath-link=$(SYSROOT)/usr/lib/ -L$(SYSROOT)/usr/lib/ \
-lssl -lcrypto -lstdc++ -lm -lgcc -nostdlib -lc \
$(NDK_BASE)/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o \
$(NDK_BASE)/platforms/android-9/arch-arm/usr/lib/crtend_android.o
# 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)
arm-linux-androideabi-strip -g $@
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:

256
src/net.cpp

@ -1637,6 +1637,262 @@ bool BindListenPort(const CService &addrBind, string& strError)
return true; return true;
} }
#ifdef __ANDROID__
#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* ifa_next;
char* ifa_name;
unsigned int ifa_flags;
struct sockaddr* ifa_addr;
struct sockaddr* ifa_netmask;
// Real ifaddrs has broadcast, point to point and data members.
// We don't need them (yet?).
};
int getifaddrs(struct ifaddrs** result);
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.
*/
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/utsname.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <unistd.h>
#include <errno.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
struct netlinkrequest {
nlmsghdr header;
ifaddrmsg msg;
};
namespace {
const int kMaxReadSize = 4096;
};
int set_ifname(struct ifaddrs* ifaddr, int interface) {
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;
}
int set_flags(struct ifaddrs* ifaddr) {
int fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd == -1) {
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;
}
int set_addresses(struct ifaddrs* ifaddr, ifaddrmsg* msg, void* data,
size_t len) {
if (msg->ifa_family == AF_INET) {
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;
}
prefix = reinterpret_cast<char*>(&mask->sin_addr);
} 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;
}
int populate_ifaddrs(struct ifaddrs* ifaddr, ifaddrmsg* msg, void* bytes,
size_t len) {
if (set_ifname(ifaddr, msg->ifa_index) != 0) {
return -1;
}
if (set_flags(ifaddr) != 0) {
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;
}
int getifaddrs(struct ifaddrs** result) {
int fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (fd < 0) {
return -1;
}
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;
}
}
}
amount_read = recv(fd, &buf, kMaxReadSize, 0);
}
close(fd);
freeifaddrs(start);
return -1;
}
void freeifaddrs(struct ifaddrs* addrs) {
struct ifaddrs* last = NULL;
struct ifaddrs* cursor = addrs;
while (cursor) {
delete[] cursor->ifa_name;
delete cursor->ifa_addr;
delete cursor->ifa_netmask;
last = cursor;
cursor = cursor->ifa_next;
delete last;
}
}
#endif
void static Discover() void static Discover()
{ {
if (!fDiscover) if (!fDiscover)

2
src/netbase.cpp

@ -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()

29
src/runme-android.sh

@ -0,0 +1,29 @@
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 -nostdlib"
export BOOST_LIB_SUFFIX=-gcc-mt-1_49
export BDB_LIB_SUFFIX=-4.8
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

6
src/util.cpp

@ -1041,8 +1041,12 @@ boost::filesystem::path GetDefaultDataDir()
fs::create_directory(pathRet); fs::create_directory(pathRet);
return pathRet / "Twister"; return pathRet / "Twister";
#else #else
#ifdef __ANDROID__
return "/sdcard/twister";
#else
// Unix // Unix
return pathRet / ".twister"; return pathRet / ".twister";
#endif
#endif #endif
#endif #endif
} }
@ -1221,7 +1225,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…
Cancel
Save