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);
}
Topic:
App & System Services
SubTopic:
Core OS
Tags: