network.h 825 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef __MAUDIT_NETWORK_H
  2. #define __MAUDIT_NETWORK_H
  3. // Fixes for supporting broken OS's like MS Windows.
  4. #ifdef _WIN32
  5. #include <winsock2.h>
  6. #define SHUT_RDWR SD_BOTH
  7. #define MSG_NOSIGNAL 0
  8. #define SOL_TCP IPPROTO_TCP
  9. #define RECV_TYPE_CAST (char*)
  10. #define SETSOCKOPT_TYPE_CAST (const char*)
  11. #define SOCKLEN_T int
  12. void NETWORK_INIT() {
  13. WSAData wsaData;
  14. if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
  15. throw std::runtime_error("Could not WSAStartup()");
  16. }
  17. void NETWORK_STOP() {
  18. WSACleanup();
  19. }
  20. #define CLOSE closesocket
  21. #else
  22. #include <sys/socket.h>
  23. #include <netinet/in.h>
  24. #include <arpa/inet.h>
  25. #include <netinet/tcp.h>
  26. #define RECV_TYPE_CAST
  27. #define SETSOCKOPT_TYPE_CAST
  28. #define SOCKLEN_T socklen_t
  29. void NETWORK_INIT() {}
  30. void NETWORK_STOP() {}
  31. #define CLOSE close
  32. #endif
  33. #endif