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.

119 lines
3.1 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1994-1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: leverage.c
  6. * Content: code to allow third parties to hook our wsock sp
  7. * History:
  8. * Date By Reason
  9. * ==== == ======
  10. * 8/30/96 andyco moved this code from dpsp.c for more better clean
  11. * 2/18/98 a-peterz Comment byte order for address and port parameters
  12. **************************************************************************/
  13. #include "dpsp.h"
  14. #undef DPF_MODNAME
  15. #define DPF_MODNAME "dpwsock helper functions- "
  16. // the functions below are exported from dpwsock so sp's sitting on
  17. // top of us can hook our enum routine (e.g. for Kali)
  18. // return the port of our enum socket (net byte order)
  19. HRESULT DPWS_GetEnumPort(IDirectPlaySP * pISP,LPWORD pPort)
  20. {
  21. SOCKADDR_IN sockaddr;
  22. int iAddrLen = sizeof(SOCKADDR);
  23. UINT err;
  24. DWORD dwDataSize = sizeof(GLOBALDATA);
  25. LPGLOBALDATA pgd;
  26. HRESULT hr;
  27. if (!pISP)
  28. {
  29. DPF_ERR("must pass in IDirectPlaySP pointer!");
  30. return E_FAIL;
  31. }
  32. // get the global data
  33. hr =pISP->lpVtbl->GetSPData(pISP,(LPVOID *)&pgd,&dwDataSize,DPGET_LOCAL);
  34. if (FAILED(hr) || (dwDataSize != sizeof(GLOBALDATA) ))
  35. {
  36. DPF_ERR("couldn't get SP data from DirectPlay - failing");
  37. ExitThread(0);
  38. return 0;
  39. }
  40. if (AF_IPX == pgd->AddressFamily)
  41. {
  42. DPF(0," could not get the enum port for AF_IPX");
  43. return E_FAIL;
  44. }
  45. ASSERT(pPort);
  46. ASSERT(INVALID_SOCKET != pgd->sSystemStreamSocket);
  47. err = getsockname(pgd->sSystemStreamSocket,(SOCKADDR *)&sockaddr,&iAddrLen);
  48. if (SOCKET_ERROR == err)
  49. {
  50. err = WSAGetLastError();
  51. DPF(0,"GetEnumPort - getsockname - err = %d\n",err);
  52. return E_FAIL;
  53. }
  54. *pPort = sockaddr.sin_port;
  55. return DP_OK;
  56. } // GetEnumPort
  57. // takes a port and an ip (both in net byte order) and builds a message header
  58. HRESULT DPWS_BuildIPMessageHeader(IDirectPlaySP * pISP,LPVOID pvMessageHeader,LPDWORD
  59. pdwMessageHeaderSize,WORD port,DWORD inaddr)
  60. {
  61. LPMESSAGEHEADER phead;
  62. DWORD dwDataSize = sizeof(GLOBALDATA);
  63. LPGLOBALDATA pgd;
  64. HRESULT hr;
  65. if (!pISP)
  66. {
  67. DPF_ERR("must pass in IDirectPlaySP pointer!");
  68. return E_FAIL;
  69. }
  70. // get the global data
  71. hr =pISP->lpVtbl->GetSPData(pISP,(LPVOID *)&pgd,&dwDataSize,DPGET_LOCAL);
  72. if (FAILED(hr) || (dwDataSize != sizeof(GLOBALDATA) ))
  73. {
  74. DPF_ERR("couldn't get SP data from DirectPlay - failing");
  75. ExitThread(0);
  76. return 0;
  77. }
  78. ASSERT(pdwMessageHeaderSize);
  79. if ( (*pdwMessageHeaderSize < sizeof(MESSAGEHEADER)) || (NULL == pvMessageHeader))
  80. {
  81. *pdwMessageHeaderSize = sizeof(MESSAGEHEADER);
  82. return DPERR_BUFFERTOOSMALL;
  83. }
  84. if (AF_IPX == pgd->AddressFamily)
  85. {
  86. DPF_ERR("can't set header for ipx");
  87. return E_NOTIMPL;
  88. }
  89. phead = (LPMESSAGEHEADER)pvMessageHeader;
  90. ((SOCKADDR_IN *)&(phead->sockaddr))->sin_family = AF_INET;
  91. ((SOCKADDR_IN *)&(phead->sockaddr))->sin_addr.s_addr = inaddr;
  92. ((SOCKADDR_IN *)&(phead->sockaddr))->sin_port = port;
  93. DEBUGPRINTADDR(5,"BuildIPMessageHeader - setting header to",&(phead->sockaddr));
  94. return DP_OK;
  95. } // BuildIPMessageHeader
  96.