Panda3D
socket_address.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file socket_address.h
10  * @author rdb
11  * @date 2014-10-19
12  */
13 
14 #ifndef SOCKET_ADDRESS_H
15 #define SOCKET_ADDRESS_H
16 
17 #include "pandabase.h"
18 #include "numeric_types.h"
19 #include "socket_portable.h"
20 
21 /**
22  * A simple place to store and manipulate tcp and port address for
23  * communication layer
24  */
25 class EXPCL_PANDA_NATIVENET Socket_Address {
26 public:
27  INLINE Socket_Address(const struct sockaddr &inaddr);
28  INLINE Socket_Address(const struct sockaddr_in &inaddr);
29  INLINE Socket_Address(const struct sockaddr_in6 &inaddr);
30  INLINE Socket_Address(const struct sockaddr_storage &inaddr);
31  INLINE struct sockaddr &GetAddressInfo() { return _addr; }
32  INLINE const struct sockaddr &GetAddressInfo() const { return _addr; }
33 
34 PUBLISHED:
35  INLINE explicit Socket_Address(unsigned short port = 0);
36  INLINE Socket_Address(const Socket_Address &inaddr);
37 
38  INLINE virtual ~Socket_Address();
39 
40  INLINE bool set_any_IP(unsigned short port);
41  INLINE bool set_any_IPv6(unsigned short port);
42  INLINE bool set_port(unsigned short port);
43  INLINE bool set_broadcast(unsigned short port);
44 
45  bool set_host(const std::string &hostname, unsigned short port);
46  bool set_host(const std::string &hostname);
47  INLINE bool set_host(uint32_t ip4addr, unsigned short port);
48  INLINE void clear();
49 
50  INLINE sa_family_t get_family() const;
51  INLINE unsigned short get_port() const;
52  std::string get_ip() const ;
53  std::string get_ip_port() const;
54  unsigned long GetIPAddressRaw() const;
55 
56  INLINE bool operator ==(const Socket_Address &in) const;
57  INLINE bool operator !=(const Socket_Address &in) const;
58  INLINE bool operator < (const Socket_Address &in) const;
59 
60  INLINE bool is_any() const;
61  INLINE bool is_mcast_range() const;
62 
63 private:
64  union {
65  sockaddr _addr;
66  sockaddr_in _addr4;
67  sockaddr_in6 _addr6;
68  sockaddr_storage _storage;
69  };
70 };
71 
72 #include "socket_address.I"
73 
74 #endif // SOCKET_ADDRESS_H
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A simple place to store and manipulate tcp and port address for communication layer.