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

bind EINVAL on valid IPv6 Address (IPv4 works fine!) #37870

Closed
yoyo00xx opened this issue Mar 23, 2021 · 2 comments
Closed

bind EINVAL on valid IPv6 Address (IPv4 works fine!) #37870

yoyo00xx opened this issue Mar 23, 2021 · 2 comments

Comments

@yoyo00xx
Copy link

yoyo00xx commented Mar 23, 2021

What steps will reproduce the bug?

  1. Use the https library and bind an IPv6 localaddress

How often does it reproduce? Is there a required condition?

Can be reproduced with the usage of any IPv6 address in the interface

What is the expected behavior?

I am supposed to be able to make the request without any problems just like when binding an IPv4

What do you see instead?

bind EINVAL error

Additional information

I have tested with multiple IPv4 addresses in the interface and they all worked but non of the IPv6 are working

This is the code:

`const https = require('https');
(async () => {
const options = {
//Not real site
hostname: 'example.com',
path: '/test',
localAddress:'Ipv6 address'
}
https.get(options,(res) => {
let body = "";

    res.on("data", (chunk) => {
        body += chunk;
    });

    res.on("end", () => {
        try {
            let json = JSON.parse(body);
            console.log(json)
            // do something with JSON
        } catch (error) {
            console.error(error.message);
        };
    });

}).on("error", (error) => {
    console.error(error.message);
});

})();`

@yoyo00xx
Copy link
Author

I know exactly what is the issue. nodejs https library is not smart enough to know that it is dealing with IPv6. I tried to make a udp4 socket by providing an IPv6 address and got the same error above, when I used udp6 it created it fine and binded.

So suggestion: Introduce explicit parameters to say an address is ipv6 OR make it smarter to determine if the address is IPv6

@yoyo00xx
Copy link
Author

OK for future people needing to fix this issue.

Provide this option in the http/https "family: 6"

Example:

const options = { hostname: 'example.com', family: 6, //<- This is the option headers: { 'Your headers here' }, localAddress:"Your IPv6 Address here }

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