Jump to content
  • Advertisement
Sign in to follow this  
supagu

fail to bind socket under vista

This topic is 4133 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

okay got some enet code that works fine under XP, but fails under vista:
if (address != NULL)
    {
       sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
       sin.sin_addr.s_addr = address -> host;
    }
    else
    {
       sin.sin_port = 0;
       sin.sin_addr.s_addr = INADDR_ANY;
    }

	bindResult = bind(newSocket, (const struct sockaddr*)&sin, sizeof(struct sockaddr_in));
    if (bindResult == SOCKET_ERROR 
		|| (type == ENET_SOCKET_TYPE_STREAM && address != NULL && listen(newSocket, SOMAXCONN) == SOCKET_ERROR))
    {
       closesocket (newSocket);
       return ENET_SOCKET_NULL;
    }

if (address != NULL), causes bind to fail, the else statement works, but i want to bind to a specific port. one intresting point if i change the port in address -> port before the if statement using the debugger, then the bind works. Bizarre. Any ideas if this is a Vista bug?

Share this post


Link to post
Share on other sites
Advertisement
I haven't upgraded to Vista yet, so here are my guesses:

Under UNIX, your process will need to have root privileges to bind to port less than 1024 or 2048. This is so that the system administrator can control who serves specific services, such as mail, web, etc. Perhaps Vista introduces the same requirement for Windows.

Note that, in Vista, even if your local user has administrator privileges, your program has to actually ask for privilege elevation to do some privileged things; this is done to reduce the amount of damage a malicious program can do.

The reason binding to zero works is that the stack can choose any port for this bind, and thus chooses a port outside of the privileged range.

Another option is that there is actually a service of some sort running at the port you chose, under Vista. Have you checked with "netstat"?

Last, I don't see you memset() the address to 0 (to clear out the sin_zero), and the fill in the sin_family field, though -- make sure you fill those out correctly.

Share this post


Link to post
Share on other sites
Consider using something like perror() to get a more useful error message after bind fails. It probably is the port restriction.

Share this post


Link to post
Share on other sites
More detail would be useful. Have you tried with a higher port number? And have you got the exact error message back from perror? What sort of program is this and do you have a restriction on the listening port you need to use? There are certain things that Vista will simply not let you do unless you have admin rights, the same way that Linux and other operating systems do, and one of those things is listen on reserved ports.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!