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

[C#] sys.net.Host tries to resolve IPAddress.Any (0.0.0.0), throws up a C# exception #6605

Closed
YellowAfterlife opened this issue Sep 23, 2017 · 0 comments · Fixed by #11551
Closed
Milestone

Comments

@YellowAfterlife
Copy link
Contributor

class Main {
	static function main() {
		var sv = new sys.net.Socket();
		sv.bind(new sys.net.Host("0.0.0.0"), 5100);
		sv.listen(3);
	}
}

Result:

System.ArgumentException: IPv4 address 0.0.0.0 and IPv6 address ::0 are unspecified addresses that cannot be used as a target address.
Parameter name: hostNameOrAddress
   at System.Net.Dns.GetHostEntry(String hostNameOrAddress)
   at sys.net.Host.__hx_ctor_sys_net_Host(Host __hx_this, String name)
   at Main.main()

IPAddress.Any is used for auto-selecting the address to bind sockets to, so is semi-important for that.

I workarounded this locally by adding a special case to sys.net.Host.new,

	public function new( name : String ) : Void {
		host = name;
		if (name == "0.0.0.0" || name == "::0") {
			ipAddress = IPAddress.Any;
			return;
		}
		// ...
	}

but that doesn't fill out hostEntry and doesn't look like an elegant solution.

@Simn Simn added this to the Bugs milestone Apr 17, 2018
@Simn Simn modified the milestones: Bugs, Later Mar 24, 2023
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

Successfully merging a pull request may close this issue.

2 participants