Skip to content

Add IPv6/Dual Stack#816

Open
12brendon34 wants to merge 4 commits intosmartcmd:mainfrom
12brendon34:Dual-Stack-IPv6-Support
Open

Add IPv6/Dual Stack#816
12brendon34 wants to merge 4 commits intosmartcmd:mainfrom
12brendon34:Dual-Stack-IPv6-Support

Conversation

@12brendon34
Copy link

@12brendon34 12brendon34 commented Mar 7, 2026

Description

Modifies WinsockNetLayer.cpp to use Dual stack/IPv6 support
fix small flaw in SetupHeadlessServerConsole()

Changes

Add a little helper WinsockNetLayer::IsNumericAddress,
Modify HostGame, AcceptThreadProc

SetupHeadlessServerConsole() now attempts AttachConsole(ATTACH_PARENT_PROCESS) first

Previous Behavior

IPv6 support just didn't exist

Root Cause

It's old

New Behavior

It now uses the IPv6 flags and IP parsing logic

Fix Implementation

bool WinsockNetLayer::HostGame(int port, const char* bindIp)
{
...
	hints.ai_family = AF_UNSPEC;
...
	if (resolvedBindIp == NULL)
		hints.ai_flags = AI_PASSIVE;
	else if (IsNumericAddress(resolvedBindIp))
		hints.ai_flags = AI_NUMERICHOST;
	else
		hints.ai_flags = 0;
...
	DWORD ipv6only = 0;
	setsockopt(s_listenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&ipv6only, sizeof(ipv6only));
...
}

bool WinsockNetLayer::JoinGame(const char* ip, int port)
{
...
	if (IsNumericAddress(ip))
		hints.ai_flags = AI_NUMERICHOST;
	else
		hints.ai_flags = 0;

	hints.ai_family = AF_UNSPEC;
...
}


bool WinsockNetLayer::IsNumericAddress(const char* addr)
{
	if (addr == NULL)
		return false;

	if (strchr(addr, ':') != NULL)
		return true;// IPv6

	if (inet_addr(addr) != INADDR_NONE)
		return true;// IPv4

	return false;// hostname
}

AI Use Disclosure

No AI was used for this

@void2012
Copy link
Collaborator

void2012 commented Mar 7, 2026

Related to #498 ?

@12brendon34
Copy link
Author

12brendon34 commented Mar 7, 2026

Related to #498 ?

I would say so

@void2012
Copy link
Collaborator

void2012 commented Mar 7, 2026

Consider collaborating with that PR author

@12brendon34
Copy link
Author

12brendon34 commented Mar 7, 2026

Consider collaborating with that PR author

I think I broke IPv4 slightly, need to figure that out first.
maybe not, I just tested on a diff server and it connected fine

@kuwacom
Copy link
Contributor

kuwacom commented Mar 7, 2026

Consider collaborating with that PR author

Basically, the separated dedicated server works by calling functionality from the Minecraft.Client side, so once these features are merged into main, they will automatically apply here as well.

@void2012
Copy link
Collaborator

void2012 commented Mar 7, 2026

Okay. Ask someone to test your PR

@12brendon34
Copy link
Author

Okay. Ask someone to test your PR

I'll see if I can get someone to test tmr, it's 3:04 AM right now for me.

@12brendon34
Copy link
Author

12brendon34 commented Mar 7, 2026

I just realized I think I accidentally reverted some of #722, no clue how I messed that up.
I'll fix that real quick

@12brendon34 12brendon34 force-pushed the Dual-Stack-IPv6-Support branch 3 times, most recently from ba3ab32 to b867c27 Compare March 7, 2026 22:46
@12brendon34
Copy link
Author

I've amended it now, I'll see if I can get some friends to test it a bit later.

@12brendon34
Copy link
Author

12brendon34 commented Mar 8, 2026

I've tested it with one of my friends, it does seem to work quite well.
I'll fix the conflicts tmr and if anyone else wants to test it, feel free to.

Also Fix SetupHeadlessServerConsole() to use an existing console if possible.
@12brendon34 12brendon34 force-pushed the Dual-Stack-IPv6-Support branch from b867c27 to 3dc133a Compare March 8, 2026 10:46
@12brendon34 12brendon34 changed the title Add IPv6/Dual Stack + read servers.dat Add IPv6/Dual Stack Mar 9, 2026
@12brendon34
Copy link
Author

I think this is suitable to be merged now.
I've done all the testing I can on my setup.

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 this pull request may close these issues.

3 participants