Leaked source code of windows server 2003
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.

178 lines
4.3 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: packetsender.cpp
  4. //
  5. // Synopsis: Implementation of CPacketSender class methods
  6. // The Class is responsible for sending RADIUS
  7. // packet data out to the client
  8. //
  9. //
  10. // History: 9/23/97 MKarki Created
  11. //
  12. // Copyright (C) 1997-98 Microsoft Corporation
  13. // All rights reserved.
  14. //
  15. //----------------------------------------------------------------
  16. #include "radcommon.h"
  17. #include "packetsender.h"
  18. //++--------------------------------------------------------------
  19. //
  20. // Function: CPacketSender
  21. //
  22. // Synopsis: This is the constructor of the CPacketSender class
  23. //
  24. // Arguments: NONE
  25. //
  26. // Returns: NONE
  27. //
  28. //
  29. // History: MKarki Created 11/25/97
  30. //
  31. //----------------------------------------------------------------
  32. CPacketSender::CPacketSender(
  33. VOID
  34. )
  35. {
  36. } // end of CPacketSender class constructor
  37. //++--------------------------------------------------------------
  38. //
  39. // Function: ~CPacketSender
  40. //
  41. // Synopsis: This is the destructor of the CPacketSender class
  42. //
  43. // Arguments: NONE
  44. //
  45. // Returns: NONE
  46. //
  47. // History: MKarki Created 11/25/97
  48. //
  49. //----------------------------------------------------------------
  50. CPacketSender::~CPacketSender(
  51. VOID
  52. )
  53. {
  54. } // end of CPacketSender class destructor
  55. //++--------------------------------------------------------------
  56. //
  57. // Function: SendPacket
  58. //
  59. // Synopsis: This is the CPacketSender public method that sends
  60. // packets out to the net
  61. //
  62. // Arguments:
  63. // [in] CPacketRadius*
  64. //
  65. // Returns: BOOL - bStatus
  66. //
  67. //
  68. // History: MKarki Created 11/25/97
  69. //
  70. // CalledBy: classes derived from CProcessor and CValidator
  71. //
  72. //----------------------------------------------------------------
  73. HRESULT
  74. CPacketSender::SendPacket (
  75. CPacketRadius *pCPacketRadius
  76. )
  77. {
  78. BOOL bStatus = FALSE;
  79. PBYTE pOutBuffer = NULL;
  80. DWORD dwSize = 0;
  81. DWORD dwPeerAddress = 0;
  82. WORD wPeerPort = 0;
  83. SOCKET sock;
  84. HRESULT hr = S_OK;
  85. _ASSERT (pCPacketRadius);
  86. __try
  87. {
  88. if (FALSE == IsProcessingEnabled ())
  89. {
  90. hr = E_FAIL;
  91. __leave;
  92. }
  93. //
  94. // get the out packet buffer from the packet object
  95. //
  96. pOutBuffer = pCPacketRadius->GetOutPacket ();
  97. //
  98. // get the data size
  99. //
  100. dwSize = pCPacketRadius->GetOutLength ();
  101. //
  102. // get the Peer address
  103. //
  104. dwPeerAddress = pCPacketRadius->GetOutAddress ();
  105. //
  106. // get the Peer port number
  107. //
  108. wPeerPort = pCPacketRadius->GetOutPort ();
  109. //
  110. // get the socket
  111. //
  112. sock = pCPacketRadius->GetSocket ();
  113. //
  114. // send the data out now
  115. //
  116. SOCKADDR_IN sin;
  117. sin.sin_family = AF_INET;
  118. sin.sin_port = htons (wPeerPort);
  119. sin.sin_addr.s_addr = htonl (dwPeerAddress);
  120. INT iBytesSent = ::sendto (
  121. sock,
  122. (PCHAR)pOutBuffer,
  123. (INT)dwSize,
  124. 0,
  125. (PSOCKADDR)&sin,
  126. (INT)sizeof (SOCKADDR)
  127. );
  128. if ((iBytesSent > 0) && (iBytesSent < dwSize))
  129. {
  130. IASTracePrintf (
  131. "Unable to send out complete Radius packet"
  132. );
  133. }
  134. else if (SOCKET_ERROR == iBytesSent)
  135. {
  136. int data = WSAGetLastError();
  137. IASTracePrintf (
  138. "Unable to send Radius packet due to error:%d", data
  139. );
  140. IASReportEvent(
  141. RADIUS_E_CANT_SEND_RESPONSE,
  142. 0,
  143. sizeof(data),
  144. NULL,
  145. &data
  146. );
  147. hr = RADIUS_E_ERRORS_OCCURRED;
  148. __leave;
  149. }
  150. //
  151. // success
  152. //
  153. }
  154. __finally
  155. {
  156. }
  157. return (hr);
  158. } // end of CPacketSender::SendPacket method