Work in Windows no Linux

Started by
2 comments, last by hplus0603 18 years, 9 months ago

struct connection {
#ifdef WIN32
	WSADATA wsaData;
	SOCKET socket1;
#else
	int socket1;
#endif
	struct sockaddr_in dest_addr;
	struct hostent *hostentry;
	char *ip;
	int port;
	int state;

};

That structure I use. In Windows I can compile my code fine but in Linux I get: error: defrencing point to incomplete type for this piece of code:
conn->dest_addr.sin_addr = *( ( struct sockaddr_in * )conn->hostentry->h_addr_list[0] ); 
but it compile in window idea?
Advertisement
You didn't include the header that defines sockaddr_in on Linux.

Note: the WSADATA is only needed on startup, so you don't need to hang on to it in the "connection" struct. Also, on Linux, you can #define SOCKET to int, so your struct doesn't need to be ifdefed at all.
enum Bool { True, False, FileNotFound };
I would prefer typedef int SOCKET over #define SOCKET int, but you can tell me why I'm wrong if you like?
I have vague recollections of trying that first (I'm usually a typedef man), and it failing in some unexpected gotcha, but I couldn't tell you what -- haven't had to change my portability layer for a while now ;-)

If you typedef and it works, so much the better.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement