aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llhost.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-06 18:24:57 -0500
committerJacek Antonelli2008-09-06 18:25:07 -0500
commit798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch)
tree1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/llmessage/llhost.cpp
parentSecond Life viewer sources 1.20.15 (diff)
downloadmeta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/llmessage/llhost.cpp')
-rw-r--r--linden/indra/llmessage/llhost.cpp72
1 files changed, 8 insertions, 64 deletions
diff --git a/linden/indra/llmessage/llhost.cpp b/linden/indra/llmessage/llhost.cpp
index e139f6d..34a0f92 100644
--- a/linden/indra/llmessage/llhost.cpp
+++ b/linden/indra/llmessage/llhost.cpp
@@ -66,34 +66,15 @@ LLHost::LLHost(const std::string& ip_and_port)
66 } 66 }
67} 67}
68 68
69void LLHost::getString(char* buffer, S32 length) const 69std::string LLHost::getString() const
70{ 70{
71 if (((U32) length) < MAXADDRSTR + 1 + 5) 71 return llformat("%s:%u", u32_to_ip_string(mIP), mPort);
72 {
73 llerrs << "LLHost::getString - string too short" << llendl;
74 return;
75 }
76
77 snprintf(buffer, length, "%s:%u", u32_to_ip_string(mIP), mPort); /* Flawfinder: ignore */
78}
79
80void LLHost::getIPString(char* buffer, S32 length) const
81{
82 if ( ((U32) length) < MAXADDRSTR)
83 {
84 llerrs << "LLHost::getIPString - string too short" << llendl;
85 return;
86 }
87
88 snprintf(buffer, length, "%s", u32_to_ip_string(mIP)); /* Flawfinder: ignore */
89} 72}
90 73
91 74
92std::string LLHost::getIPandPort() const 75std::string LLHost::getIPandPort() const
93{ 76{
94 char buffer[MAXADDRSTR + 1 + 5]; /*Flawfinder: ignore*/ 77 return getString();
95 getString(buffer, sizeof(buffer));
96 return buffer;
97} 78}
98 79
99 80
@@ -103,35 +84,6 @@ std::string LLHost::getIPString() const
103} 84}
104 85
105 86
106void LLHost::getHostName(char *buf, S32 len) const
107{
108 hostent *he;
109
110 if (INVALID_HOST_IP_ADDRESS == mIP)
111 {
112 llwarns << "LLHost::getHostName() : Invalid IP address" << llendl;
113 buf[0] = '\0';
114 return;
115 }
116 he = gethostbyaddr((char *)&mIP, sizeof(mIP), AF_INET);
117 if (!he)
118 {
119#if LL_WINDOWS
120 llwarns << "LLHost::getHostName() : Couldn't find host name for address " << mIP << ", Error: "
121 << WSAGetLastError() << llendl;
122#else
123 llwarns << "LLHost::getHostName() : Couldn't find host name for address " << mIP << ", Error: "
124 << h_errno << llendl;
125#endif
126 buf[0] = '\0';
127 }
128 else
129 {
130 strncpy(buf, he->h_name, len); /*Flawfinder: ignore*/
131 buf[len-1] = '\0';
132 }
133}
134
135std::string LLHost::getHostName() const 87std::string LLHost::getHostName() const
136{ 88{
137 hostent* he; 89 hostent* he;
@@ -158,28 +110,20 @@ std::string LLHost::getHostName() const
158 } 110 }
159} 111}
160 112
161BOOL LLHost::setHostByName(const char *string) 113BOOL LLHost::setHostByName(const std::string& hostname)
162{ 114{
163 hostent *he; 115 hostent *he;
164 char local_name[MAX_STRING]; /*Flawfinder: ignore*/ 116 std::string local_name(hostname);
165
166 if (strlen(string)+1 > MAX_STRING) /*Flawfinder: ignore*/
167 {
168 llerrs << "LLHost::setHostByName() : Address string is too long: "
169 << string << llendl;
170 }
171 117
172 strncpy(local_name, string,MAX_STRING); /*Flawfinder: ignore*/
173 local_name[MAX_STRING-1] = '\0';
174#if LL_WINDOWS 118#if LL_WINDOWS
175 // We may need an equivalent for Linux, but not sure - djs 119 // We may need an equivalent for Linux, but not sure - djs
176 _strupr(local_name); 120 LLStringUtil::toUpper(local_name);
177#endif 121#endif
178 122
179 he = gethostbyname(local_name); 123 he = gethostbyname(local_name.c_str());
180 if(!he) 124 if(!he)
181 { 125 {
182 U32 ip_address = inet_addr(string); 126 U32 ip_address = inet_addr(hostname.c_str());
183 he = gethostbyaddr((char *)&ip_address, sizeof(ip_address), AF_INET); 127 he = gethostbyaddr((char *)&ip_address, sizeof(ip_address), AF_INET);
184 } 128 }
185 129