Skip to content
Merged
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
Binary file modified lib/linux-32/libjni_socketcan.so
100644 → 100755
Binary file not shown.
Binary file modified lib/linux-64/libjni_socketcan.so
100644 → 100755
Binary file not shown.
Binary file modified lib/linux-arm/libjni_socketcan.so
100644 → 100755
Binary file not shown.
Binary file modified lib/linux-arm64/libjni_socketcan.so
100644 → 100755
Binary file not shown.
53 changes: 10 additions & 43 deletions src/main/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,20 @@ JAVA_DEST=../../../target/jni/classes
JNI_DIR=../../../target/jni/headers
JAR_DEST=../../../target/jni/dist

all: jni_src
mv $(LIB_DEST)/lib$(SONAME).so ../../../lib/linux/$(TARGET)/
JAVAH=$(JAVA_HOME)/bin/javah
JAVAC=$(JAVA_HOME)/bin/javac
JAVA_INCLUDES=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux

init:
### JAVA_HOME
ifndef JAVA_HOME
JAVA_HOME=$(shell readlink -f /usr/bin/javac | sed "s:bin/javac::")
endif
JAVAH=$(JAVA_HOME)/bin/javah
JAVAC=$(JAVA_HOME)/bin/javac
JAVA_INCLUDES=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
CXXFLAGS=-I./include -I$(JNI_DIR) -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -fPIC -Wno-unused-parameter -pedantic -D_REENTRANT -D_GNU_SOURCE $(JAVA_INCLUDES)
LDFLAGS=-Wl,-soname,$(SONAME)
LIB_DEST=../../../target/jni/lib

### TARGET
ifndef TARGET
@echo "TARGET must be specified. These can be: $(TARGET_OPTS)"; exit 2;
else
ifeq ($(TARGET),x86)
CXX=g++
STRIP=strip
CXXFLAGS=-I./include -I$(JNI_DIR) -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -fPIC -Wno-unused-parameter -pedantic -D_REENTRANT -D_GNU_SOURCE $(JAVA_INCLUDES)
LDFLAGS=-Wl,-soname,$(SONAME)
LIB_DEST=../../../target/jni/lib
else ifeq ($(TARGET),armv5_sf)
CXX=g++
STRIP=strip
CXXFLAGS=-I./include -I$(JNI_DIR) -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -fPIC -Wno-unused-parameter -pedantic -D_REENTRANT -D_GNU_SOURCE $(JAVA_INCLUDES)
LDFLAGS=-Wl,-soname,$(SONAME)
LIB_DEST=../../../target/jni/lib
else ifeq ($(TARGET),armv6_hf)
CXX=g++
STRIP=strip
CXXFLAGS=-I./include -I$(JNI_DIR) -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -fPIC -Wno-unused-parameter -pedantic -D_REENTRANT -D_GNU_SOURCE $(JAVA_INCLUDES)
LDFLAGS=-Wl,-soname,$(SONAME)
LIB_DEST=../../../target/jni/lib
else ifeq ($(TARGET),poky)
CXXFLAGS=-I./include -I$(JNI_DIR) -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -fPIC -Wno-unused-parameter -pedantic -D_REENTRANT -D_GNU_SOURCE $(JAVA_INCLUDES)
LDFLAGS=-Wl,-soname,$(SONAME)
LIB_DEST=../../../target/jni/lib
else
@echo "TARGET must be specified. These can be: $(TARGET_OPTS)"; exit 2;
endif
endif
# DIRS to be created for the build
DIRS=$(JAVA_DEST) $(LIB_DEST) $(JAR_DEST)

# DIRS to be created for the build
DIRS=$(JAVA_DEST) $(LIB_DEST) $(JAR_DEST)
all: jni_src

java_src: init
java_src:
### Make directories
mkdir -p $(DIRS)

Expand Down
12 changes: 10 additions & 2 deletions src/main/c/jni/cansocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,28 @@ JNIEXPORT void JNICALL Java_de_entropia_can_CanSocket__1sendFrame
}
}

// kernel 5.4+ recvfrom will return the size of this structure
// as addrlen instead of sizeof(struct sockaddr_can) for CAN_RAW sockets
struct sockaddr_can_min {
__kernel_sa_family_t _unused;
// this is the only field the code is interested in
int can_ifindex;
};

JNIEXPORT jobject JNICALL Java_de_entropia_can_CanSocket__1recvFrame
(JNIEnv *env, jclass obj, jint fd)
{
const int flags = 0;
ssize_t nbytes;
struct sockaddr_can addr;
struct sockaddr_can_min addr;
socklen_t len = sizeof(addr);
struct can_frame frame;

memset(&addr, 0, sizeof(addr));
memset(&frame, 0, sizeof(frame));
nbytes = recvfrom(fd, &frame, sizeof(frame), flags,
reinterpret_cast<struct sockaddr *>(&addr), &len);
if (len != sizeof(addr)) {
if (len < sizeof(addr)) {
throwIllegalArgumentException(env, "illegal AF_CAN address");
return NULL;
}
Expand Down