Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

fixing a few errors and UBs #80

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 1 addition & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,45 +191,7 @@ Depending on what version you target, you may have to change two defines to not

Android
-----------------------------------------

You will need the latest CYWGIN and the android SDK to build native code on the android. Under CYWGIN, you will need to run ndk-build on a directory for RakNet.

1. Under cygwin, create the RakNet directory somewhere, such as under samples.
For example, if you create the path `\cygwin\home\Kevin\android-ndk-r4b\samples\RakNet`

2. I copied the Android.Manifest.xml and other files from another sample

3. Under jni, you will need the following Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := RakNet
MY_PREFIX := $(LOCAL_PATH)/RakNetSources/
MY_SOURCES := $(wildcard $(MY_PREFIX)*.cpp)
LOCAL_SRC_FILES += $(MY_SOURCES:$(MY_PREFIX)%=RakNetSources/%)
include $(BUILD_SHARED_LIBRARY)

This version of Android.mk assumes there is a directory called RakNetSources, for example
`cygwin/home/Kevin/android-ndk-r4b/samples/RakNet/jni/RakNetSources`

Under RakNetSources should be the /Source directory to RakNet. Rather than copy the files I used junction.exe
http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx

The command I used to create the junction was:

D:/cygwin/home/Kevin/android-ndk-r4b/samples/RakNet/jni/junction.exe -s D:/cygwin/home/Kevin/android-ndk-r4b/samples/RakNet/jni/RakNetSources D:/RakNet4/Source

To unjunction I used:

D:/cygwin/home/Kevin/android-ndk-r4b/samples/RakNet/jni/junction.exe -d D:/cygwin/home/Kevin/android-ndk-r4b/samples/RakNet/jni/RakNetSources

From within the CYWGIN enviroment, navigate to home/Kevin/android-ndk-r4b/samples/RakNet. Then type

../../ndk-build

Everything should build and you should end up with a .so file.

You should then be able to create a project in eclipse, and import cygwin/home/Kevin/android-ndk-r4b/samples/RakNet
Android project with build instructionsis is located in RakNet_Android_NDK folder.

Native client
-----------------------------------------
Expand Down
31 changes: 31 additions & 0 deletions RakNet_Android_NDK/README.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Android project for Oculus RakNet library.
Initial project version: Viktor Korsun, bitekas@gmail.com

Copyright (c) 2015, Oculus VR, Inc.
All rights reserved.

This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory.
---------------------------------------------------------------------------

To build Android native libraries run "ndk-build" from THIS directory, or
merge the content with your project.

Windows build command example:
D:\Soft\android-ndk-r10e-64\bin\ndk-build

Linux/OS X build command example:
$ ~/soft/android-ndk-r10e-32/ndk-build

This will produce "libs" folder with shared libraries for platforms:
armeabi
armeabi-v7a
x86

The project uses android-9 API, that covers almost 100% of Android devices
by the end of 2015. To raise API (and possibly build additional ABIs)
please edit jni/Application.mk.

The project has been tested with Android NDK 10e both 32- and 64- bit
versions.
8 changes: 8 additions & 0 deletions RakNet_Android_NDK/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libraknet

FILE_LIST := $(wildcard $(LOCAL_PATH)/../../Source/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

include $(BUILD_SHARED_LIBRARY)
3 changes: 3 additions & 0 deletions RakNet_Android_NDK/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APP_STL := c++_static
APP_ABI := armeabi armeabi-v7a x86
APP_PLATFORM := android-9
4 changes: 2 additions & 2 deletions Source/PacketizedTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ bool PacketizedTCP::SendList( const char **data, const unsigned int *lengths, co
#endif


unsigned int lengthsArray[512];
const char *dataArray[512];
unsigned int lengthsArray[513];
const char *dataArray[513];
dataArray[0]=(char*) &dataLength;
lengthsArray[0]=sizeof(dataLength);
for (int i=0; i < 512 && i < numParameters; i++)
Expand Down
3 changes: 3 additions & 0 deletions Source/RakString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ RakString::RakString(const unsigned char *format, ...){
va_list ap;
va_start(ap, format);
Assign((const char*) format,ap);
va_end(ap);
}
RakString::RakString(const char *format, ...){
va_list ap;
va_start(ap, format);
Assign(format,ap);
va_end(ap);
}
RakString::RakString( const RakString & rhs)
{
Expand Down Expand Up @@ -377,6 +379,7 @@ void RakString::Set(const char *format, ...)
va_start(ap, format);
Clear();
Assign(format,ap);
va_end(ap);
}
bool RakString::IsEmpty(void) const
{
Expand Down
5 changes: 3 additions & 2 deletions Source/SocketLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ RakNet::RakString SocketLayer::GetSubNetForSocketAndIp(__UDPSOCKET__ inSock, Rak
ifc.ifc_buf = buf;
if(ioctl(fd2, SIOCGIFCONF, &ifc) < 0)
{
return "";
close(fd2);
return "";
}

struct ifreq *ifr;
Expand Down Expand Up @@ -594,7 +595,7 @@ bool SocketLayer::GetFirstBindableIP(char firstBindable[128], int ipProto)
break;
}

if (ipList[l]==UNASSIGNED_SYSTEM_ADDRESS || l==MAXIMUM_NUMBER_OF_INTERNAL_IDS)
if (l==MAXIMUM_NUMBER_OF_INTERNAL_IDS || ipList[l]==UNASSIGNED_SYSTEM_ADDRESS)
return false;
// RAKNET_DEBUG_PRINTF("%i %i %i %i\n",
// ((char*)(&ipList[l].address.addr4.sin_addr.s_addr))[0],
Expand Down