pellegre / libcrafter

A high level C++ network packet sniffing and crafting library.
298 stars 88 forks source link

Code now compiles for Android NDK #34

Closed oliviertilmans closed 9 years ago

oliviertilmans commented 9 years ago

Support compiling for platform rev. 15 Requires a few more files for a complete build:

Changes are mainly due to

Please check that it still compiles on your machine, as I had to add some includes which should normally be present everywhere ...

pellegre commented 9 years ago

very nice, thanks for this :-) how are you dealing with the ns_* functions? last time I tried to compile for android I had to add those files to the library (from the C library)

oliviertilmans commented 9 years ago

I'm building libbind (which is incorporated to glibc) using the exported ndk toolchain. Here's an excerpt from the build script for tracebox on Android (hopefully I'll finish that this week):

mkdir -p usr/include/sys
echo "#include <sys/types.h>" > usr/include/sys/bitypes.h
export CFLAGS="$CFLAGS -I$BASE_DIR/usr/include"
export CXXFLAGS="$CXXFLAGS -I$BASE_DIR/usr/include"

BIND=libbind
FBIND=$BIND-$BIND_VER.tar.gz
BIND_URL=http://ftp.isc.org/isc/libbind/$BIND_VER/$FBIND
BIND_build() {
    echo "Building $BIND"

    STD_CDEFINES="-DS_IREAD=S_IRUSR -DS_IWRITE=S_IWUSR -DS_IEXEC=S_IXUSR" \
        ./configure \
        --host=arm-linux \
        --disable-shared \
        --prefix=$PWD \
        --with-randomdev=/dev/random
    make
    make install
}
export CFLAGS="$CFLAGS -I$BASE_DIR/$BIND-$BIND_VER/include"
export CXXFLAGS="$CXXFLAGS -I$BASE_DIR/$BIND-$BIND_VER/include"
export LDFLAGS="$LDFLAGS -L$BASE_DIR/$BIND-$BIND_VER/lib"

That way all the ns_* functions are there and I just link against it. It is not required if you target platform rev. >= 21 (lollipop).

oliviertilmans commented 9 years ago

Actually it also requires to link against https://github.com/kmackay/android-ifaddrs which implements the getifaddrs call.