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.

59 lines
1.3 KiB

  1. // host.h
  2. //
  3. #include "stdpch.h"
  4. #pragma once
  5. class CHost
  6. {
  7. public:
  8. CHost() : m_ulAddr(INADDR_NONE) {};
  9. CHost(LPCTSTR szHost) : m_szHost(szHost), m_ulAddr(INADDR_NONE) {};
  10. operator unsigned long ()
  11. {
  12. if (m_ulAddr == INADDR_NONE)
  13. {
  14. char szHost[128];
  15. hostent * hp;
  16. unsigned long ulAddr;
  17. if (!m_szHost || !*m_szHost)
  18. return INADDR_NONE;
  19. #ifdef UNICODE
  20. wcstombs(szHost, m_szHost, 128);
  21. #else
  22. strcpy(szHost, m_szHost);
  23. #endif
  24. if ((ulAddr = inet_addr(szHost)) == INADDR_NONE)
  25. {
  26. if ((hp = gethostbyname(szHost)) != NULL)
  27. {
  28. memcpy(&(m_ulAddr),hp->h_addr,hp->h_length);
  29. return m_ulAddr;
  30. }
  31. return INADDR_NONE;
  32. }
  33. else
  34. {
  35. m_ulAddr = ulAddr;
  36. return m_ulAddr;
  37. }
  38. }
  39. else
  40. return m_ulAddr;
  41. }
  42. LPCTSTR GetHost() { return m_szHost; }
  43. void SetHost(LPCTSTR szHost)
  44. {
  45. m_szHost = szHost;
  46. m_ulAddr = INADDR_NONE;
  47. }
  48. tstring m_strDescription;
  49. protected:
  50. tstring m_szHost;
  51. ULONG m_ulAddr;
  52. };