Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
780 B

  1. // connect.cpp
  2. //
  3. #pragma hdrstop
  4. #include "host.h"
  5. HRESULT Connect (CHost& host, INT port, bool& bRet)
  6. {
  7. SOCKET s;
  8. SOCKADDR_IN sAddr;
  9. HRESULT hr;
  10. s= socket(AF_INET, SOCK_STREAM, PF_UNSPEC);
  11. if (INVALID_SOCKET == s)
  12. {
  13. bRet = false;
  14. return WSAGetLastError();
  15. }
  16. // Bind this socket to the server's socket address
  17. memset(&sAddr, 0, sizeof (sAddr));
  18. sAddr.sin_family = AF_INET;
  19. sAddr.sin_addr.s_addr = host;
  20. sAddr.sin_port = htons((u_short)port);
  21. if (connect(s, (SOCKADDR*)&sAddr, sizeof(SOCKADDR_IN)) == 0)
  22. {
  23. bRet = true;
  24. closesocket(s);
  25. return S_OK;
  26. }
  27. else
  28. {
  29. bRet = false;
  30. hr = WSAGetLastError();
  31. closesocket(s);
  32. return hr;
  33. }
  34. }