// Included by NetworkDevice.cpp and TCPConduit.cpp to provide a platform-independent networking base #include #include #include #if defined(G3D_LINUX) || defined(G3D_OSX) || defined(G3D_FREEBSD) # include # include # include # include # include # ifdef __linux__ # include # include # include # include // Match Linux to FreeBSD # define AF_LINK AF_PACKET # else # include # include # endif #include #include #include #include #include #include #include #include #include #include #include #include #define _alloca alloca /** Define an error code for non-windows platforms. */ int WSAGetLastError() { return -1; } #define SOCKET_ERROR -1 static std::string socketErrorCode(int code) { return G3D::format("CODE %d: %s\n", code, strerror(code)); } static std::string socketErrorCode() { return socketErrorCode(errno); } static const int WSAEWOULDBLOCK = -100; typedef int SOCKET; typedef struct sockaddr_in SOCKADDR_IN; #else // Windows static std::string socketErrorCode(int code) { LPTSTR formatMsg = NULL; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, NULL, code, 0, (LPTSTR)&formatMsg, 0, NULL); return G3D::format("CODE %d: %s\n", code, formatMsg); } static std::string socketErrorCode() { return socketErrorCode(GetLastError()); } #endif #ifndef _SOCKLEN_T # if defined(G3D_WINDOWS) || defined(G3D_OSX) typedef int socklen_t; # endif #endif