Panda3D
Loading...
Searching...
No Matches
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 */
25class EXPCL_PANDA_NATIVENET Socket_Address {
26public:
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
34PUBLISHED:
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
63private:
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
sa_family_t get_family() const
Returns AF_INET if this is an IPv4 address, or AF_INET6 if this is an IPv6 address.
bool set_host(const std::string &hostname, unsigned short port)
This function will take a port and string-based TCP address and initialize the address with this info...
bool set_broadcast(unsigned short port)
Set to the broadcast address and a specified port.
void clear()
Set the internal values to a suitable known value.
bool is_mcast_range() const
True if the address is in the multicast range.
bool set_any_IPv6(unsigned short port)
Set to any IPv6 address and a specified port.
std::string get_ip() const
Return the IP address portion in dot notation string.
unsigned long GetIPAddressRaw() const
Returns a raw 32-bit unsigned integer representing the IPv4 address.
bool is_any() const
True if the address is zero.
bool set_any_IP(unsigned short port)
Set to any address and a specified port.
std::string get_ip_port() const
Return the ip address/port in dot notation string.
unsigned short get_port() const
Get the port portion as an integer.
bool set_port(unsigned short port)
Set to a specified port.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.