Panda3D
netAddress.h
1 // Filename: netAddress.h
2 // Created by: drose (08Feb00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef NETADDRESS_H
16 #define NETADDRESS_H
17 
18 #include "pandabase.h"
19 #include "numeric_types.h"
20 #include "socket_address.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : NetAddress
24 // Description : Represents a network address to which UDP packets may
25 // be sent or to which a TCP socket may be bound.
26 ////////////////////////////////////////////////////////////////////
27 class EXPCL_PANDA_NET NetAddress {
28 PUBLISHED:
29  NetAddress();
30  NetAddress(const Socket_Address &addr);
31 
32  bool set_any(int port);
33  bool set_localhost(int port);
34  bool set_broadcast(int port);
35  bool set_host(const string &hostname, int port);
36 
37  void clear();
38 
39  int get_port() const;
40  void set_port(int port);
41  string get_ip_string() const;
42  PN_uint32 get_ip() const;
43  PN_uint8 get_ip_component(int n) const;
44 
45  const Socket_Address &get_addr() const;
46 
47  void output(ostream &out) const;
48 
49  size_t get_hash() const;
50  bool operator == (const NetAddress &other) const;
51  bool operator != (const NetAddress &other) const;
52 
53 private:
54  Socket_Address _addr;
55 };
56 
57 INLINE ostream &operator << (ostream &out, const NetAddress &addr) {
58  addr.output(out);
59  return out;
60 }
61 
62 #endif
63 
A simple place to store and munipulate tcp and port address for communication layer.
Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound...
Definition: netAddress.h:27