tron@2186: /* $Id$ */ tron@2186: truelight@543: #ifndef NETWORK_CORE_H truelight@543: #define NETWORK_CORE_H truelight@543: truelight@543: // Network stuff has many things that needs to be included truelight@543: // by default. All those things are in this file. truelight@543: truelight@543: // ============================= truelight@543: // Include standard stuff per OS truelight@543: Darkvater@1812: #ifdef ENABLE_NETWORK Darkvater@1812: bjarni@9956: #if defined(__APPLE__) && (MAC_OS_X_VERSION_MAX_ALLOWED == MAC_OS_X_VERSION_10_2) bjarni@2741: // OSX 10.2 don't have socklen_t defined, so we will define it here bjarni@2741: typedef int socklen_t; bjarni@2741: #endif bjarni@2741: truelight@543: // Windows stuff Darkvater@2482: #if defined(WIN32) || defined(WIN64) darkvater@796: #include darkvater@796: #include Darkvater@2482: #include darkvater@792: darkvater@1505: #if !(defined(__MINGW32__) || defined(__CYGWIN__)) darkvater@796: // Windows has some different names for some types.. darkvater@796: typedef SSIZE_T ssize_t; darkvater@1342: typedef int socklen_t; darkvater@796: #endif darkvater@796: darkvater@796: #define GET_LAST_ERROR() WSAGetLastError() darkvater@796: #define EWOULDBLOCK WSAEWOULDBLOCK truelight@543: // Windows has some different names for some types.. truelight@543: typedef unsigned long in_addr_t; truelight@543: typedef INTERFACE_INFO IFREQ; truelight@543: #endif // WIN32 truelight@543: truelight@543: // UNIX stuff truelight@543: #if defined(UNIX) truelight@543: # define SOCKET int truelight@543: # define INVALID_SOCKET -1 truelight@543: typedef struct ifreq IFREQ; truelight@543: # if !defined(__MORPHOS__) && !defined(__AMIGA__) truelight@543: # define ioctlsocket ioctl truelight@543: # if !defined(BEOS_NET_SERVER) truelight@543: # define closesocket close truelight@543: # endif truelight@543: # define GET_LAST_ERROR() (errno) truelight@543: # endif truelight@543: // Need this for FIONREAD on solaris truelight@543: # define BSD_COMP truelight@543: truelight@543: // Includes needed for UNIX-like systems truelight@543: # include truelight@543: # include truelight@543: # if defined(__BEOS__) && defined(BEOS_NET_SERVER) truelight@543: # include truelight@543: # include // snooze() truelight@543: # include truelight@543: typedef unsigned long in_addr_t; truelight@543: # define INADDR_NONE INADDR_BROADCAST truelight@543: # else truelight@543: # include truelight@543: # include truelight@543: # include truelight@543: # include truelight@543: # include pasky@1412: // According to glibc/NEWS, appeared in glibc-2.3. Darkvater@1810: # if !defined(__sgi__) && !defined(SUNOS) && !defined(__MORPHOS__) && !defined(__BEOS__) \ truelight@1687: && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) pasky@1412: // If for any reason ifaddrs.h does not exist on your system, comment out pasky@1412: // the following two lines and an alternative way will be used to fetch pasky@1412: // the list of IPs from the system. tron@706: # include tron@706: # define HAVE_GETIFADDRS pasky@1412: # endif pasky@1412: # if defined(SUNOS) || defined(__MORPHOS__) || defined(__BEOS__) tron@706: # define INADDR_NONE 0xffffffff pasky@1412: # endif tron@1051: # if defined(__BEOS__) && !defined(BEOS_NET_SERVER) tron@1051: // needed on Zeta tron@1051: # include tron@1051: # endif truelight@543: # endif // BEOS_NET_SERVER truelight@789: Darkvater@1812: # if !defined(__BEOS__) && defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 1) truelight@789: typedef uint32_t in_addr_t; pasky@1412: # endif truelight@789: truelight@543: # include truelight@543: # include truelight@543: # include truelight@543: #endif // UNIX truelight@543: tron@1429: #ifdef __BEOS__ darkvater@1441: typedef int socklen_t; tron@1429: #endif tron@1429: truelight@781: // OS/2 stuff truelight@781: #if defined(__OS2__) truelight@781: # define SOCKET int truelight@781: # define INVALID_SOCKET -1 truelight@781: typedef struct ifreq IFREQ; truelight@781: # define ioctlsocket ioctl truelight@781: # define closesocket close truelight@810: # define GET_LAST_ERROR() (sock_errno()) truelight@781: truelight@781: // Includes needed for OS/2 systems truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@781: # include truelight@810: # define INADDR_NONE 0xffffffff truelight@781: darkvater@1507: typedef int socklen_t; truelight@781: typedef unsigned long in_addr_t; truelight@781: #endif // OS/2 truelight@781: truelight@543: // MorphOS and Amiga stuff truelight@543: #if defined(__MORPHOS__) || defined(__AMIGA__) truelight@543: # include truelight@543: # include // required for Open/CloseLibrary() truelight@543: # if defined(__MORPHOS__) bjarni@770: # include // FIO* defines bjarni@770: # include // SIO* defines tron@1343: # include truelight@543: # else // __AMIGA__ truelight@543: # include truelight@543: # endif truelight@543: truelight@543: // Make the names compatible truelight@543: # define closesocket(s) CloseSocket(s) truelight@543: # define GET_LAST_ERROR() Errno() truelight@543: # define ioctlsocket(s,request,status) IoctlSocket((LONG)s,(ULONG)request,(char*)status) bjarni@770: # define ioctl ioctlsocket truelight@543: bjarni@770: typedef unsigned int in_addr_t; tron@1343: typedef long socklen_t; bjarni@770: extern struct Library *SocketBase; bjarni@770: bjarni@770: # ifdef __AMIGA__ bjarni@770: // for usleep() implementation bjarni@770: extern struct Device *TimerBase; bjarni@770: extern struct MsgPort *TimerPort; bjarni@770: extern struct timerequest *TimerRequest; bjarni@770: # endif truelight@543: #endif // __MORPHOS__ || __AMIGA__ truelight@543: tron@1332: static inline bool SetNonBlocking(int d) tron@1332: { tron@1466: #ifdef WIN32 tron@1466: u_long nonblocking = 1; tron@1466: #else tron@1332: int nonblocking = 1; tron@1466: #endif tron@1332: #if defined(__BEOS__) && defined(BEOS_NET_SERVER) tron@1332: return setsockopt(d, SOL_SOCKET, SO_NONBLOCK, &nonblocking, sizeof(nonblocking)) == 0; tron@1332: #else tron@1332: return ioctlsocket(d, FIONBIO, &nonblocking) == 0; tron@1332: #endif tron@1332: } tron@1332: tron@1332: static inline bool SetNoDelay(int d) tron@1332: { tron@1332: // XXX should this be done at all? tron@1332: #if !defined(BEOS_NET_SERVER) // not implemented on BeOS net_server tron@1332: int b = 1; tron@1332: // The (const char*) cast is needed for windows tron@1332: return setsockopt(d, IPPROTO_TCP, TCP_NODELAY, (const char*)&b, sizeof(b)) == 0; tron@1332: #else tron@1332: return true; tron@1332: #endif tron@1332: } tron@1332: Darkvater@1812: #endif /* ENABLE_NETWORK */ Darkvater@1812: Darkvater@1812: #endif /* NETWORK_CORE_H */