MLIB
Loading...
Searching...
No Matches
mlib::inaddr Class Reference

sockaddr wrapper More...

#include <inaddr.h>

Public Member Functions

 inaddr (unsigned long host=INADDR_ANY, unsigned short port=0)
 Fill sockaddr structure with host number and port.
 
 inaddr (const std::string &hostname, unsigned short port)
 Fill sockaddr structure after resolving hostname.
 
 inaddr (const std::string &hostname, const std::string &service, const std::string &proto=std::string())
 Fill sockaddr structure after resolving host and service names.
 
 inaddr (const sockaddr &adr)
 Construct from a sockaddr structure.
 
inaddroperator= (const inaddr &rhs)
 Assignment operator.
 
 operator sockaddr * () const
 convert to a pointer to sockaddr
 
bool operator== (const inaddr &other) const
 Equality operator.
 
bool operator!= (const inaddr &other) const
 Inequality operator.
 
 operator const sockaddr & () const
 convert to a reference to sockaddr (const variant)
 
 operator sockaddr & ()
 convert to a reference to sockaddr (nonconst variant)
 
unsigned short port () const
 return port number in host order
 
void port (unsigned short p)
 set port number
 
erc port (const std::string &service, const std::string &proto=std::string())
 set port number based on well-known service ports
 
unsigned host () const
 return host address in host order
 
void host (unsigned int h)
 set host address
 
erc host (const std::string &hostname)
 Set host address after resolving name.
 
std::string hostname () const
 Find hostname from the host address in sockaddr.
 
const char * ntoa () const
 return host address in dotted format
 
bool is_multicast () const
 check if it's multicast host
 

Static Public Member Functions

static unsigned localhost ()
 Return local address in HOST order.
 

Detailed Description

sockaddr wrapper

This is a wrapper for sockaddr structure, providing functions that go between host and network order.

All parameters and returned values are in host order.

Constructor & Destructor Documentation

◆ inaddr() [1/2]

mlib::inaddr::inaddr ( unsigned long  host = INADDR_ANY,
unsigned short  port = 0 
)

Fill sockaddr structure with host number and port.

Parameters are in HOST order

◆ inaddr() [2/2]

mlib::inaddr::inaddr ( const std::string &  hostname,
const std::string &  service,
const std::string &  proto = std::string () 
)

Fill sockaddr structure after resolving host and service names.

Parameters
hostnamehost name or IP address
servicewell-known service or port number
protoservice protocol

Member Function Documentation

◆ port()

erc mlib::inaddr::port ( const std::string &  service,
const std::string &  proto = std::string () 
)

set port number based on well-known service ports

Parameters
serviceservice name
protoprotocol name

The name parameter can be either one of the well-known service names or a numeric port value. If it is a numeric value, the function converts it to a port number using the strtoul function.


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