/******
nonport.h
GameSpy Developer SDK

Copyright 1999 GameSpy Industries, Inc

Suite E-204
2900 Bristol Street
Costa Mesa, CA 92626
(714)549-7689
Fax(714)549-0757

******/

#ifndef _NONPORT_H_
#define _NONPORT_H_

#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
	#include <winsock2.h>
	#include <windows.h>
#else
	#include <string.h>
	#include <stdlib.h>
	#include <ctype.h>
	#include <unistd.h>
	#include <sys/types.h>
	#include <sys/ioctl.h>
	#include <sys/socket.h>
	#include <stdio.h>
	#include <stdlib.h>
	#include <sys/types.h>
	#include <sys/socket.h>
	#include <netinet/in.h>
	#include <netdb.h>
	#include <arpa/inet.h>
	#include <ctype.h>
	#include <errno.h>
	#include <sys/time.h>
#ifdef __DJGPP__ /* WATT-32 library */
	#include <tcp.h>  /* select_s() */
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if defined(_WIN32) || defined(__DJGPP__)
typedef int goa_int32;
typedef unsigned int goa_uint32;
#else
typedef int goa_int32;
typedef unsigned int goa_uint32;
#endif

goa_uint32 current_time(void);
void msleep(goa_uint32 msec);

void SocketStartUp(void);
void SocketShutDown(void);

#ifndef SOCKET_ERROR 
	#define SOCKET_ERROR (-1)
#endif

#ifndef INADDR_NONE
	#define INADDR_NONE 0xffffffff
#endif

#ifndef INVALID_SOCKET
	#define INVALID_SOCKET (-1)
#endif

#ifdef _WIN32
	#define strcasecmp _stricmp
	#define strncasecmp _strnicmp
	#define selectsocket select
	#define IOCTLARG_T
	typedef int socklen_t;
	typedef u_long in_addr_t; /* uint32_t */
#elif defined(__DJGPP__)
	#define _strdup strdup
	#define IOCTLARG_T	(char*)
	#define SOCKET int
	#define selectsocket select_s
	typedef int socklen_t;
	typedef u_long in_addr_t;
#else
	#define _strdup strdup
	#define SOCKET int
	#define ioctlsocket ioctl
	#define closesocket close
	#define selectsocket select
	#define IOCTLARG_T
#endif

#ifndef _WIN32
	#define WSAEWOULDBLOCK EWOULDBLOCK
	#define WSAEINPROGRESS EINPROGRESS
	#define WSAEALREADY EALREADY
	#define WSAENOTSOCK ENOTSOCK
	#define WSAEDESTADDRREQ EDESTADDRREQ
	#define WSAEMSGSIZE EMSGSIZE
	#define WSAEPROTOTYPE EPROTOTYPE
	#define WSAENOPROTOOPT ENOPROTOOPT
	#define WSAEPROTONOSUPPORT EPROTONOSUPPORT
	#define WSAESOCKTNOSUPPORT ESOCKTNOSUPPORT
	#define WSAEOPNOTSUPP EOPNOTSUPP
	#define WSAEPFNOSUPPORT EPFNOSUPPORT
	#define WSAEAFNOSUPPORT EAFNOSUPPORT
	#define WSAEADDRINUSE EADDRINUSE
	#define WSAEADDRNOTAVAIL EADDRNOTAVAIL
	#define WSAENETDOWN ENETDOWN
	#define WSAENETUNREACH ENETUNREACH
	#define WSAENETRESET ENETRESET
	#define WSAECONNABORTED ECONNABORTED
	#define WSAECONNRESET ECONNRESET
	#define WSAENOBUFS ENOBUFS
	#define WSAEISCONN EISCONN
	#define WSAENOTCONN ENOTCONN
	#define WSAESHUTDOWN ESHUTDOWN
	#define WSAETOOMANYREFS ETOOMANYREFS
	#define WSAETIMEDOUT ETIMEDOUT
	#define WSAECONNREFUSED ECONNREFUSED
	#define WSAELOOP ELOOP
	#define WSAENAMETOOLONG ENAMETOOLONG
	#define WSAEHOSTDOWN EHOSTDOWN
	#define WSAEHOSTUNREACH EHOSTUNREACH
	#define WSAENOTEMPTY ENOTEMPTY
	#define WSAEPROCLIM EPROCLIM
	#define WSAEUSERS EUSERS
	#define WSAEDQUOT EDQUOT
	#define WSAESTALE ESTALE
	#define WSAEREMOTE EREMOTE
#else
	#define GOAGetLastError(s) WSAGetLastError()
#endif

#ifndef _WIN32
	typedef struct sockaddr SOCKADDR;
	typedef struct sockaddr_in SOCKADDR_IN;
	typedef struct in_addr IN_ADDR;
	typedef struct hostent HOSTENT;
	typedef struct timeval TIMEVAL;
#endif

#ifndef max
#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define min(a,b)    (((a) < (b)) ? (a) : (b))
#endif

#ifdef _WIN32
	#define PATHCHAR '\\'
#elif defined MACOS
	#define PATHCHAR ':'
#else
	#define PATHCHAR '/'
#endif

int SetSockBlocking(SOCKET sock, int isblocking);

#include <time.h>

#ifdef __cplusplus
}
#endif

#endif /* _NONPORT_H_ */
