Network Name (local domain Name) of a Mac (Mac-OS)

I want to get the network-name (domain-name) on my Mac-Machine. Where iin the Settings does this domain name gets configured. I refer to this page which talks about computer name and host name, I could find where my hostname is present (Settings->General->Sharing->local host name) but not anything related to the network-name (local -domain) .

Even try to fetch this info using the linux api to getdomainname, api call succeeded but it returns Nothing.

#include <iostream>
#include <unistd.h>
#include <limits.h>
#include <cstring>

int main() {
    char domainname[255];
    
    // Get the domain name
    if (getdomainname(domainname, 255) != 0) {
        std::cout << "Error getting domain name" << std::endl;
        return 1;
    }
    
    std::cout << "Domain name: " << domainname << std::endl;
    
    return 0;
}

Output

Domain name:

I even came across Search-Domains, Does it have anything to do with the network-name (domain name of the machine)?

Replies

Do you mean hostname / localhost name? You can use the SystemConfiguration framework:

#include <stdio.h>
#include <SystemConfiguration/SystemConfiguration.h>

int main() {
	char hostname[1024];
	const char* name = "name";
	CFStringRef nameRef = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingASCII);
	SCDynamicStoreRef store = SCDynamicStoreCreate(kCFAllocatorDefault, nameRef, NULL, NULL);
	CFStringRef hostnameRef = SCDynamicStoreCopyLocalHostName(store);
	CFStringGetCString(hostnameRef, hostname, 128, kCFStringEncodingUTF8);
	printf("Hostname: %s\n", hostname);
}

No, i require the local domain assigned to a machine, just like we have in Windows. Hostname is used to identify a machine in network. I am able to get the hostname, how can i get FQDN (Fully Qualified Domain Name) which will be consisting of hostname.networkname for Ex - macofficestudio is my host name and thread.solutions.com is my network name (local domain name) so FQDN becomes macofficestudio.thread.solutions.com. How to get that ??

To be clear, you’re not talking about FQDNs here, at least not in the standard sense of that term:

  • A Mac can have a variety of different network interfaces.

  • Each of those has zero or more IP addresses.

  • Each of those has zero or more FQDNs that point to it.

So there’s no single FQDN value that identifies the machine.

i require the local domain assigned to a machine, just like we have in Windows.

This is probably something Active Directory related. Is the machine in question bound to AD?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Yeah its related to Active Directory. We used our host-name to identify a node in a network, similarly we also have network-name (local domain) assigned to a machine which doesn't varies, on the basis of network you are connected. This value helps form a full qualified name for the machine / device and can be used as an alternative to resolve to an IP Address to reach the machine / device or show it to the user as user relates more to names than IP Addresses.

Add a Comment

Yes It's related to Active Directory. Here I am not referring to the FQDN of the interfaces through which we are connected to Internet. Just like hostname which helps us to identify a machine in a network. We can use network-name (local domain name) which is assigned to a machine and doesn't depend on the interfaces, which can be used as an alternative of an IP-address.

Fully Qualified Domain Name which i means is hostname + network name (local domain name) which can be used to communicate with a machine.

IIRC this AD name is stored in the OD configuration somewhere, but I don’t have an AD setup handy so I can’t share exact details.

Try poking around in OD using dscl. Once you find the value you need, it’s relatively straightforward to get it with the Open Directory framework API.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Thanks I will try this out, in mean time if you find where it's present in the active directory let me know.

Add a Comment