socket.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef SOCKET_H_INCLUDED
  2. #define SOCKET_H_INCLUDED
  3. #include <string>
  4. #ifdef _WIN32
  5. #ifndef WINVER
  6. #define WINVER 0x0501
  7. #endif // WINVER
  8. #include <ws2tcpip.h>
  9. #include <winsock2.h>
  10. #else
  11. //translate windows functions to linux functions
  12. #include <unistd.h>
  13. #include <string.h>
  14. #define SOCKET int
  15. #define INVALID_SOCKET (SOCKET)(~0)
  16. #define SOCKET_ERROR (-1)
  17. #define closesocket close
  18. #define SOCKADDR_IN sockaddr_in
  19. #define ZeroMemory(d,l) memset((d), 0, (l))
  20. #define ioctlsocket ioctl
  21. #ifndef SA_INTERRUPT
  22. #define SA_INTERRUPT 0 //ignore this setting
  23. #endif
  24. #ifndef __hpux
  25. #include <sys/select.h>
  26. #endif /* __hpux */
  27. #include <sys/socket.h>
  28. #include <sys/types.h>
  29. #include <sys/ioctl.h>
  30. #include <netinet/in.h>
  31. #include <arpa/inet.h>
  32. #include <stdio.h>
  33. #include <netdb.h>
  34. #include <signal.h>
  35. #include <unistd.h>
  36. typedef sockaddr *LPSOCKADDR;
  37. #endif // _WIN32
  38. #define BUF_SIZE 8192
  39. int getNetworkType(std::string addr);
  40. int Send(SOCKET sHost, const char* data, int len, int flags);
  41. int Recv(SOCKET sHost, char* data, int len, int flags);
  42. int socks5_do_auth_userpass(SOCKET sHost, std::string user, std::string pass);
  43. int setTimeout(SOCKET s, int timeout);
  44. int startConnect(SOCKET sHost, std::string addr, int port);
  45. int simpleSend(std::string addr, int port, std::string data);
  46. int send_simple(SOCKET sHost, std::string data);
  47. std::string hostnameToIPAddr(std::string host);
  48. int connectSocks5(SOCKET sHost, std::string username, std::string password);
  49. int connectThruSocks(SOCKET sHost, std::string host, int port);
  50. int connectThruHTTP(SOCKET sHost, std::string username, std::string password, std::string dsthost, int dstport);
  51. int checkPort(int startport);
  52. #endif // SOCKET_H_INCLUDED