Skip to content

Unable to find correct pointers for struct and optlen #9

@toonvd

Description

@toonvd

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions