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.

91 lines
2.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1995 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. FILE HISTORY:
  7. */
  8. #ifndef _IPADDRES_H_
  9. #define _IPADDRES_H_
  10. //
  11. // IP Address Conversion Macros
  12. //
  13. #ifndef MAKEIPADDRESS
  14. #define MAKEIPADDRESS(b1,b2,b3,b4) ((LONG)(((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4))))
  15. #define GETIP_FIRST(x) ((x>>24) & 0xff)
  16. #define GETIP_SECOND(x) ((x>>16) & 0xff)
  17. #define GETIP_THIRD(x) ((x>> 8) & 0xff)
  18. #define GETIP_FOURTH(x) ((x) & 0xff)
  19. #endif // MAKEIPADDRESS
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CIpAddress class
  22. class CIpAddress : public CObjectPlus
  23. {
  24. public:
  25. // Constructors
  26. CIpAddress()
  27. {
  28. m_lIpAddress = 0L;
  29. m_fInitOk = FALSE;
  30. }
  31. CIpAddress (LONG l)
  32. {
  33. m_lIpAddress = l;
  34. m_fInitOk = TRUE;
  35. }
  36. CIpAddress (BYTE b1, BYTE b2, BYTE b3, BYTE b4)
  37. {
  38. m_lIpAddress = (LONG)MAKEIPADDRESS(b1,b2,b3,b4);
  39. m_fInitOk = TRUE;
  40. }
  41. CIpAddress(const CIpAddress& ia)
  42. {
  43. m_lIpAddress = ia.m_lIpAddress;
  44. m_fInitOk = ia.m_fInitOk;
  45. }
  46. CIpAddress (const CString & str);
  47. //
  48. // Assignment operators
  49. //
  50. const CIpAddress & operator =(const LONG l);
  51. const CIpAddress & operator =(const CString & str);
  52. const CIpAddress & operator =(const CIpAddress& ia)
  53. {
  54. m_lIpAddress = ia.m_lIpAddress;
  55. m_fInitOk = ia.m_fInitOk;
  56. return *this;
  57. }
  58. //
  59. // Conversion operators
  60. //
  61. operator const LONG() const
  62. {
  63. return m_lIpAddress;
  64. }
  65. operator const CString&() const;
  66. public:
  67. BOOL IsValid() const
  68. {
  69. return m_fInitOk;
  70. }
  71. protected:
  72. BOOL IsValidIp(const CString & str);
  73. private:
  74. LONG m_lIpAddress;
  75. BOOL m_fInitOk;
  76. };
  77. #endif _IPADDRES_H