How to Get Computer Name

Howard Scott's icon

Anyone know how to get the computer name in C?
The Max Object is "gestalt" and you can send "host" message to get it but I have no clue how with the sdk.

Rob Ramirez's icon

it doesn't look like the gestalt header file is included in the SDK, but it does look like the functions are exported, so you can try including the following definitions somewhere and calling them in your external (obviously no guarantees of past/present/future support):

long sysinfo_gestalt_get_sysv(void);
void sysinfo_gestalt_get_sysvers(long *major, long *minor, long *patch);
t_symbol *sysinfo_gestalt_get_systemversion(void);
long sysinfo_gestalt_get_pid(void);
t_symbol *sysinfo_gestalt_get_processname(void);
long sysinfo_gestalt_get_processorcount(void);
t_uint64 sysinfo_gestalt_get_physicalmemory(void);
t_symbol *sysinfo_gestalt_get_hostname(void);
t_atomarray *sysinfo_gestalt_get_arguments(void);
t_dictionary *sysinfo_gestalt_get_environment(void);


alternatively, the implementation used for hostname on mac is

NSString *hostname = [[NSProcessInfo processInfo] hostName];
return gensym([hostname UTF8String]);


and on win (uses JUCE so you will have to adapt to your needs)

TCHAR text[128] = { 0 };
auto len = (DWORD) numElementsInArray (text) - 1;
GetComputerNameEx (ComputerNamePhysicalDnsHostname, text, &len);
return String (text, len);

Rob Ramirez's icon

file an issue here to get these added, if you're so inclined : https://github.com/Cycling74/max-sdk/issues

Howard Scott's icon

Thank you soo much Rob. This is a good start. Hopefully it’ll work.