mirror of
https://github.com/anope/anope.git
synced 2026-06-29 20:26:39 +02:00
Add sockaddrs::str to stringify a sockaddrs properly.
Also clean up the socket code slightly.
This commit is contained in:
+6
-1
@@ -63,6 +63,11 @@ union CoreExport sockaddrs
|
||||
*/
|
||||
Anope::string addr() const;
|
||||
|
||||
/** Gets the endpoint represented by this addr.
|
||||
* @return The endpoint.
|
||||
*/
|
||||
Anope::string str() const;
|
||||
|
||||
/** Get the reverse address represented by this addr
|
||||
* @return The reverse address
|
||||
*/
|
||||
@@ -232,7 +237,7 @@ class CoreExport Socket
|
||||
* @param family The family of the socket
|
||||
* @param type The socket type, defaults to SOCK_STREAM
|
||||
*/
|
||||
Socket(int sock, bool family = AF_INET, int type = SOCK_STREAM);
|
||||
Socket(int sock, int family = AF_INET, int type = SOCK_STREAM);
|
||||
|
||||
/** Destructor, closes the socket and removes it from the engine
|
||||
*/
|
||||
|
||||
@@ -87,7 +87,7 @@ class ProxyConnect : public ConnectionSocket
|
||||
reason = reason.replace_all_cs("%p", stringify(this->conaddr.port()));
|
||||
|
||||
BotInfo *OperServ = Config->GetClient("OperServ");
|
||||
Log(OperServ) << "PROXYSCAN: Open " << this->GetType() << " proxy found on " << this->conaddr.addr() << ":" << this->conaddr.port() << " (" << reason << ")";
|
||||
Log(OperServ) << "PROXYSCAN: Open " << this->GetType() << " proxy found on " << this->conaddr.str() << " (" << reason << ")";
|
||||
XLine *x = new XLine("*@" + this->conaddr.addr(), OperServ ? OperServ->nick : "", Anope::CurTime + this->proxy.duration, reason, XLineManager::GenerateUID());
|
||||
if (add_to_akill && akills)
|
||||
{
|
||||
|
||||
+38
-7
@@ -80,18 +80,49 @@ int sockaddrs::port() const
|
||||
|
||||
Anope::string sockaddrs::addr() const
|
||||
{
|
||||
char address[INET6_ADDRSTRLEN];
|
||||
|
||||
switch (sa.sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
if (inet_ntop(AF_INET, &sa4.sin_addr, address, sizeof(address)))
|
||||
return address;
|
||||
{
|
||||
char v4address[INET_ADDRSTRLEN];
|
||||
if (inet_ntop(AF_INET, &sa4.sin_addr, v4address, sizeof(v4address)))
|
||||
return v4address;
|
||||
break;
|
||||
}
|
||||
case AF_INET6:
|
||||
if (inet_ntop(AF_INET6, &sa6.sin6_addr, address, sizeof(address)))
|
||||
return address;
|
||||
{
|
||||
char v6address[INET6_ADDRSTRLEN];
|
||||
if (inet_ntop(AF_INET6, &sa6.sin6_addr, v6address, sizeof(v6address)))
|
||||
return v6address;
|
||||
break;
|
||||
}
|
||||
case AF_UNIX:
|
||||
return saun.sun_path;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
Anope::string sockaddrs::str() const
|
||||
{
|
||||
switch (sa.sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
{
|
||||
char v4address[INET_ADDRSTRLEN];
|
||||
if (!inet_ntop(AF_INET, &sa4.sin_addr, v4address, sizeof(v4address)))
|
||||
strcpy(v4address, "0.0.0.0");
|
||||
return Anope::printf("%s:%u", v4address, sa4.sin_port);
|
||||
}
|
||||
case AF_INET6:
|
||||
{
|
||||
char v6address[INET6_ADDRSTRLEN];
|
||||
if (!inet_ntop(AF_INET6, &sa6.sin6_addr, v6address, sizeof(v6address)))
|
||||
strcpy(v6address, "0:0:0:0:0:0:0:0");
|
||||
return Anope::printf("[%s]:%u", v6address, sa6.sin6_port);
|
||||
}
|
||||
case AF_UNIX:
|
||||
return saun.sun_path;
|
||||
default:
|
||||
@@ -503,7 +534,7 @@ Socket::Socket()
|
||||
throw CoreException("Socket::Socket() ?");
|
||||
}
|
||||
|
||||
Socket::Socket(int s, bool f, int type)
|
||||
Socket::Socket(int s, int f, int type)
|
||||
{
|
||||
this->io = &NormalSocketIO;
|
||||
this->family = f;
|
||||
|
||||
Reference in New Issue
Block a user