I'm trying to use redir in NodeJs using node-ffi.
Here's my redir.js
:
const ref = require('ref');
const ffi = require('ffi');
const Struct = require('ref-struct');
const struct_in_addr = Struct({
's_addr': 'unsigned long',
});
const struct_sockaddr_in = Struct({
'sin_family': 'short',
'sin_port' : 'u_short',
'in_addr' : struct_in_addr,
'sin_zero' : 'char',
});
var redir = ffi.Library('./redir', {
'target_init' : [ 'int', [ 'char *', 'int', [ struct_sockaddr_in, "pointer" ]] ],
'target_connect': [ 'int', [ 'int', [ struct_sockaddr_in, "pointer" ] ] ],
'client_accept' : [ 'int', [ 'int', [ struct_sockaddr_in, "pointer" ] ] ],
'server_socket' : [ 'int', [ 'char *', 'int', 'int' ] ],
});
I compiled by doing ./autogen.sh && ./configure && ./make
and generate redir
executable. I had to rename it to redir.so
because node-ffi keeps putting .so
in the end of the file
Here's what I get when I do node redir.js
:
Error: Dynamic Symbol Retrieval Error: ./redir.so: undefined symbol: target_init
at DynamicLibrary.get (/home/lz/redir-controller/node_modules/ffi/lib/dynamic_library.js:112:11)
It cannot locate the target_init
function. I believe I did everything alright. Could it be a function signature error (I'm using the wrong types) or it menas that there is really no function with the name target_init
?
UPDATE:
I tried to compile it specifically into a shared library:
gcc -shared -fpic redir.c -o libredir.so
but the problem of not finding target_init
persists
解决方案:从函数中删除static
关键字:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.