InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
Classes | Functions
irc::sockets Namespace Reference

Classes

struct  cidr_mask
 
union  sockaddrs
 

Functions

CoreExport bool MatchCIDR (const std::string &address, const std::string &cidr_mask, bool match_with_username)
 
int sa_size (const irc::sockets::sockaddrs &sa)
 
CoreExport bool aptosa (const std::string &addr, int port, irc::sockets::sockaddrs &sa)
 
CoreExport bool satoap (const irc::sockets::sockaddrs &sa, std::string &addr, int &port)
 
std::string satouser (const irc::sockets::sockaddrs &sa)
 

Detailed Description

This namespace contains various protocol-independent helper classes. It also contains some types which are often used by the core and modules in place of inet_* functions and types.

Function Documentation

bool irc::sockets::aptosa ( const std::string &  addr,
int  port,
irc::sockets::sockaddrs sa 
)

Convert an address-port pair into a binary sockaddr

Parameters
addrThe IP address, IPv4 or IPv6
portThe port, 0 for unspecified
saThe structure to place the result in. Will be zeroed prior to conversion
Returns
true if the conversion was successful, false if not.
bool irc::sockets::MatchCIDR ( const std::string &  address,
const std::string &  cidr_mask,
bool  match_with_username 
)

Match CIDR, including an optional username/nickname part.

This function will compare a human-readable address (plus optional username and nickname) against a human-readable CIDR mask, for example joe!bloggs@1.2.3.4 against *!bloggs@1.2.0.0/16. This method supports both IPV4 and IPV6 addresses.

Parameters
addressThe human readable address, e.g. fred@1.2.3.4
cidr_maskThe human readable mask, e.g. *@1.2.0.0/16
match_with_usernameDoes the mask include a nickname segment?
Returns
True if the mask matches the address
int irc::sockets::sa_size ( const irc::sockets::sockaddrs sa)
inline

Return the size of the structure for syscall passing

bool irc::sockets::satoap ( const irc::sockets::sockaddrs sa,
std::string &  addr,
int &  port 
)

Convert a binary sockaddr to an address-port pair

Parameters
saThe structure to convert
addrthe IP address
portthe port
Returns
true if the conversion was successful, false if unknown address family
std::string irc::sockets::satouser ( const irc::sockets::sockaddrs sa)
inline

Convert a binary sockaddr to a user-readable string. This means IPv6 addresses are written as [::1]:6667, and *:6668 is used for 0.0.0.0:6668

Parameters
saThe structure to convert
Returns
The string; "<unknown>" if not a valid address