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.

128 lines
2.1 KiB

  1. /*++
  2. Copyright (c) 1999, Microsoft Corporation
  3. Module Name:
  4. sample\packet.c
  5. Abstract:
  6. The file contains functions to deal with an ip sample packet.
  7. --*/
  8. #include "pchsample.h"
  9. #pragma hdrstop
  10. DWORD
  11. PacketCreate (
  12. OUT PPACKET *ppPacket)
  13. /*++
  14. Routine Description
  15. Creates a packet.
  16. Locks
  17. None
  18. Arguments
  19. ppPacket pointer to the packet address
  20. Return Value
  21. NO_ERROR if success
  22. Failure code o/w
  23. --*/
  24. {
  25. DWORD dwErr = NO_ERROR;
  26. // validate parameters
  27. if (!ppPacket)
  28. return ERROR_INVALID_PARAMETER;
  29. do // breakout loop
  30. {
  31. // allocate and zero out the packet structure
  32. MALLOC(ppPacket, sizeof(PACKET), &dwErr);
  33. if (dwErr != NO_ERROR)
  34. break;
  35. // initialize fields
  36. // ((*ppPacket)->ipSource zero'ed out
  37. sprintf((*ppPacket)->rgbyBuffer, "hello world!"); // for now :)
  38. (*ppPacket)->wsaBuffer.buf = (*ppPacket)->rgbyBuffer;
  39. (*ppPacket)->wsaBuffer.len = strlen((*ppPacket)->rgbyBuffer);
  40. } while (FALSE);
  41. return dwErr;
  42. }
  43. DWORD
  44. PacketDestroy (
  45. IN PPACKET pPacket)
  46. /*++
  47. Routine Description
  48. Destroys a packet.
  49. Locks
  50. None
  51. Arguments
  52. pPacket packet to destroy
  53. Return Value
  54. NO_ERROR always
  55. --*/
  56. {
  57. // validate parameters
  58. if (!pPacket)
  59. return NO_ERROR;
  60. FREE(pPacket);
  61. return NO_ERROR;
  62. }
  63. #ifdef DEBUG
  64. DWORD
  65. PacketDisplay (
  66. IN PPACKET pPacket)
  67. /*++
  68. Routine Description
  69. Displays a packet, it's fields and the buffer.
  70. Locks
  71. None
  72. Arguments
  73. pPacket packet to destroy
  74. Return Value
  75. NO_ERROR always
  76. --*/
  77. {
  78. ULONG i;
  79. CHAR szBuffer[2 * MAX_PACKET_LENGTH + 1]; // buffer in hex
  80. for (i = 0; i < pPacket->wsaBuffer.len; i++)
  81. sprintf(szBuffer + i*2, "%02x", pPacket->rgbyBuffer[i]);
  82. TRACE3(NETWORK, "Packet... Source %s, Length %d, Buffer %s",
  83. INET_NTOA(pPacket->ipSource), pPacket->wsaBuffer.len, szBuffer);
  84. return NO_ERROR;
  85. }
  86. #endif // DEBUG