From de25d946733f774e3a5b53a58438a9c92af0acbe Mon Sep 17 00:00:00 2001 From: danieldg Date: Sat, 3 Oct 2009 01:52:59 +0000 Subject: Get rid of a bunch of memory-wasting C-style strings git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11796 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/socket.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/socket.cpp') diff --git a/src/socket.cpp b/src/socket.cpp index b719ebe82..00be4250b 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -72,13 +72,12 @@ bool InspIRCd::BindSocket(int sockfd, int port, const char* addr, bool dolisten) } // Open a TCP Socket -int irc::sockets::OpenTCPSocket(const char* addr, int socktype) +int irc::sockets::OpenTCPSocket(const std::string& addr, int socktype) { int sockfd; int on = 1; - addr = addr; struct linger linger = { 0, 0 }; - if (!*addr) + if (addr.empty()) { #ifdef IPV6 sockfd = socket (PF_INET6, socktype, 0); @@ -86,7 +85,7 @@ int irc::sockets::OpenTCPSocket(const char* addr, int socktype) #endif sockfd = socket (PF_INET, socktype, 0); } - else if (strchr(addr,':')) + else if (addr.find(':') != std::string::npos) sockfd = socket (PF_INET6, socktype, 0); else sockfd = socket (PF_INET, socktype, 0); @@ -186,10 +185,10 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports) return bound; } -bool irc::sockets::aptosa(const char* addr, int port, irc::sockets::sockaddrs* sa) +bool irc::sockets::aptosa(const std::string& addr, int port, irc::sockets::sockaddrs* sa) { memset(sa, 0, sizeof(*sa)); - if (!addr || !*addr) + if (addr.empty()) { #ifdef IPV6 sa->in6.sin6_family = AF_INET6; @@ -200,13 +199,13 @@ bool irc::sockets::aptosa(const char* addr, int port, irc::sockets::sockaddrs* s #endif return true; } - else if (inet_pton(AF_INET, addr, &sa->in4.sin_addr) > 0) + else if (inet_pton(AF_INET, addr.c_str(), &sa->in4.sin_addr) > 0) { sa->in4.sin_family = AF_INET; sa->in4.sin_port = htons(port); return true; } - else if (inet_pton(AF_INET6, addr, &sa->in6.sin6_addr) > 0) + else if (inet_pton(AF_INET6, addr.c_str(), &sa->in6.sin6_addr) > 0) { sa->in6.sin6_family = AF_INET6; sa->in6.sin6_port = htons(port); -- cgit v1.2.3