Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to find correct pointers for struct and optlen #9

Open
toonvd opened this issue Dec 19, 2020 · 0 comments
Open

Unable to find correct pointers for struct and optlen #9

toonvd opened this issue Dec 19, 2020 · 0 comments

Comments

@toonvd
Copy link

toonvd commented Dec 19, 2020

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant