This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

sockets: problem using h_errno


Hello,

I'm trying to compile a C program that was created on Unix.  It uses
sockets: one of the source files includes the netdb.h file and uses h_errno
to get the error code after a call to getHostByName().  See the code below.

	#include <netdb.h>	/* getservbyname(),
gethostbyname(),HOST_NOT_FOUND */

	/* CODE SKIPPED */

	int tcp_open(){
		struct sockaddr_in server;
		struct servent* servp;
		struct hostent* servh;
		
		assert(myFd >= 0);

		/* get the host address from /etc/hosts */
		if ((servh=gethostbyname(Machine_name)) == NULL){
			
			if (h_errno == HOST_NOT_FOUND){

	/* CODE SKIPPED */

At compile time, ld complains about an "undefined reference to h_errno" from
the last line above.
In netdb.h, here is the definition of h_errno (I don't use the
-D__INSIDE_CYGWIN_NET__ flag in gcc):

	#ifdef  __INSIDE_CYGWIN_NET__
	extern int h_errno;
	#else
	extern __declspec(dllimport) int h_errno;
	#endif

At the end of the compilation process, I link the object files against the
cygwin library:
gcc -Wall -ansi -D__STDC__=0 MsgHandler.o SCPLoadLog.o timeval.o TcpGate.o
SCPLoadSim.o -o SCPLoadSim -lcygwin

I thought this library exports h_errno...  Do you have an idea ?
I know this could be a very basic question on how to use gcc... sorry if it
is so.

Many thanks,

	_Olivier_



--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]