CoreExport int OpenTCPSocket(const char* addr, int socktype = SOCK_STREAM);
/** Return the size of the structure for syscall passing */
- CoreExport int sa_size(irc::sockets::sockaddrs& sa);
+ CoreExport int sa_size(const irc::sockets::sockaddrs& sa);
/** Convert an address-port pair into a binary sockaddr
* @param addr The IP address, IPv4 or IPv6
* @return true if the conversion was successful, false if unknown address family
*/
CoreExport bool satoap(const irc::sockets::sockaddrs* sa, std::string& addr, int &port);
+ /** 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
+ * @param sa The structure to convert
+ * @return The string; "<unknown>" if not a valid address
+ */
+ CoreExport std::string satouser(const irc::sockets::sockaddrs* sa);
}
}
class CoreExport ListenSocketBase : public EventHandler
{
protected:
- /** The creator/owner of this object
- */
- InspIRCd* ServerInstance;
/** Socket description (shown in stats p) */
std::string desc;
- /** Address socket is bound to */
+ /** Raw address socket is bound to */
std::string bind_addr;
/** Port socket is bound to */
int bind_port;
+ /** Human-readable address/port socket is bound to */
+ std::string bind_desc;
/** The client address if the most recently connected client.
* Should only be used when accepting a new client.
public:
/** Create a new listening socket
*/
- ListenSocketBase(InspIRCd* Instance, int port, const std::string &addr);
+ ListenSocketBase(int port, const std::string &addr);
/** Handle an I/O event
*/
void HandleEvent(EventType et, int errornum = 0);
}
/** Get description for socket
*/
- const std::string& GetDescription()
- {
- return desc;
- }
+ const std::string& GetDescription() { return desc; }
/** Get port number for socket
*/
- int GetPort() { return bind_port; }
+ int GetPort() const { return bind_port; }
/** Get IP address socket is bound to
*/
const std::string &GetIP() { return bind_addr; }
+ const std::string &GetBindDesc() { return bind_desc; }
+
/** Handles sockets internals crap of a connection, convenience wrapper really
*/
void AcceptInternal();
{
virtual void OnAcceptReady(int fd);
public:
- ClientListenSocket(InspIRCd* Instance, int port, const std::string &addr) : ListenSocketBase(Instance, port, addr) { }
+ ClientListenSocket(int port, const std::string &addr) : ListenSocketBase(port, addr) { }
};
#endif