summaryrefslogtreecommitdiff
path: root/indra/llmessage/llhost.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmessage/llhost.cpp')
-rw-r--r--indra/llmessage/llhost.cpp107
1 files changed, 23 insertions, 84 deletions
diff --git a/indra/llmessage/llhost.cpp b/indra/llmessage/llhost.cpp
index 4d10f06051..61a84de8e3 100644
--- a/indra/llmessage/llhost.cpp
+++ b/indra/llmessage/llhost.cpp
@@ -2,30 +2,25 @@
* @file llhost.cpp
* @brief Encapsulates an IP address and a port.
*
- * $LicenseInfo:firstyear=2000&license=viewergpl$
- *
- * Copyright (c) 2000-2007, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2000&license=viewerlgpl$
* Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlife.com/developers/opensource/gplv2
+ * Copyright (C) 2010, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
*
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at http://secondlife.com/developers/opensource/flossexception
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -66,34 +61,15 @@ LLHost::LLHost(const std::string& ip_and_port)
}
}
-void LLHost::getString(char* buffer, S32 length) const
+std::string LLHost::getString() const
{
- if (((U32) length) < MAXADDRSTR + 1 + 5)
- {
- llerrs << "LLHost::getString - string too short" << llendl;
- return;
- }
-
- snprintf(buffer, length, "%s:%u", u32_to_ip_string(mIP), mPort); /* Flawfinder: ignore */
-}
-
-void LLHost::getIPString(char* buffer, S32 length) const
-{
- if ( ((U32) length) < MAXADDRSTR)
- {
- llerrs << "LLHost::getIPString - string too short" << llendl;
- return;
- }
-
- snprintf(buffer, length, "%s", u32_to_ip_string(mIP)); /* Flawfinder: ignore */
+ return llformat("%s:%u", u32_to_ip_string(mIP), mPort);
}
std::string LLHost::getIPandPort() const
{
- char buffer[MAXADDRSTR + 1 + 5]; /*Flawfinder: ignore*/
- getString(buffer, sizeof(buffer));
- return buffer;
+ return getString();
}
@@ -103,35 +79,6 @@ std::string LLHost::getIPString() const
}
-void LLHost::getHostName(char *buf, S32 len) const
-{
- hostent *he;
-
- if (INVALID_HOST_IP_ADDRESS == mIP)
- {
- llwarns << "LLHost::getHostName() : Invalid IP address" << llendl;
- buf[0] = '\0';
- return;
- }
- he = gethostbyaddr((char *)&mIP, sizeof(mIP), AF_INET);
- if (!he)
- {
-#if LL_WINDOWS
- llwarns << "LLHost::getHostName() : Couldn't find host name for address " << mIP << ", Error: "
- << WSAGetLastError() << llendl;
-#else
- llwarns << "LLHost::getHostName() : Couldn't find host name for address " << mIP << ", Error: "
- << h_errno << llendl;
-#endif
- buf[0] = '\0';
- }
- else
- {
- strncpy(buf, he->h_name, len); /*Flawfinder: ignore*/
- buf[len-1] = '\0';
- }
-}
-
std::string LLHost::getHostName() const
{
hostent* he;
@@ -158,28 +105,20 @@ std::string LLHost::getHostName() const
}
}
-BOOL LLHost::setHostByName(const char *string)
+BOOL LLHost::setHostByName(const std::string& hostname)
{
hostent *he;
- char local_name[MAX_STRING]; /*Flawfinder: ignore*/
-
- if (strlen(string)+1 > MAX_STRING) /*Flawfinder: ignore*/
- {
- llerrs << "LLHost::setHostByName() : Address string is too long: "
- << string << llendl;
- }
+ std::string local_name(hostname);
- strncpy(local_name, string,MAX_STRING); /*Flawfinder: ignore*/
- local_name[MAX_STRING-1] = '\0';
#if LL_WINDOWS
// We may need an equivalent for Linux, but not sure - djs
- _strupr(local_name);
+ LLStringUtil::toUpper(local_name);
#endif
- he = gethostbyname(local_name);
+ he = gethostbyname(local_name.c_str());
if(!he)
{
- U32 ip_address = inet_addr(string);
+ U32 ip_address = ip_string_to_u32(hostname.c_str());
he = gethostbyaddr((char *)&ip_address, sizeof(ip_address), AF_INET);
}