diff options
author | Jacek Antonelli | 2008-09-06 18:24:57 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-09-06 18:25:07 -0500 |
commit | 798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch) | |
tree | 1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/llmessage/llhost.cpp | |
parent | Second Life viewer sources 1.20.15 (diff) | |
download | meta-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.cpp | 72 |
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 | ||
69 | void LLHost::getString(char* buffer, S32 length) const | 69 | std::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 | |||
80 | void 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 | ||
92 | std::string LLHost::getIPandPort() const | 75 | std::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 | ||
106 | void 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 | |||
135 | std::string LLHost::getHostName() const | 87 | std::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 | ||
161 | BOOL LLHost::setHostByName(const char *string) | 113 | BOOL 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 | ||