34 #ifndef PTLIB_IPSOCKET_H 35 #define PTLIB_IPSOCKET_H 45 #ifdef P_KNOCKOUT_WINSOCK2 47 #endif // KNOCKOUT_WINSOCK2 89 Address(PINDEX len,
const BYTE * bytes);
92 Address(BYTE b1, BYTE b2, BYTE b3, BYTE b4);
101 Address(
const in6_addr & addr);
107 Address(
const int ai_family,
const int ai_addrlen,
struct sockaddr *ai_addr);
109 #ifdef __NUCLEUS_NET__ 110 Address(
const struct id_struct & addr);
170 bool bracketIPv6 =
false 182 operator in_addr()
const;
185 operator in6_addr()
const;
190 operator DWORD()
const;
289 static void SetDefaultIpAddressFamilyV6();
290 static PBoolean IsIpAddressFamilyV6Supported();
292 static void SetDefaultV6ScopeId(
int scopeId);
293 static int GetDefaultV6ScopeId();
316 int ipAdressFamily=PF_INET
369 unsigned queueSize = 5,
375 unsigned queueSize = 5,
561 static unsigned AsNumeric(
Address addr);
627 virtual void Cancel() = 0;
681 static void SanitiseName(
PString & name);
699 InterfaceTable & table,
716 {
if (!
SetOption(IP_PKTINFO, 1, SOL_IP))
return false; catchReceiveToAddr =
true;
return true; }
721 {
return lastReceiveToAddr; }
724 void SetLastReceiveAddr(
void * addr,
int addrLen)
725 {
if (addrLen ==
sizeof(in_addr)) lastReceiveToAddr = *(in_addr *)addr; }
747 #include "msos/ptlib/ipsock.h" 749 #include "unix/ptlib/ipsock.h" 757 : m_port(0), m_separator(
':')
761 : m_port(0), m_separator(separator)
765 : m_port(defaultPort), m_separator(separator)
766 { Parse(str, defaultPort, m_separator); }
768 PBoolean Parse(
const PString & str, WORD defaultPort = 0,
char separator =
':');
783 bool IsValid()
const {
return m_address.IsValid() && m_port != 0; }
799 #endif // PTLIB_IPSOCKET_H Class for detector of Route Table changes.
Definition: ipsock.h:620
static const Address GetBroadcast(int version=4)
PString interfaceName
Definition: ipsock.h:602
BYTE Byte3() const
Return third byte of IPv4 address.
BYTE operator[](PINDEX idx) const
Return specified byte of IPv4 or IPv6 address.
static PString GetGatewayInterface(int version=4)
Get the name for the interface that is being used as the gateway, that is, the interface that packets...
virtual PBoolean Listen(unsigned queueSize=5, WORD port=0, Reusability reuse=AddressIsExclusive)
Listen on a socket for a remote host on the specified port number.
Address net_mask
Definition: ipsock.h:600
Address GetNetwork() const
Get the network address associated with the route table entry.
Definition: ipsock.h:584
Definition: object.h:1186
bool operator!=(in_addr &addr) const
Definition: ipsock.h:138
PBoolean IsMulticast() const
Check if address is multicast group.
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:55
bool operator==(const Address &addr) const
Definition: ipsock.h:131
bool operator!=(DWORD dw) const
Definition: ipsock.h:140
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
static int GetDefaultIpAddressFamily()
Set the default IP address familly.
PBoolean FromString(const PString &str)
Convert string to IP address. Returns true if was a valid address.
static PBoolean IsLocalHost(const PString &hostname)
Determine if the specified host is actually the local machine.
static PBoolean GetGatewayAddress(Address &addr, int version=4)
Get the IP address that is being used as the gateway, that is, the computer that packets on the defau...
friend ostream & operator<<(ostream &s, const Address &a)
Output IPv6 & IPv4 address as a string to the specified string.
bool operator!=(const Address &addr) const
Definition: ipsock.h:132
static RouteTableDetector * CreateRouteTableDetector()
Create an object that can wait for a change in the route table or active network interfaces.
PBoolean IsBroadcast() const
Check for Broadcast address 255.255.255.255.
Describe an interface table entry.
Definition: ipsock.h:642
static PBoolean GetHostAddress(Address &addr)
Get the Internet Protocol address for the specified host, or if none specified, for the host this pro...
static const Address & GetAny(int version=4)
This class describes a type of socket that will communicate using the Internet Protocol.
Definition: ipsock.h:63
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:1184
Address m_netMask
Definition: ipsock.h:686
virtual PString GetLocalAddress()
Get the Internet Protocol address and port for the local host.
friend istream & operator>>(istream &s, Address &a)
Input IPv4 (not IPv6 yet!) address as a string from the specified string.
Address m_ipAddress
Definition: ipsock.h:685
const PString & GetInterface() const
Get the network address name associated with the route table entry.
Definition: ipsock.h:593
static void SetSuppressCanonicalName(bool suppress)
Set flag for suppress getting canonical name when doing lookup via hostname.
This is an array collection class of PString objects.
Definition: pstring.h:2024
PINDEX GetSize() const
Get the address length (will be either 4 or 16).
WORD port
Port to be used by the socket when opening the channel.
Definition: socket.h:444
PString GetPeerHostName()
Get the host name for the peer host the socket is connected to.
unsigned GetVersion() const
Get the version of the IP address being used.
Definition: ipsock.h:214
virtual PString GetName() const
Get the platform and I/O channel type name of the channel.
static bool GetSuppressCanonicalName()
Get flag for suppress getting canonical name when doing lookup via hostname.
PIPSocketAddressAndPort(char separator)
Definition: ipsock.h:760
in_addr four
Definition: ipsock.h:254
BYTE Byte1() const
Return first byte of IPv4 address.
PString m_macAddress
Definition: ipsock.h:687
BYTE Byte4() const
Return fourth byte of IPv4 address.
BOOL PBoolean
Definition: object.h:102
static PBoolean GetRouteTable(RouteTable &table)
Get the systems route table.
PBoolean IsRFC1918() const
Check if the remote address is a private address.
PIPSocketAddressAndPort(const PString &str, WORD defaultPort=0, char separator= ':')
Definition: ipsock.h:764
static PIPSocket::Address GetRouteInterfaceAddress(PIPSocket::Address remoteAddress)
Get the interface address that will be used to reach the specified remote address.
RouteEntry(const Address &addr)
Create a route table entry from an IP address.
Definition: ipsock.h:581
Address GetAddress() const
Get the address associated with the interface.
Definition: ipsock.h:672
WORD m_port
Definition: ipsock.h:792
PString GetLocalHostName()
Get the host name for the local host.
PIPSocket()
Create a new Internet Protocol socket based on the port number specified.
Describe a route table entry.
Definition: ipsock.h:576
static PBoolean GetNetworkInterface(PIPSocket::Address &addr)
Get the address of an interface that corresponds to a real network.
BYTE Byte2() const
Return second byte of IPv4 address.
PString m_name
Definition: ipsock.h:684
Address GetDestination() const
Get the default gateway address associated with the route table entry.
Definition: ipsock.h:590
union PIPSocket::Address::@5 v
Runtime test of IP addresse type.
static PStringArray GetHostAliases(const PString &hostname)
Get the alias host names for the specified host.
unsigned version
Definition: ipsock.h:259
bool IsValid() const
Definition: ipsock.h:783
virtual PBoolean OpenSocket()=0
virtual PBoolean Connect(const PString &address)
Connect a socket to a remote host on the specified port number.
virtual ~RouteTableDetector()
Definition: ipsock.h:623
const char * GetPointer() const
Get the pointer to IP address data.
Definition: ipsock.h:211
WORD GetPort() const
Definition: ipsock.h:778
PIPSocket::Address m_address
Definition: ipsock.h:791
bool operator*=(const Address &addr) const
Compare two addresses for equivalence.
Definition: ipsock.h:165
static void SetDefaultIpAddressFamilyV4()
Address destination
Definition: ipsock.h:601
PARRAY(RouteTable, RouteEntry)
long GetMetric() const
Get the network metric associated with the route table entry.
Definition: ipsock.h:596
long metric
Definition: ipsock.h:603
static void ClearNameCache()
Clear the name (DNS) cache.
The character string class.
Definition: pstring.h:108
std::vector< PIPSocketAddressAndPort > PIPSocketAddressAndPortVector
Definition: ipsock.h:796
bool operator!=(int i) const
Definition: ipsock.h:158
void SetPort(WORD port)
Definition: ipsock.h:779
friend ostream & operator<<(ostream &strm, const PIPSocketAddressAndPort &ap)
Definition: ipsock.h:785
const PIPSocket::Address & GetAddress() const
Definition: ipsock.h:777
static const Address & GetLoopback(int version=4)
Comparison Compare(const PObject &obj) const
Compare two adresses for absolute (in)equality.
Definition: pstring.h:286
PIPSocket::Address GetLastReceiveToAddress() const
Return the interface address of the last incoming packet.
Definition: ipsock.h:740
static PIPSocket::Address GetDefaultIpAny()
Address & operator=(const in_addr &addr)
Copy an address from another IP v4 address.
A class describing an IP address.
Definition: ipsock.h:75
PBoolean IsLoopback() const
Check address 127.0.0.1 or ::1.
Address GetNetMask() const
Get the network address mask associated with the route table entry.
Definition: ipsock.h:587
PString AsString(char separator=0) const
Definition: ipsock.h:770
Address GetNetMask() const
Get the net mask associated with the interface.
Definition: ipsock.h:675
virtual PString GetPeerAddress()
Get the Internet Protocol address for the peer host and port the socket is connected to...
bool operator==(int i) const
Definition: ipsock.h:157
Address network
Definition: ipsock.h:599
PString AsString(bool bracketIPv6=false) const
Format an address as a string.
static PBoolean GetInterfaceTable(InterfaceTable &table, PBoolean includeDown=false)
Get a list of all interfaces.
const PString & GetName() const
Get the name of the interface.
Definition: ipsock.h:669
static PString GetHostName()
Get the "official" host name for the host specified or if none, the host this process is running on...
A network communications channel.
Definition: socket.h:58
const PString & GetMACAddress() const
Get the MAC address associate with the interface.
Definition: ipsock.h:678
PBoolean SetCaptureReceiveToAddress()
Set flag to capture interface address for incoming packets.
Definition: ipsock.h:735
PIPSocketAddressAndPort()
Definition: ipsock.h:756
Reusability
Flags to reuse of port numbers in Listen() function.
Definition: socket.h:84
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PBoolean SetOption(int option, int value, int level=SOL_SOCKET)
Set options on the socket.
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
static void SetDefaultIpAddressFamily(int ipAdressFamily)
PBoolean IsValid() const
Check address 0.0.0.0 or ::.
Address()
Create an IPv4 address with the default address: 127.0.0.1 (loopback).
char m_separator
Definition: ipsock.h:793