netAddress.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Filename: netAddress.h
  2. // Created by: drose (08Feb00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef NETADDRESS_H
  19. #define NETADDRESS_H
  20. #include "pandabase.h"
  21. #include "numeric_types.h"
  22. #include <prio.h>
  23. ////////////////////////////////////////////////////////////////////
  24. // Class : NetAddress
  25. // Description : Represents a network address to which UDP packets may
  26. // be sent or to which a TCP socket may be bound.
  27. ////////////////////////////////////////////////////////////////////
  28. class EXPCL_PANDA NetAddress {
  29. PUBLISHED:
  30. NetAddress();
  31. NetAddress(const PRNetAddr &addr);
  32. bool set_any(int port);
  33. bool set_localhost(int port);
  34. bool set_host(const string &hostname, int port);
  35. void clear();
  36. int get_port() const;
  37. void set_port(int port);
  38. string get_ip_string() const;
  39. PN_uint32 get_ip() const;
  40. PN_uint8 get_ip_component(int n) const;
  41. PRNetAddr *get_addr() const;
  42. void output(ostream &out) const;
  43. private:
  44. PRNetAddr _addr;
  45. };
  46. INLINE ostream &operator << (ostream &out, const NetAddress &addr) {
  47. addr.output(out);
  48. return out;
  49. }
  50. #endif