Click to See Complete Forum and Search --> : GetComputerName on Solaris


luftwaffe
February 3rd, 2003, 10:04 AM
Hello,

Is there any function what retrieves name of computer the application is running on?

Thanks

cup
February 4th, 2003, 12:43 PM
Lookup the man page on uname.

AdaraCD
February 5th, 2003, 06:54 AM
int gethostname(char *name, int namelen);

mwilliamson
February 5th, 2003, 06:09 PM
The Windows Sockets gethostname function returns the standard host name for the local machine.

Strait out of MSDN! Hes not running on Windows, and therefore does not have Winsock.

PaulWendt
February 5th, 2003, 07:51 PM
Originally posted by mwilliamson


Strait out of MSDN! Hes not running on Windows, and therefore does not have Winsock.

gethostname() is available on many systems, not just Windows.
It's available on many unix systems:

http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?gethostname+2

luftwaffe
February 6th, 2003, 02:53 AM
Okay, thank you gentlemen (or gentlewomen) :)

I got it. I did not want to link sockets stuff on Solaris (as I do not link winsock for GetComputerName, just MFC).

Is there a chance to get the computer name w/o the socket stuff?

AdaraCD
February 6th, 2003, 03:47 AM
uname will not work on old unix systems ,there for gethostname will be the best solution

cup
February 6th, 2003, 06:00 AM
uname will work from Solaris 2.6 onwards. Don't know about 2.5. On 2.6, because gethostname was a BSD thing, you will need to declare it explicitly as it is not included in any header file. Well, that's my penny's worth - things may have changed on later versions of Solaris: I think it is now on 2.9.