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.

192 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. dhcpprt.c
  5. Abstract:
  6. This module contains DHCP specific utility routines used by the
  7. DHCP components.
  8. Author:
  9. Madan Appiah (madana) 16-Sep-1993
  10. Revision History:
  11. --*/
  12. #include <nt.h>
  13. #include <ntrtl.h>
  14. #include <nturtl.h>
  15. #include <dhcpl.h>
  16. #if DBG
  17. VOID
  18. DhcpDumpMessage(
  19. DWORD DhcpDebugFlag,
  20. LPDHCP_MESSAGE DhcpMessage,
  21. ULONG MessageSize
  22. )
  23. /*++
  24. Routine Description:
  25. This function dumps a DHCP packet in human readable form.
  26. Arguments:
  27. DhcpDebugFlag - debug flag that indicates what we are debugging.
  28. DhcpMessage - A pointer to a DHCP message.
  29. Return Value:
  30. None.
  31. --*/
  32. {
  33. LPOPTION option;
  34. BYTE i;
  35. DhcpPrint(( DhcpDebugFlag, "Dhcp message: \n\n"));
  36. DhcpPrint(( DhcpDebugFlag, "Operation :"));
  37. if ( DhcpMessage->Operation == BOOT_REQUEST ) {
  38. DhcpPrint(( DhcpDebugFlag, "BootRequest\n"));
  39. } else if ( DhcpMessage->Operation == BOOT_REPLY ) {
  40. DhcpPrint(( DhcpDebugFlag, "BootReply\n"));
  41. } else {
  42. DhcpPrint(( DhcpDebugFlag, "Unknown\n"));
  43. }
  44. DhcpPrint(( DhcpDebugFlag, "Hardware Address type : %d\n", DhcpMessage->HardwareAddressType));
  45. DhcpPrint(( DhcpDebugFlag, "Hardware Address Length: %d\n", DhcpMessage->HardwareAddressLength));
  46. DhcpPrint(( DhcpDebugFlag, "Hop Count : %d\n", DhcpMessage->HopCount ));
  47. DhcpPrint(( DhcpDebugFlag, "Transaction ID : %lx\n", DhcpMessage->TransactionID ));
  48. DhcpPrint(( DhcpDebugFlag, "Seconds Since Boot : %d\n", DhcpMessage->SecondsSinceBoot ));
  49. DhcpPrint(( DhcpDebugFlag, "Client IP Address : " ));
  50. DhcpPrint(( DhcpDebugFlag, "%s\n",
  51. inet_ntoa(*(struct in_addr *)&DhcpMessage->ClientIpAddress ) ));
  52. DhcpPrint(( DhcpDebugFlag, "Your IP Address : " ));
  53. DhcpPrint(( DhcpDebugFlag, "%s\n",
  54. inet_ntoa(*(struct in_addr *)&DhcpMessage->YourIpAddress ) ));
  55. DhcpPrint(( DhcpDebugFlag, "Server IP Address : " ));
  56. DhcpPrint(( DhcpDebugFlag, "%s\n",
  57. inet_ntoa(*(struct in_addr *)&DhcpMessage->BootstrapServerAddress ) ));
  58. DhcpPrint(( DhcpDebugFlag, "Relay Agent IP Address : " ));
  59. DhcpPrint(( DhcpDebugFlag, "%s\n",
  60. inet_ntoa(*(struct in_addr *)&DhcpMessage->RelayAgentIpAddress ) ));
  61. DhcpPrint(( DhcpDebugFlag, "Hardware Address : "));
  62. for ( i = 0; i < DhcpMessage->HardwareAddressLength; i++ ) {
  63. DhcpPrint(( DhcpDebugFlag, "%2.2x", DhcpMessage->HardwareAddress[i] ));
  64. }
  65. option = &DhcpMessage->Option;
  66. DhcpPrint(( DhcpDebugFlag, "\n\n"));
  67. DhcpPrint(( DhcpDebugFlag, "Magic Cookie: "));
  68. for ( i = 0; i < 4; i++ ) {
  69. DhcpPrint(( DhcpDebugFlag, "%d ", *((LPBYTE)option)++ ));
  70. }
  71. DhcpPrint(( DhcpDebugFlag, "\n\n"));
  72. DhcpPrint(( DhcpDebugFlag, "Options:\n"));
  73. while ( option->OptionType != 255 ) {
  74. DhcpPrint(( DhcpDebugFlag, "\tType = %d ", option->OptionType ));
  75. for ( i = 0; i < option->OptionLength; i++ ) {
  76. DhcpPrint(( DhcpDebugFlag, "%2.2x", option->OptionValue[i] ));
  77. }
  78. DhcpPrint(( DhcpDebugFlag, "\n"));
  79. if ( option->OptionType == OPTION_PAD ||
  80. option->OptionType == OPTION_END ) {
  81. option = (LPOPTION)( (LPBYTE)(option) + 1);
  82. } else {
  83. option = (LPOPTION)( (LPBYTE)(option) + option->OptionLength + 2);
  84. }
  85. if ( (ULONG)((LPBYTE)option - (LPBYTE)DhcpMessage) > MessageSize ) {
  86. DhcpPrint(( DhcpDebugFlag, "End of message, but no trailer found!\n"));
  87. break;
  88. }
  89. }
  90. }
  91. VOID
  92. MadcapDumpMessage(
  93. DWORD DhcpDebugFlag,
  94. LPMADCAP_MESSAGE MadcapMessage,
  95. ULONG MessageSize
  96. )
  97. /*++
  98. Routine Description:
  99. This function dumps a DHCP packet in human readable form.
  100. Arguments:
  101. DhcpDebugFlag - debug flag that indicates what we are debugging.
  102. MadcapMessage - A pointer to a DHCP message.
  103. Return Value:
  104. None.
  105. --*/
  106. {
  107. WIDE_OPTION UNALIGNED* NextOpt;
  108. BYTE UNALIGNED* EndOpt;
  109. DWORD Size;
  110. DWORD OptionType;
  111. BYTE i;
  112. DhcpPrint(( DhcpDebugFlag, "Madcap message: \n\n"));
  113. DhcpPrint(( DhcpDebugFlag, "Version : %d\n",MadcapMessage->Version));
  114. DhcpPrint(( DhcpDebugFlag, "MessageType : %d\n",MadcapMessage->MessageType));
  115. DhcpPrint(( DhcpDebugFlag, "AddressFamily : %d\n",ntohs(MadcapMessage->AddressFamily)));
  116. DhcpPrint(( DhcpDebugFlag, "TransactionId : %d\n",MadcapMessage->TransactionID));
  117. DhcpPrint(( DhcpDebugFlag, "\n\n"));
  118. DhcpPrint(( DhcpDebugFlag, "Options:\n"));
  119. // MBUG CHANGE 255 TO end option
  120. NextOpt = (WIDE_OPTION UNALIGNED*)&MadcapMessage->Option;
  121. EndOpt = (PBYTE)MadcapMessage + MessageSize;
  122. while( NextOpt->OptionValue <= EndOpt &&
  123. MADCAP_OPTION_END != (OptionType = ntohs(NextOpt->OptionType)) ) {
  124. Size = ntohs(NextOpt->OptionLength);
  125. if ((NextOpt->OptionValue + Size) > EndOpt) {
  126. break;
  127. }
  128. DhcpPrint(( DhcpDebugFlag, "\tType = %d ", OptionType ));
  129. for ( i = 0; i < Size; i++ ) {
  130. DhcpPrint(( DhcpDebugFlag, "%2.2x", NextOpt->OptionValue[i] ));
  131. }
  132. DhcpPrint(( DhcpDebugFlag, "\n"));
  133. NextOpt = (WIDE_OPTION UNALIGNED*)(NextOpt->OptionValue + Size);
  134. }
  135. }
  136. #endif