NetGetDCName or Net32GetDCName

Given a domain name, the NetGetDCName API returns the name of the domain controller, if there is one. If you specify the null domain name, the API returns the name of the domain controller (DC) of the primary domain.