Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than netapi32, prefix the name with the module name and a period.
DsAddressToSiteNames (netapi32)
.
C# Signature:
[DllImport("netapi32.dll", CharSet=CharSet.Auto)]
public static extern int DsAddressToSiteNames(string computerName, int entryCount, SOCKET_ADDRESS[] socketAddresses, ref IntPtr siteNames);
[DllImport("netapi32.dll", SetLastError=true)]
static extern TODO DsAddressToSiteNames(TODO);
VB Signature:
Declare Function DsAddressToSiteNames Lib "netapi32.dll" (TODO) As TODO
User-Defined Types:
None.
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.
Alternative Managed API:
Do you know one? Please contribute it!
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.
None.
Tips & Tricks:
Please add some!
C# Sample Code:
public static string GetSiteNameForAddress(string address)
{
if (string.IsNullOrEmpty(address))
{
throw new ArgumentNullException("address");
}
Sample Code:
Please add some!
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;
}
The DsAddressToSiteNames function obtains the site names corresponding to the specified addresses.
11/3/2011 11:14:22 AM - -131.107.0.98
The DsGetDcName function returns the name of a domain controller in a specified domain. This function accepts additional domain controller selection criteria to indicate preference for a domain controller with particular characteristics.
11/19/2009 10:18:52 AM - -198.54.202.18
The SOCKET_ADDRESS structure stores protocol-specific address information.
11/3/2011 10:31:15 AM - anonymous
Frees the memory allocated by network management functions.
6/21/2016 8:26:32 AM - -63.226.251.37
The DsAddressToSiteNames function obtains the site names corresponding to the specified addresses.
11/3/2011 11:14:22 AM - -131.107.0.98
The SOCKET_ADDRESS structure stores protocol-specific address information.
11/3/2011 10:31:15 AM - anonymous
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).