Open markwylde opened 4 years ago
Although I wrote this package, I'm not familiar with all aspects of socket/network programming, and I have forgotten most of it again. 🙈
Given that the Go syscall.GetsockoptIPv6Mreq
API takes 3 arguments fd
, level
& opt
, I assume that you need to pass IPPROTO_IP
to getsockopt
as well (instead of SOL_SOCKET
). Can you try that?
No worries @derhuerst . I'm in the same boat and your library has already helped me so much. I'll keep playing around and post if I work out a solution.
Have you tried passing IPPROTO_IP
as the 2nd argument?
Yeah I've even tried removing the types from node and hardcoding everything, just incase it was a type issue:
Napi::Value Getsockopt(const Napi::CallbackInfo& args) {
Napi::Env env = args.Env();
if (!args[0].IsNumber()) {
Napi::TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
return env.Null();
}
int socket = args[0].As<Napi::Number>().Int32Value();
struct sockaddr_in *destaddr;
socklen_t socklen = sizeof(*destaddr);
if (0 != getsockopt(socket, IPPROTO_IP, SO_ORIGINAL_DST, destaddr, &socklen)) {
char * msg = (char *) malloc(sizeof(char) * 100);
sprintf(msg, "getsockopt failed: %s (%d)", strerror(errno), errno);
// todo: expose `errno`
Napi::TypeError::New(env, msg).ThrowAsJavaScriptException();
return env.Null();
}
return Napi::Number::New(env, 1);
}
At least I'm getting a different error :S
getsockopt failed: (-1) Bad address (14)
At this point I'm out of ideas, sorry. Can you check if it works in plain C/C++, in order to check if it's due to node-sockopt
or due to your general setup?
Me too @derhuerst . Thanks for helping. Linux is hard :(
I'm going to close this issue for now. Please reopen if you have more questions related to this topic, or if there's a bug in node-sockopt
.
I've just come across this bug in a CI run: https://github.com/derhuerst/node-sockopt/runs/6378445051?check_suite_focus=true#step:6:12
Not sure what to do though.
I'm trying to use this in linux ubuntu to get the SO_ORIGINAL_DST from a tcp socket that is redirect via iptables.
Looking at some working golang code:
It would appear that IPPROTO_IP = 0 and SO_ORIGINAL_DST = 80.
I would have expected (although I'm sure I'm completely missing something) the following code to work:
But it returns:
It looks like my combination of 1 and 80 is either incorrect, or I'm using this completely wrong.
Next I ran a couple of loops to try every possibility I could think of. But I can't see 80 working for any level + flagName combination.
Could you please point me in the right direction?