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.

102 lines
2.6 KiB

  1. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  2. /*---------------------------------------------------------
  3. Filename: vbl.cpp
  4. Written By: B.Rajeev
  5. ----------------------------------------------------------*/
  6. #include "precomp.h"
  7. #include <typeinfo.h>
  8. #include "common.h"
  9. #include "encap.h"
  10. #include "vbl.h"
  11. #include <winsock.h>
  12. #define IP_ADDR_LEN 4
  13. #define BYTE_SIZE 8
  14. #define BYTE_ON_FLAG 255
  15. VBList::VBList(
  16. IN SnmpEncodeDecode &a_SnmpEncodeDecode ,
  17. IN SnmpVarBindList &var_bind_list ,
  18. IN ULONG index
  19. ) : var_bind_list ( NULL )
  20. {
  21. m_Index = index ;
  22. VBList::var_bind_list = &var_bind_list;
  23. // Extract session from EncodeDecode object
  24. WinSNMPSession t_Session = NULL ;
  25. SnmpV1EncodeDecode *t_SnmpV1EncodeDecode = dynamic_cast<SnmpV1EncodeDecode *>(&a_SnmpEncodeDecode);
  26. if ( t_SnmpV1EncodeDecode )
  27. {
  28. t_Session = ( HSNMP_SESSION ) t_SnmpV1EncodeDecode->GetWinSnmpSession () ;
  29. }
  30. else
  31. {
  32. SnmpV2CEncodeDecode *t_SnmpV2CEncodeDecode = dynamic_cast<SnmpV2CEncodeDecode *>(&a_SnmpEncodeDecode);
  33. if ( t_SnmpV2CEncodeDecode )
  34. {
  35. t_Session = ( HSNMP_SESSION ) t_SnmpV2CEncodeDecode->GetWinSnmpSession () ;
  36. }
  37. else
  38. {
  39. throw ;
  40. }
  41. }
  42. }
  43. // the VarBindList and the WinSnmpVbl are indexed differently.
  44. // [0..(length-1)] [1..length]
  45. // the parameter index refers to the WinSnmpVbl index
  46. SnmpVarBind *VBList::Get(IN UINT vbl_index)
  47. {
  48. UINT length = var_bind_list->GetLength();
  49. if ( vbl_index > length )
  50. return NULL;
  51. SnmpVarBind *var_bind = new SnmpVarBind(*((*var_bind_list)[vbl_index-1]));
  52. return var_bind;
  53. }
  54. // the VarBindList and the WinSnmpVbl are indexed differently.
  55. // [0..(length-1)] [1..length]
  56. // the parameter index refers to the WinSnmpVbl index
  57. SnmpVarBind *VBList::Remove(IN UINT vbl_index)
  58. {
  59. UINT length = var_bind_list->GetLength();
  60. if ( vbl_index > length )
  61. return NULL;
  62. SnmpVarBind *var_bind = new SnmpVarBind(*((*var_bind_list)[vbl_index-1]));
  63. var_bind_list->Remove();
  64. return var_bind;
  65. }
  66. // the VarBindList and the WinSnmpVbl are indexed differently.
  67. // [0..(length-1)] [1..length]
  68. // the parameter index refers to the WinSnmpVbl index
  69. void VBList::Delete(IN UINT vbl_index)
  70. {
  71. UINT length = var_bind_list->GetLength();
  72. if ( vbl_index > length )
  73. return ;
  74. var_bind_list->Remove();
  75. }
  76. VBList::~VBList(void)
  77. {
  78. delete var_bind_list;
  79. }