11#if __has_include("defs.h")
15#include "safe_winsock.h"
29 const std::string& proto = std::string ());
31 inaddr (
const sockaddr& adr);
35 operator sockaddr* ()
const
37 return (sockaddr*)&sa;
43 operator const sockaddr& ()
const
45 return *(sockaddr*)&sa;
51 return *(sockaddr*)&sa;
55 unsigned short port ()
const
57 return ntohs (sa.sin_port);
61 void port (
unsigned short p)
63 sa.sin_port = htons (p);
67 erc port (
const std::string& service,
const std::string& proto = std::string ());
72 return ntohl (sa.sin_addr.s_addr);
78 sa.sin_addr.s_addr = htonl (h);
86 const char*
ntoa ()
const;
91 return ((
host () & 0xf0000000) == 0xe0000000);
103 memcpy (&sa, &rhs.sa, sizeof (sa));
110 return (sa.sin_addr.S_un.S_addr == other.sa.sin_addr.S_un.S_addr)
111 && (sa.sin_port == other.sa.sin_port);
117 return (!
operator== (other));
125 return std::string (addr.
ntoa ()) +
':' + std::to_string(addr.
port ());
objects returned as a function result or thrown directly.
Definition errorcode.h:73
Wrapper for sockaddr structure.
Definition inaddr.h:24
static unsigned localhost()
Return local address in HOST order.
Definition inaddr.cpp:155
void host(unsigned int h)
set host address
Definition inaddr.h:76
std::string hostname() const
Find hostname from the host address in sockaddr.
Definition inaddr.cpp:132
void port(unsigned short p)
set port number
Definition inaddr.h:61
const char * ntoa() const
return host address in dotted format
Definition inaddr.cpp:191
inaddr(unsigned long host=INADDR_ANY, unsigned short port=0)
Fill sockaddr structure with host number and port.
Definition inaddr.cpp:26
unsigned short port() const
return port number in host order
Definition inaddr.h:55
unsigned host() const
return host address in host order
Definition inaddr.h:70
inaddr & operator=(const inaddr &rhs)
Assignment operator.
Definition inaddr.h:101
bool operator!=(const inaddr &other) const
Inequality operator.
Definition inaddr.h:115
bool is_multicast() const
check if it's multicast host
Definition inaddr.h:89
bool operator==(const inaddr &other) const
Equality operator.
Definition inaddr.h:108
Definition of mlib::erc and mlib::errfac classes.
std::ostream & operator<<(std::ostream &strm, const mlib::inaddr &addr)
Serialize an address as '<hostname>:<port>'.
Definition inaddr.h:128
std::string to_string(const mlib::inaddr &addr)
Convert an address to a string in format '<hostname>:<port>
Definition inaddr.h:123