Hi
In our application, we are calling bind function with port number 0
(system to allocate the port number). On one of our VISTA machines, it
is failing with error code 10013 (WSAEACCESS). To create this
problem, I had written a standalone program which simply creates the
sockets and binds those sockets to different system assigned ports. If
i run this program multiple times (during every execution, it creates
4000 sockets and binds to different ports), system is failing to
allocate the ports after some execution (to continue further, i am
forced to reboot that machine). I am properly closing the created
sockets at the end of the program. I could not get the reason for the
failure (error code:10013). The same program is running properly on
different VISTA machine. I need your help to understand and to
resolve this problem.

Program:
// winsk.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include
#include "winsock2.h"

void main() {
//----------------------
// Initialize Winsock
WSADATA wsaData;
int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != NO_ERROR)
printf("Error at WSAStartup()\n");

char hname[MAXGETHOSTSTRUCT];
struct hostent *haddr;

gethostname(hname, MAXGETHOSTSTRUCT);
hname[MAXGETHOSTSTRUCT-1]='\0';
haddr=gethostbyname(hname);

SOCKET ListenSocket[4000], TMP;
int i;
for (i=0;i<4000;i++) {
struct sockaddr_in service;

ListenSocket[i] = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (ListenSocket[i] == INVALID_SOCKET) {
printf("Error at socket(): %ld\n", WSAGetLastError());
WSACleanup();
return;
}

memset(&service,0,sizeof(service));
service.sin_family = AF_INET;
service.sin_addr.s_addr = htonl(INADDR_ANY); //
inet_addr("127.0.0.1");

// Bind the socket.
if (bind( ListenSocket[i],(SOCKADDR*) &service,sizeof(service)) ==
SOCKET_ERROR) {
printf("bind() failed. %ld\n", WSAGetLastError());
getchar();
for (int j=0;j if(closesocket(ListenSocket[j])) {
fprintf(stderr, "close socket:%d\n", WSAGetLastError());
getchar();
}
}
return;
} else {
int siz=sizeof(service);
memset(&service,0,sizeof(service));
getsockname(ListenSocket[i], (SOCKADDR*) &service, &siz);
fprintf(stderr, "%d Listen socket is done, port:%ld\n", i,
service.sin_port );
}

} //end of for
getchar();
for (int j=0;j shutdown(ListenSocket[i], 2);
if(closesocket(ListenSocket[j])) {
fprintf(stderr, "close socket:%d\n", WSAGetLastError());
getchar();
}
}
WSACleanup();
return;
}

Thanks
Param