sbffi icon indicating copy to clipboard operation
sbffi copied to clipboard

Unable to find correct pointers for struct and optlen

Open toonvd opened this issue 4 years ago • 0 comments

Hi

I am trying to get socketOptions for my unix socket, but I cannot seem to pinpoint the correct pointers to use. I keep getting the following error: Cannot mix BigInt and other types, use explicit conversions. Can you give me any hints on how to proceed?

const { getNativeFunction } = require('./sbffi/lib/index.js');
var ref = require('ref-napi')
var StructType = require('ref-struct-di')(ref);

const Credentials = StructType({
    pid: 'int',
    uid: 'int',
    gid: 'int'
});

const SOL_SOCKET = 1;
const SO_PEERCRED = 17;
const clen = ref.alloc('int', 4 * 3);

const cred = new Credentials();
const getsockopt = getNativeFunction(null, 'getsockopt', 'int', ['int', 'int', 'int', 'void *', 'int *']);
// int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
exports.getUserInfo = socket => {
    var returnValue = getsockopt(socket._handle.fd, SOL_SOCKET, SO_PEERCRED, cred.ref(), clen);
    console.log(returnValue)
    return cred;
}

toonvd avatar Dec 19 '20 00:12 toonvd