// Test DsAddressToSiteNames API #include #include #include #include #include #include #include #include // #include #include #include #include #define AllocSplMem( _x) LocalAlloc( 0, _x) #define DBGMSG( _x, _y) printf VOID AllocSplSockets( struct hostent *pHostEnt, PSOCKET_ADDRESS *ppSocketAddress, DWORD *nSocketAddresses ) { DWORD i; PSOCKET_ADDRESS pSocket; // Allocate Sockaddr element for each SOCKET_ADDRESS // If we fail partway through, just use partial list for ( i= 0 ; pHostEnt->h_addr_list[i] ; i++) { pSocket = &((*ppSocketAddress)[*nSocketAddresses]); if (!(pSocket->lpSockaddr = (struct sockaddr *) AllocSplMem(sizeof(struct sockaddr_in)))) { break; } ((struct sockaddr_in *) pSocket->lpSockaddr)->sin_family = AF_INET; ((struct sockaddr_in *) pSocket->lpSockaddr)->sin_addr = *(struct in_addr *) pHostEnt->h_addr_list[i]; pSocket->iSockaddrLength = sizeof(struct sockaddr_in); *nSocketAddresses += 1; } } VOID GetSocketAddressesFromMachineName( PSTR pszAnsiMachineName, // Machine PSOCKET_ADDRESS *ppSocketAddress, DWORD *nSocketAddresses ) /*++ Routine Description: This routine builds list of names other than the machine name that can be used to call spooler APIs. --*/ { struct hostent *HostEnt; DWORD iWsaError; if (HostEnt = gethostbyname(pszAnsiMachineName)) { AllocSplSockets(HostEnt, ppSocketAddress, nSocketAddresses); } else { iWsaError = WSAGetLastError(); printf("gethostbyname failed: %d\n", iWsaError); } } __cdecl main (int argc, char *argv[]) { NET_API_STATUS NetStatus; SOCKET_ADDRESS* SocketAddresses; ULONG EntryCount; LPWSTR *SiteNames; LPSTR *SiteNamesA; LPWSTR *SubnetNames; LPSTR *SubnetNamesA; ULONG i; int j; char *end; BOOLEAN Verbose = FALSE; if ( argc < 2 ) { Usage: printf("Usage: %s [-s:] [-v] \n", argv[0] ); return 1; } { WORD wVersionRequested; WSADATA wsaData; int err; // // Initialize winsock. // wVersionRequested = MAKEWORD( 1, 1 ); NetStatus = WSAStartup( wVersionRequested, &wsaData ); if ( NetStatus != 0 ) { printf("NETAPI32.DLL: Cannot initialize winsock %ld.\n", NetStatus ); return NetStatus; } if ( LOBYTE( wsaData.wVersion ) != 1 || HIBYTE( wsaData.wVersion ) != 1 ) { WSACleanup(); printf("NETAPI32.DLL: Wrong winsock version %ld.\n", NetStatus ); return WSANOTINITIALISED; } } // // Build an array of socket addresses // SocketAddresses = (PSOCKET_ADDRESS) AllocSplMem(5000*sizeof(SOCKET_ADDRESS)); EntryCount = 0; for ( j=1; j