@msdn=http://search.microsoft.com/search/results.aspx?qu=$$$ @pinvoke=http://pinvoke.net/$$$.htm Summary: The DsAddressToSiteNames function obtains the site names corresponding to the specified addresses. !!!!C# Signature: [DllImport("netapi32.dll", CharSet=CharSet.Auto)] public static extern int DsAddressToSiteNames(string computerName, int entryCount, SOCKET_ADDRESS[] socketAddresses, ref IntPtr siteNames); !!!!VB Signature: Declare Function DsAddressToSiteNames Lib "netapi32.dll" (TODO) As TODO !!!!Parameters: *computerName: String that specifies the name of the remote server to process this function. This parameter must be the name of a domain controller. A non-domain controller can call this function by calling [DsGetDcName] to find the domain controller. *entryCount: The number of elements in the socketAddresses array. *socketAddresses: An array of [SOCKET_ADDRESS] structures that contain the addresses to convert. Each address in this array must be of the type AF_INET. EntryCount contains the number of elements in this array. *siteNames: An array of null-terminated string pointers that contain the site names for the addresses. Each element in this array corresponds to the same element in the socketAddresses array. An element is NULL if the corresponding address does not map to any known site or if the address entry is not of the proper form. The caller must free this array when it is no longer required by calling NetApiBufferFree. !!!!Notes: Prior to calling he DsAddressToSiteNames function, a [SOCKET_ADDRESS] structure must be created for each address that is to be resolved to a site name. This can be done using the WSAStringToAddress method shown in the sample code. !!!!Tips & Tricks: Please add some! !!!!C# Sample Code: public static string GetSiteNameForAddress(string address) { if (string.IsNullOrEmpty(address)) { throw new ArgumentNullException("address"); } WSADATA data = new WSADATA(); SockAddr sockAddr = new SockAddr(); IntPtr pSockAddr = IntPtr.Zero; IntPtr pSites = IntPtr.Zero; SOCKET_ADDRESS[] SocketAddresses = new SOCKET_ADDRESS[1]; string siteName = string.Empty; if (WSAStartup(0x201, ref data) == ERROR_SUCCESS) { int sockAddrSize = Marshal.SizeOf(sockAddr); // Call into WSAStringToAddress to build SOCKET_ADDRESS structure from the address string int result = WSAStringToAddress( address, System.Net.Sockets.AddressFamily.InterNetwork, IntPtr.Zero, ref sockAddr, ref sockAddrSize); WSACleanup(); // Check for failure from the WSAStringToAddress method if (result != ERROR_SUCCESS) { throw new Win32Exception(result); } // Allocate memory on the heap for the SockAddr structure pSockAddr = Marshal.AllocHGlobal(Marshal.SizeOf(sockAddr)); Marshal.StructureToPtr(sockAddr, pSockAddr, true); // Fill in the appropriate fields SocketAddresses[0].lpSockaddr = pSockAddr; SocketAddresses[0].iSockaddrLength = Marshal.SizeOf(sockAddr); // Get the site name for this address result = DsAddressToSiteNames("domaincontroller.mydomain.com", 1, SocketAddresses, ref pSites); if(result != ERROR_SUCCESS) { throw new Win32Exception(result); } // Read the string out of memory IntPtr pSiteName = Marshal.ReadIntPtr(pSites, 0); // If a site could not be found for this address, pSiteName will be 0, so only marshal out the string if // we got back a valid pointer. if (pSiteName != IntPtr.Zero) { siteName = Marshal.PtrToStringAuto(pSiteName); } // Be sure to free the memory allocated NetApiBufferFree(pSites); } return siteName; } Documentation: DsAddressToSiteNames@msdn on MSDN
Edit netapi32.DsAddres...
You do not have permission to change this page. If you feel this is in error, please send feedback with the contact link on the main page.