Panda3D
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Socket_Address Class Reference

A simple place to store and manipulate tcp and port address for communication layer. More...

#include "socket_address.h"

Public Member Functions

 Socket_Address (const Socket_Address &inaddr)
 
 Socket_Address (const struct sockaddr &inaddr)
 
 Socket_Address (const struct sockaddr_in &inaddr)
 
 Socket_Address (const struct sockaddr_in6 &inaddr)
 
 Socket_Address (const struct sockaddr_storage &inaddr)
 
 Socket_Address (unsigned short port=0)
 Constructor that lets us set a port value.
 
virtual ~Socket_Address ()
 Normal Destructor.
 
void clear ()
 Set the internal values to a suitable known value.
 
sa_family_t get_family () const
 Returns AF_INET if this is an IPv4 address, or AF_INET6 if this is an IPv6 address.
 
std::string get_ip () const
 Return the IP address portion in dot notation string.
 
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.
 
struct sockaddr & GetAddressInfo ()
 
const struct sockaddr & GetAddressInfo () const
 
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 is_mcast_range () const
 True if the address is in the multicast range.
 
bool operator!= (const Socket_Address &in) const
 
bool operator< (const Socket_Address &in) const
 
bool operator== (const Socket_Address &in) const
 
bool set_any_IP (unsigned short port)
 Set to any address and a specified port.
 
bool set_any_IPv6 (unsigned short port)
 Set to any IPv6 address and a specified port.
 
bool set_broadcast (unsigned short port)
 Set to the broadcast address and a specified port.
 
bool set_host (const std::string &hostname)
 Initializes the address from a string specifying both the address and port, separated by a colon.
 
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 information.
 
bool set_host (uint32_t ip4addr, unsigned short port)
 
bool set_port (unsigned short port)
 Set to a specified port.
 

Detailed Description

A simple place to store and manipulate tcp and port address for communication layer.

Definition at line 25 of file socket_address.h.

Constructor & Destructor Documentation

◆ Socket_Address() [1/6]

Socket_Address::Socket_Address ( const struct sockaddr & inaddr)
inline

Definition at line 37 of file socket_address.I.

◆ Socket_Address() [2/6]

Socket_Address::Socket_Address ( const struct sockaddr_in & inaddr)
inline

Definition at line 54 of file socket_address.I.

◆ Socket_Address() [3/6]

Socket_Address::Socket_Address ( const struct sockaddr_in6 & inaddr)
inline

Definition at line 62 of file socket_address.I.

◆ Socket_Address() [4/6]

Socket_Address::Socket_Address ( const struct sockaddr_storage & inaddr)
inline

Definition at line 76 of file socket_address.I.

◆ Socket_Address() [5/6]

Socket_Address::Socket_Address ( unsigned short port = 0)
inlineexplicit

Constructor that lets us set a port value.

Definition at line 19 of file socket_address.I.

◆ Socket_Address() [6/6]

Socket_Address::Socket_Address ( const Socket_Address & inaddr)
inline

Definition at line 29 of file socket_address.I.

◆ ~Socket_Address()

Socket_Address::~Socket_Address ( )
inlinevirtual

Normal Destructor.

Definition at line 84 of file socket_address.I.

Member Function Documentation

◆ clear()

void Socket_Address::clear ( )
inline

Set the internal values to a suitable known value.

Definition at line 167 of file socket_address.I.

Referenced by NetAddress::clear().

◆ get_family()

sa_family_t Socket_Address::get_family ( ) const
inline

Returns AF_INET if this is an IPv4 address, or AF_INET6 if this is an IPv6 address.

Definition at line 178 of file socket_address.I.

Referenced by Socket_TCP::ActiveOpen(), Socket_TCP::ActiveOpenNonBlocking(), Socket_UDP_Incoming::OpenForInput(), Socket_UDP_Incoming::OpenForInputMCast(), and Socket_TCP_Listen::OpenForListen().

◆ get_ip()

std::string Socket_Address::get_ip ( ) const

Return the IP address portion in dot notation string.

Definition at line 89 of file socket_address.cxx.

Referenced by NetAddress::get_ip_string().

◆ get_ip_port()

std::string Socket_Address::get_ip_port ( ) const

Return the ip address/port in dot notation string.

If this is an IPv6 address, it will be enclosed in square brackets.

Definition at line 111 of file socket_address.cxx.

References get_port().

◆ get_port()

unsigned short Socket_Address::get_port ( ) const
inline

Get the port portion as an integer.

Definition at line 186 of file socket_address.I.

Referenced by get_ip_port(), NetAddress::get_port(), and Socket_UDP_Incoming::OpenForInputMCast().

◆ GetAddressInfo() [1/2]

struct sockaddr & Socket_Address::GetAddressInfo ( )
inline

Definition at line 31 of file socket_address.h.

◆ GetAddressInfo() [2/2]

const struct sockaddr & Socket_Address::GetAddressInfo ( ) const
inline

Definition at line 32 of file socket_address.h.

◆ GetIPAddressRaw()

unsigned long Socket_Address::GetIPAddressRaw ( ) const

Returns a raw 32-bit unsigned integer representing the IPv4 address.

Definition at line 137 of file socket_address.cxx.

Referenced by NetAddress::get_ip(), and NetAddress::get_ip_component().

◆ is_any()

bool Socket_Address::is_any ( ) const
inline

True if the address is zero.

Definition at line 234 of file socket_address.I.

Referenced by NetAddress::is_any().

◆ is_mcast_range()

bool Socket_Address::is_mcast_range ( ) const
inline

True if the address is in the multicast range.

Definition at line 250 of file socket_address.I.

◆ operator!=()

bool Socket_Address::operator!= ( const Socket_Address & in) const
inline

Definition at line 116 of file socket_address.I.

◆ operator<()

bool Socket_Address::operator< ( const Socket_Address & in) const
inline

Definition at line 205 of file socket_address.I.

◆ operator==()

bool Socket_Address::operator== ( const Socket_Address & in) const
inline

Definition at line 91 of file socket_address.I.

◆ set_any_IP()

bool Socket_Address::set_any_IP ( unsigned short port)
inline

Set to any address and a specified port.

Definition at line 135 of file socket_address.I.

Referenced by Socket_UDP_Incoming::OpenForInput(), Socket_TCP_Listen::OpenForListen(), and NetAddress::set_any().

◆ set_any_IPv6()

bool Socket_Address::set_any_IPv6 ( unsigned short port)
inline

Set to any IPv6 address and a specified port.

Definition at line 146 of file socket_address.I.

Referenced by Socket_UDP_Incoming::OpenForInput(), and Socket_TCP_Listen::OpenForListen().

◆ set_broadcast()

bool Socket_Address::set_broadcast ( unsigned short port)
inline

Set to the broadcast address and a specified port.

Definition at line 124 of file socket_address.I.

Referenced by NetAddress::set_broadcast(), and set_host().

◆ set_host() [1/3]

bool Socket_Address::set_host ( const std::string & hostname)

Initializes the address from a string specifying both the address and port, separated by a colon.

An IPv6 address must be enclosed in brackets.

Definition at line 50 of file socket_address.cxx.

References set_host().

◆ set_host() [2/3]

bool Socket_Address::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 information.

Returns true on success; on failure, it returns false and the address may be undefined.

Definition at line 22 of file socket_address.cxx.

References set_broadcast().

Referenced by ConnectionManager::scan_interfaces(), set_host(), NetAddress::set_host(), and NetAddress::set_localhost().

◆ set_host() [3/3]

bool Socket_Address::set_host ( uint32_t ip4addr,
unsigned short port )
inline

Definition at line 194 of file socket_address.I.

◆ set_port()

bool Socket_Address::set_port ( unsigned short port)
inline

Set to a specified port.

Definition at line 158 of file socket_address.I.

Referenced by NetAddress::set_port().

Member Data Documentation

◆ _addr

sockaddr Socket_Address::_addr

Definition at line 65 of file socket_address.h.

◆ _addr4

sockaddr_in Socket_Address::_addr4

Definition at line 66 of file socket_address.h.

◆ _addr6

sockaddr_in6 Socket_Address::_addr6

Definition at line 67 of file socket_address.h.

◆ _storage

sockaddr_storage Socket_Address::_storage

Definition at line 68 of file socket_address.h.


The documentation for this class was generated from the following files: