The default dynamic port range for TCP/IP has changed in Windows Vista Enterprise
http://support.microsoft.com/kb/929851/en-usTo conform with IANA port-assignment standards, the default dynamic port range for TCP/IP has changed from 1024-5000 to 49152-65535 in Windows Vista Enterprise.
#include <stdio.h>
#include <winsock2.h>
void main()
{
WSADATA tWSAData;
WSAStartup(MAKEWORD(2, 2), &tWSAData);
sockaddr_in name;
name.sin_family = AF_INET;
name.sin_port = htons(5001);
name.sin_addr.s_addr = INADDR_ANY;
int namelen = sizeof(SOCKADDR);
SOCKET s = socket(AF_INET, SOCK_STREAM, 0);
bind(s, (SOCKADDR*)&name, namelen);
listen(s, 1);
for(;;)
{
sockaddr_in name;
name.sin_family = AF_INET;
name.sin_port = htons(5001);
name.sin_addr.s_addr = inet_addr("127.0.0.1");
int namelen = sizeof(SOCKADDR);
if(connect(socket(AF_INET, SOCK_STREAM, 0), (SOCKADDR*)&name, namelen) == SOCKET_ERROR)
{
break;
}
accept(s, (SOCKADDR*)&name, &namelen);
printf("%d\n", ntohs(name.sin_port));
}
printf("->%d\n", WSAGetLastError());
}
ip-sysctl.txt
Defines the local port range that is used by TCP and UDP to
choose the local port. The first number is the first, the
second the last local port number. Default value depends on
amount of memory available on the system:
> 128Mb 32768-61000
< 128Mb 1024-4999 or even less.
This number defines number of active connections, which this
system can issue simultaneously to systems not supporting
TCP extensions (timestamps). With tcp_tw_recycle enabled
(i.e. by default) range 1024-4999 is enough to issue up to
2000 connections per second to systems supporting timestamps.
man 7 ip
ip_local_port_range
Contains two integers that define the default local port range allocated to sockets. Allocation starts with the first number and ends with the second number. Note that these should not conflict with the ports used by masquerading (although the case is handled). Also arbitrary choices may cause problems with some firewall packet filters that make assumptions about the local ports in use. First number should be at least >1024, better >4096 to avoid clashes with well known ports and to minimize firewall problems.