Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com Message-Id: <199904211532.KAA06074@modi.xraylith.wisc.edu> X-Authentication-Warning: modi.xraylith.wisc.edu: localhost.xraylith.wisc.edu [127.0.0.1] didn't use HELO protocol To: Aldo Mazzilli cc: cygwin AT sourceware DOT cygnus DOT com Subject: Re: gethostname In-reply-to: Your message of "Wed, 21 Apr 1999 14:44:35 +0200." <371DC833 DOT 71FF AT inria DOT fr> Date: Wed, 21 Apr 1999 10:32:08 -0500 From: Mumit Khan Aldo Mazzilli writes: > Hello, > > I have to port a little C program to WindowsNT and I have some problems > with the following 'gethostname' command. > > I just want to get the HOSTNAME value using : > - gcc with cygwin32 libs (local compilation) > and - egcs with mingw32 libs (cross-compilation) > > None of these both solutions work. > > Do you know why the following program can't give me the HOSTNAME value : > --------- > main () > { > char HOSTNAME[4096]; > > gethostname (HOSTNAME, 4096); > printf("HOST : %s",HOSTNAME) ; > } > --------- > > NB : it seems that WindowsNT requires to start up the Windows Sockets > API using WSAStartup() . Am I right ? What exactly does not work?? I tried out your test code With Cygwin b20.1 and it spit out the hostname for me. Please provide more details when you post these "but it doesn't work!" messages. For mingw32, you'll have to make sure the correct prototype is included (via winsock.h or some such header) and also wsock32 library is linked in. You quite possibly also have to initialize Winsock, and I'm sure any win32 book will tell you what the right thing is ... Try the following (untested, mind you): #include #include #if defined (_WIN32) && ! defined (__CYGWIN__) #include #endif int main () { char HOSTNAME[4096]; #if defined (_WIN32) && ! defined (__CYGWIN__) WSADATA p; WSAStartup ((2<<8) | 2, &p); #endif gethostname (HOSTNAME, 4096); printf("HOST : %s\n", HOSTNAME) ; return 0; } Regards, Mumit -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com