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

Represent and manipulate IP addresses without providing a port (Socket::IPAddress without a port) #10428

Open
j8r opened this issue Feb 20, 2021 · 5 comments

Comments

@j8r
Copy link
Contributor

j8r commented Feb 20, 2021

Sometimes we just want to represent an IP address (#10408 reminded me of this issue). This has already caught me in the past to have to put a 0 in a place we just want to represent an IP, where we just want to calculate masks for instance.

Examples of other places which has such type:

@j8r
Copy link
Contributor Author

j8r commented Feb 20, 2021

Go also has TCPAddr and UDPAddr types, which have a port field.

@straight-shoota
Copy link
Member

Sure, that could be useful sometimes. But IMO it would not be worth it adding another type, when you can just use Socket::IPAddress with port 0 for example (and ignore port if you only care about the address).

The naming can obviously be confusing. The type is called IPAddress but actually, it consists of the combination of address and port number. This could probably more correctly be called "port", but that would be confusing for similar reasons.

For all practical purposes, I think we're fine with the current situation. It's not ideal, but there's no strictly better solution. And I don't imagine adding another type would be useful for stdlib.

@straight-shoota
Copy link
Member

When listing other implementations of such a type, you should also mention if there's also a separate type for the combination with a port number like in Go. If not, our IPAddress is just like the other languages' type, just with the possibility to also specify a port number.

@j8r
Copy link
Contributor Author

j8r commented Feb 20, 2021

Rust has SocketAddr. C# has IPEndPoint. I don't see anything in Ruby, except Socket.

@j8r
Copy link
Contributor Author

j8r commented Feb 20, 2021

Yes, indeed calling the object IPAdress is confusing. It doesn't fit its definition
.

I think it would make perfect sense to have a SocketAddress, with a IPAddress and a port field.

The 0 port is a trick, "a la null pointer". At least, the port should be nillable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants