A
Amir Michail
Hi,
I tried this hack for passing a Java socket fd to C but could not get
it to work:
http://www.geocities.com/SiliconValley/Vista/2013/JavaOOB.html
Here's the code I have:
JNIEXPORT void JNICALL
Java_UnixProcess_closeSockets__Ljava_net_Socket_2
(JNIEnv *env, jclass cls, jobject obj) {
struct Hjava_io_FileDescriptor *fd; /* Java-struct-excavation aids */
struct Hjava_net_SocketImpl *impl;
struct Hjava_net_Socket *socket;
int sockfd;
/* dig deep into "this" to get the UNIX file descriptor */
//socket = unhand(this)->socket;
socket = obj;
impl = unhand(socket)->impl;
fd = unhand(impl)->fd;
sockfd = (int)(unhand(fd)->fd - 1);
/* "The FileDescriptor object integer class variable fd represents
the actual file descriptor plus 1." - Mark Yarvis */
closeSockets(sockfd);
}
I get this error:
UnixProcessImp.c: In function
`Java_UnixProcess_closeSockets__Ljava_net_Socket_2':
UnixProcessImp.c:97: error: invalid type argument of `->'
UnixProcessImp.c:98: error: invalid type argument of `->'
UnixProcessImp.c:99: error: invalid type argument of `->'
which corrrespond to these lines:
impl = unhand(socket)->impl;
fd = unhand(impl)->fd;
sockfd = (int)(unhand(fd)->fd - 1);
Here are the header files generated by javah:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class java_net_Socket */
#ifndef _Included_java_net_Socket
#define _Included_java_net_Socket
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: factory */
#ifdef __cplusplus
}
#endif
#endif
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class java_net_SocketImpl */
#ifndef _Included_java_net_SocketImpl
#define _Included_java_net_SocketImpl
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class java_io_FileDescriptor */
#ifndef _Included_java_io_FileDescriptor
#define _Included_java_io_FileDescriptor
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: in */
/* Inaccessible static: out */
/* Inaccessible static: err */
/*
* Class: java_io_FileDescriptor
* Method: sync
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_java_io_FileDescriptor_sync
(JNIEnv *, jobject);
/*
* Class: java_io_FileDescriptor
* Method: initIDs
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_java_io_FileDescriptor_initIDs
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
Amir
I tried this hack for passing a Java socket fd to C but could not get
it to work:
http://www.geocities.com/SiliconValley/Vista/2013/JavaOOB.html
Here's the code I have:
JNIEXPORT void JNICALL
Java_UnixProcess_closeSockets__Ljava_net_Socket_2
(JNIEnv *env, jclass cls, jobject obj) {
struct Hjava_io_FileDescriptor *fd; /* Java-struct-excavation aids */
struct Hjava_net_SocketImpl *impl;
struct Hjava_net_Socket *socket;
int sockfd;
/* dig deep into "this" to get the UNIX file descriptor */
//socket = unhand(this)->socket;
socket = obj;
impl = unhand(socket)->impl;
fd = unhand(impl)->fd;
sockfd = (int)(unhand(fd)->fd - 1);
/* "The FileDescriptor object integer class variable fd represents
the actual file descriptor plus 1." - Mark Yarvis */
closeSockets(sockfd);
}
I get this error:
UnixProcessImp.c: In function
`Java_UnixProcess_closeSockets__Ljava_net_Socket_2':
UnixProcessImp.c:97: error: invalid type argument of `->'
UnixProcessImp.c:98: error: invalid type argument of `->'
UnixProcessImp.c:99: error: invalid type argument of `->'
which corrrespond to these lines:
impl = unhand(socket)->impl;
fd = unhand(impl)->fd;
sockfd = (int)(unhand(fd)->fd - 1);
Here are the header files generated by javah:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class java_net_Socket */
#ifndef _Included_java_net_Socket
#define _Included_java_net_Socket
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: factory */
#ifdef __cplusplus
}
#endif
#endif
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class java_net_SocketImpl */
#ifndef _Included_java_net_SocketImpl
#define _Included_java_net_SocketImpl
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class java_io_FileDescriptor */
#ifndef _Included_java_io_FileDescriptor
#define _Included_java_io_FileDescriptor
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: in */
/* Inaccessible static: out */
/* Inaccessible static: err */
/*
* Class: java_io_FileDescriptor
* Method: sync
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_java_io_FileDescriptor_sync
(JNIEnv *, jobject);
/*
* Class: java_io_FileDescriptor
* Method: initIDs
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_java_io_FileDescriptor_initIDs
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
Amir