Nebula
Loading...
Searching...
No Matches
win32ipaddress.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
25#include "core/types.h"
26#include "io/uri.h"
27
28//------------------------------------------------------------------------------
29namespace Win32
30{
32{
33public:
39 Win32IpAddress(const IO::URI& uri);
41 Win32IpAddress(const Util::String& hostName, ushort portNumber);
43 bool operator==(const Win32IpAddress& rhs) const;
45 bool operator<(const Win32IpAddress& rhs) const;
47 bool operator>(const Win32IpAddress& rhs) const;
49 void ExtractFromUri(const IO::URI& uri);
53 const Util::String& GetHostName() const;
55 void SetPort(ushort port);
57 ushort GetPort() const;
59 const Util::String& GetHostAddr() const;
60
61private:
62 friend class Win32Socket;
63
65 Win32IpAddress(const sockaddr_in& addr);
67 void SetSockAddr(const sockaddr_in& addr);
69 const sockaddr_in& GetSockAddr() const;
71 static bool GetHostByName(const Util::String& hostName, in_addr& outAddr);
73 static bool IsInetAddr(const in_addr* addr);
74
77 sockaddr_in addr;
78};
79
80//------------------------------------------------------------------------------
83inline bool
85{
86 return ((this->addr.sin_addr.S_un.S_addr == rhs.addr.sin_addr.S_un.S_addr) &&
87 (this->addr.sin_port == rhs.addr.sin_port));
88}
89
90//------------------------------------------------------------------------------
93inline bool
95{
96 if (this->addr.sin_addr.S_un.S_addr == rhs.addr.sin_addr.S_un.S_addr)
97 {
98 return this->addr.sin_port < rhs.addr.sin_port;
99 }
100 else
101 {
102 return this->addr.sin_addr.S_un.S_addr < rhs.addr.sin_addr.S_un.S_addr;
103 }
104}
105
106//------------------------------------------------------------------------------
109inline bool
111{
112 if (this->addr.sin_addr.S_un.S_addr == rhs.addr.sin_addr.S_un.S_addr)
113 {
114 return this->addr.sin_port > rhs.addr.sin_port;
115 }
116 else
117 {
118 return this->addr.sin_addr.S_un.S_addr > rhs.addr.sin_addr.S_un.S_addr;
119 }
120}
121
122} // namespace Win32
123//------------------------------------------------------------------------------
An URI object can split a Uniform Resource Identifier string into its components or build a string fr...
Definition uri.h:67
Represents an IP address, consisting of a IPv4 host address and a port number.
Definition win32ipaddress.h:32
const Util::String & GetHostName() const
get host name
Definition win32ipaddress.cc:169
void SetPort(ushort port)
set port number
Definition win32ipaddress.cc:129
void SetHostName(const Util::String &hostName)
set host name
Definition win32ipaddress.cc:152
Util::String hostName
Definition win32ipaddress.h:75
const sockaddr_in & GetSockAddr() const
get sockaddr_in field
Definition win32ipaddress.cc:95
sockaddr_in addr
Definition win32ipaddress.h:77
void ExtractFromUri(const IO::URI &uri)
extract host name and port number from URI
Definition win32ipaddress.cc:108
bool operator==(const Win32IpAddress &rhs) const
equality operator
Definition win32ipaddress.h:84
bool operator>(const Win32IpAddress &rhs) const
greater-then operator
Definition win32ipaddress.h:110
ushort GetPort() const
get port number
Definition win32ipaddress.cc:139
static bool GetHostByName(const Util::String &hostName, in_addr &outAddr)
perform address resolution, understands special host names
Definition win32ipaddress.cc:205
void SetSockAddr(const sockaddr_in &addr)
set sockaddr_in directly
Definition win32ipaddress.cc:77
Win32IpAddress()
default constructor
Definition win32ipaddress.cc:18
bool operator<(const Win32IpAddress &rhs) const
less-then operator
Definition win32ipaddress.h:94
const Util::String & GetHostAddr() const
get the ip address resulting from the host name as string
Definition win32ipaddress.cc:179
static bool IsInetAddr(const in_addr *addr)
return true if an address is an internet address (not class A,B,C)
Definition win32ipaddress.cc:284
Util::String addrAsString
Definition win32ipaddress.h:76
A lowlevel socket wrapper class.
Definition win32socket.h:27
[TODO: Describe Win32 subsystem]
Nebula's universal string class.
Definition string.h:50
unsigned short ushort
Definition types.h:32